How to restart X session (KDE) under systemd

Updated: December 4, 2014

Once upon a time, there were init scripts. So when you wanted a service to stop running, you simply stopped it, and that was all. The same rules applied to the desktop session, powered by this or that graphical manager, including the likes of gdm, kdm, xdm, and friends. And so, using KDE as an example, you could stop it, and no fuss.

Then, code monkeys decided to step in and make everything Object Oriented, the most hated catchphrase in the world. Init scripts were replaced with a supposedly parallelized event-based bullshit called systemd, which improves the boot speed pause NOT, but it sure did add complexity to the life of a common user. And now, if you want to restart your X session, you will struggle. Not to worry, Dedoimedo comes to the rescue. Let's learn how to work under these new, ugly circumstances.

Keyboard setup

KDE is our demonstrator here, but others also apply. Anyhow, head into the keyboard setup. You will find all kinds of shortcut presets waiting for you there, one of which promises to restart the X session. Why would you need this, you wonder? Well, it may have gotten stuck, or you just installed your Nvidia drivers, and you do not feel like rebooting, because there's no need.

Restart X via keyboard shortcut

Option 2: Systemd commands

Now, how do you really know which service, under systemd, controls the graphical environment. It's tricky, I'll grant you that, but here's how you do it:

systemctl list-units

This command will show all loaded units, including services. There will be too many of those to read through the whole list meaningfully, so we ought to narrow it down a little. Now, we are looking for some kind of a manager. So we will pimp up the command to read:

systemctl list-units | grep -i manager

List units

As you can see in the screenshot above, one of these is The KDE login manager, identified by the kdm.service string. So we now know how to translate the good ole /etc/init.d/kdm into a new systemd convention. Now, we will restart it:

systemctl restart kdm.service

And you get your old functionality back, with only some ugliness.

More reading

Fedora 20 Heisenbug review, with KDE

How to fix broken desktop effects in KDE

Systemd blame functionality


This short guide is full of wit and good charm, and it tries to resolve the fundamental problem of over-complexity present in systemd, which seems like nothing but trouble. Still, you have two decent recipes for making your X session restart, without having to reboot the system. We used KDE as the guinea pig, but it will work for all the rest.

My recommendation is to try simple things first, like the built-in options in the system settings of whatever desktop environment you're using. If that does not work, only then should you meddle with the systemctl stuff, and it's not pretty, and quite confusing, and you may do some damage, so think carefully. But in essence, we are done here.


You may also like: