79

I would like to implement a keyboard shortcut to restart gnome-shell whenever this one crashes (some bugs aren't currently fixed just yet). For this I would need a command line to restart the shell.

The Alt+F2 and restart command won't work when the shell is crashed because the prompt is implemented in the shell.

Hence, how to restart the gnome-shell from command line?

  • NOTE: Alt+F2 and restart will stop all the running programs. (I still don't know how to restart the GUI without stopping the programs.) – Andriy Makukha Aug 17 '18 at 6:38
84

GNOME Shell 3.30.1 on Ubuntu 18.10

The command to replace the gnome-shell would be sending a SIGQUIT signal to gnome-shell with killall -3 gnome-shell or:

killall -SIGQUIT gnome-shell

As of GNOME Shell 3.30.1 on Ubuntu 18.10, the solution below no longer works, and will kick the user to the login screen, losing all of their work.

Before GNOME Shell 3.30.1

The command to replace the gnome-shell would be

gnome-shell --replace &

The ampersand is added to return the shell prompt after running the command; pressing Ctrl + C or closing the terminal instead would make the desktop unusable, and require a full restart.

From the manual page of gnome-shell:

--replace Replace the running window manager

| improve this answer | |
  • 3
    Thanks I wasn't sure --replace = "restart". – Benjamin Jan 31 '12 at 15:56
  • 5
    As of GNOME Shell 3.30.1 on Ubuntu 18.10, this solution no longer works, and will kick the user to the login screen, losing all their work. The correct solution is now commandline: "killall -3 gnome-shell", or ALT+f2 and r (if possible). – C.Rogers Nov 15 '18 at 10:48
  • 2
    ALT+f2 (show command prompt) + gnome-shell --replace will work nicely in 18.04. All running programs won't be stopped. – lifeisfoo Jun 10 '19 at 12:42
  • 1
    I add the ampersand to the end of the command to put the process in the background so I can close the terminal without killing gnome-shell: gnome-shell --replace & – Teddy Oct 4 '19 at 13:01
  • 2
    @Sparr - thanks for the warning. Fortunately, the killall -3 gnome-shell answer seems to work on Ubuntu 19.10. – bitinerant Nov 11 '19 at 21:03
63

The easiest way is to Alt+F2 and type r then .

| improve this answer | |
  • 7
    That is true, but exactly not the question. The question then is: what happens when you do this. So that you can do it yourself – sehe Jan 21 '17 at 11:34
  • 8
    As of GNOME Shell 3.30.1 on Ubuntu 18.10, and commandline: "killall -3 gnome-shell" are the only solutions posted here that work. All others kick the user out to login screen, losing all their work. – C.Rogers Nov 15 '18 at 10:49
  • 1
    Tried this on debian buster. Getting "Restart is not available on wayland" error. – livinston Aug 14 '19 at 21:49
  • 2
    Amazing! That was so simple on Ubuntu 19.10 :) Thank you! – yanike Jan 23 at 1:40
  • This one works for me on Xorg display server. But on Wayland, for now, no way to make it work. – fsevenm Mar 21 at 8:09
38

Since GNOME Shell 3.30.1: You can also do a killall -3 gnome-shell.

| improve this answer | |
  • 4
    I don't know why people keep recommending this command. All this does is kill gnome-shell. How have you answered the question of restarting it? – smac89 May 30 '18 at 16:42
  • 1
    Probably because this is a good solution where the other command doesn't work. I tried both, the choosen one is good but didn't solve my problem, while this did. – Mitro Nov 5 '18 at 10:00
  • 2
    As of Ubuntu 18.10, GNOME Shell 3.30.1 - THIS IS THE CORRECT SOLUTION. All other solutions restart the session and kick the user out to the login screen, losing all their work. – C.Rogers Nov 15 '18 at 10:44
  • 3
    SIGQUIT (3) doesn't kill the process – Jack Wasey Jan 1 '19 at 11:22
  • This seemed to work for me. Whereas I was using gnome-shell --replace & before. It worked but, kept running in the terminal. The issue I was having was with Youtube videos in full screen somehow causing Dash-to-Dock and the panel to freeze closed. github.com/micheleg/dash-to-dock/issues/… – Natetronn Apr 18 '19 at 23:48
9

In case the whole gnome-shell got frozen there is a way how to restart it from the terminal without restarting the whole X window:

  • Ctrl+Alt+F2 to switch to terminal
  • log in with your credentials (username and password) and then run:
  • DISPLAY=:0 gnome-shell -r &
  • log out exit and
  • Alt+F1 to switch back to graphical interface X Window.
| improve this answer | |
6

Before GNOME Shell 3.30.1 the command should just be gnome-shell --replace.

| improve this answer | |
  • 4
    As of GNOME Shell 3.30.1 on Ubuntu 18.10, this solution no longer works, and will kick the user to the login screen, losing all their work. The correct solution is now commandline: "killall -3 gnome-shell", or ALT+f2 and r (if possible). – C.Rogers Nov 15 '18 at 10:50
  • doesn't work for a remote session, so when gnome shell has frozen, this doesn't work. – Jack Wasey Jan 1 '19 at 11:21
1

I came up with this function to logout users (see at the bottom)

It assumes

  • you have sudo permissions
  • you have bash
  • the users have 1 running X session (although you should be able to issue the same logout command multiple times to get rid of remaining sessions)

You can give it multiple usernames:

logout john jane mike elisa

And you can give it additional options:

logout john --force

So, I have the following helper function:

function forcelogout() {
    logout "$@" --no-prompt --force
}

Notes:

  • This is a blunt instruments and works by just copying the entire session environment. This could be more selective.
  • Sometimes logout seems to take a while
  • In rare occasions the session keeps being reported until someone visits the vt where the session ran, but nothing is there anymore)

CODE

function logout() {
    local USERNAME
    export USERNAMES=( ) 
    while [ -n "$1" ]; do case "$1" in
        -* ) break ;;
        *) USERNAMES+=( "$1" ); shift ;;
    esac; done

    for USERNAME in "${USERNAMES[@]}"; do
        local SESSION_PID=$(pgrep -fu "$USERNAME" gnome-session|head -1)
        if [ -n "$SESSION_PID" ]; then
            (
                sudo -u "$USERNAME" cat "/proc/$SESSION_PID/environ" | xargs -0 -n 1 echo export
                echo "gnome-session-quit --logout $@"
            ) | sudo -u "$USERNAME" sh -;
        fi
    done
}
| improve this answer | |
  • logout USERNAME --force, gives me an output telling me a number is necessary. – Quidam Jun 4 at 5:11
  • 1
    @Quidam That indicates that the variable is not set to a value. You need to set it (which is what happens in the script) – sehe Jun 4 at 9:39
  • Thank you Sehe. – Quidam Jun 4 at 15:39
1

I defined an alias: alias gnomeshellrestart='echo "gnome-shell --replace -d" $(w| grep "$USER"| awk "{print \$3}"|grep ":"|head -1)| at now'

You may be able to start a terminal by right-clicking with the mouse on background and type there (alt-tab is dysfct then, too), if not, login to a tty with e.g. ctrl-alt-F2 and run from there.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.