Xfce4 restart&shutdown without systemd/polkit/consolekit/you-name-kit
In this post I am describing how to bypass modern user authorization tools for Linux desktops (Ubuntu 16 in particular) and have the XFCE4 session logout window display the Restart and Shutdown as enabled (handy, uh?), while at the same time bind them to a simple command of the user’s choice.
Logout dialog & systemd
In Ubuntu 16 Xenial it is impossible to have those two buttons enabled if you don’t install policykit-1, which in turn depends on systemd to be installed (although not necessarily run as init system).
After extensive online searches I made many (failed) attempts to get rid of this dependency, in particular a promising one was enabling sudo for xfsm-shutdown-helper; however, after reading the source code, I discovered that this approach is completely dependent on pkexec (policykit).
Back to square 0.
Read the source
After reading bits of the apt-provided source code for xfce4-session I discovered an interesting history of how restart, shutdown, hibernate and suspend have been provided throughout the years.
In particular:
- new DBus way
- old DBus way, as fallback
- UPower
- ConsoleKit
- PolicyKit
- Systemd
Being stubborn and not willing to mess with any kit nor systemd, I decided to simply convert those grayed out buttons into shell commands of our choice.
Targeted surgery
The Debian source package building system came in handy in this case to allow customization of the xfce4-session package; the repository with all the scripts/patches can be found here:
https://github.com/gdm85/ubuntu16-no-systemd
(NOTE: It contains customization also for other packages, in case you need it.)
In order to build the customized xfce4-session, issue in the root of the project:
$ make xfce4-session
# ... expect a sudo prompt here ...
$ make install
$ sudo ./install-custom-session-logout.sh
It will require sudo to install build dependencies and the actual xfce4-session package and diversions.
This customization does a few important changes:
- rebuild xfce4-session so that it executes an external xfce4-session-logout instead of providing an embedded dialog
- divert xfce4-session-logout so that the custom-session-logout script will be executed instead
On the other hand, custom-session-logout does replace all of the attempts found in the source code of xfce4-session with the approach that I guess 90% of the people were looking for:
- when I ask to restart, run: shutdown -r now
- when I ask to shutdown, run: shutdown -P now
The customization script also enables password-less calls to shutdown through sudo; please note that new updates to the xfce4-session package will override the binary you have built and installed.
Conclusion
The end result looks like this:
Surely not the fanciest logout dialog, but hey — it does actually let you reboot or shutdown!
Update: you can replace this logout screen with a Win98-look-alike if you please