You know how GNOME/KDE have “shutdown” and “reboot” buttons that normal users can use to turn off the computer? Rather than using sudo or making
/sbin/shutdown setuid, they use HAL which provides a nice power management interface. Turns out this is pretty easy to call from the command line so you can use it in Fluxbox, etc.
The DBus object is
/org/freedesktop/Hal/devices/computer which has lots of interesting methods including
Suspend(). For example, you can reboot the computer using:
qdbus --system org.freedesktop.Hal /org/freedesktop/Hal/devices/computer \ org.freedesktop.Hal.Device.SystemPowerManagement.Reboot
This is using the
qdbus tool which is distributed with QT. If you get permission errors you may have to configure PolicyKit to let you call this interface. Here’s my PolicyKit.conf which works for me on Arch Linux. (You’ll also need to add your user to the
Here’s a simple script to wrap this up: hal-power. Usage example:
hal-power reboot to reboot the computer.