Reboot machine gracefully from CLI?

I want to script a logout/reboot to exit KDE gracefully and reboot, not just issue a shutdown -R now that will just kill all processes and reboot.

I have found several solutions that are all years old and that involve installing no longer existing utilities that are part of QT4, which I do not want to do. That’s just introducing legacy that can potentially can come back later to haunt me. Ie, I am not going to install libqt4 just to get the qdbus binary.

I can use qdbus-qt5, but it appears “org.kde.Shutdown” is no longer available, so that doesn’t help much either…

Can’t find any recent posts on the topic using commands available in Plasma / QT5. There is a topic on here in Tips & Tricks that uses org.kde.ksmserver but that throws a dbus error when invoking through qdbus-qt5.

Any suggestions here on how to do this?

This may not be the best option, but it is what I came up with. These are in my aliases list.

alias reboot=‘systemctl reboot’ # allows reboot from the command line
alias off=‘systemctl poweroff’ # allows power down from the command line

So,

systemctl reboot

systemctl poweroff

Works for me. Can you tell me the exact command you use and the error message?

There was something about it here: https://discuss.kde.org/t/logout-reboot-and-shutdown-using-the-terminal/743/4

I get:

Could not connect to D-Bus server: org.freedesktop.DBus.Error.NotSupported: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

From command:

sudo qdbus-qt5 org.kde.ksmserver /KSMServer logout 1 1 1

Doh!

I am so used to needing sudo, I forget I am trying to logout and reboot my own session.

:man_facepalming:

So when I do:

qdbus-qt5 org.kde.ksmserver /KSMServer logout 1 1 1

It does work…

@throttlemeister please read the link I posted. The ksmserver API might be removed in Plasma 6.

1 Like

as follow up: If you want to have platform independent code, the qdbus method also works just fine on FreeBSD (while the systemctl will not).

e.g for 13.2
qdbus-qt5 org.kde.LogoutPrompt /LogoutPrompt org.kde.LogoutPrompt.promptLogout