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?
GNOME Shell 3.30.1 on Ubuntu 18.10
The command to replace
gnome-shell
would be sending a SIGQUIT signal to it with:or:
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
gnome-shell
would be: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
:Unsure which version you are using?
The command to check your GNOME Shell version is:
The easiest way is to Alt+F2 and type
r
then ↵.Since GNOME Shell 3.30.1: You can also do a
killall -3 gnome-shell
.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:DISPLAY=:0 gnome-shell -r &
exit
andBefore GNOME Shell 3.30.1 the command should just be
gnome-shell --replace
.The Gnome 40 the equivalent of
Alt+F2 restart
is:Got this tip myself from https://www.linuxuprising.com/2020/07/how-to-restart-gnome-shell-from-command.html.
I came up with this function to logout users (see at the bottom)
It assumes
You can give it multiple usernames:
And you can give it additional options:
So, I have the following helper function:
Notes:
CODE
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.
In order to proper restart all related, I prefer restarts of whole stack (if tty1..4 works)
Sending TERM signal to Gnome Shell 42.1 works for me on Ubuntu 22.04:
Note: TERM is the default signal for pkill.