Is there a catch-all command to restart display managers (on any given common init system)?

I've got systemctl restart display-manager for systemd-based systems currently, but I don't know that that'll work on every systemd-based system, and it sure won't work on other init systems.

Are there other catch-all commands that are likely to work (given that a particular common init system is installed on a common distro)?

  • in the traditional init system, switching from runlevel 5 to runlevel 3 and back is probably the closest you'll find to a generic means of stopping and starting the display manager. this could fail in systems that chose not to follow the conventional runlevel definitions. i don't know how well this translates to the various modern init systems.
    – quixotic
    Feb 19, 2018 at 20:50
  • @quixotic that would also stop and restart a lot of other things that had nothing to do with the display manager. I don't think there's any generic solution that will always work - even Bigon's answer will only work sometimes (probably even most of the time - when the base filename of the display-manager's executable is identical to the service name....works for, e.g., lightdm and gdm. It may not work for others)
    – cas
    Feb 20, 2018 at 2:10

1 Answer 1


If you are using Debian (and derivatives like ubuntu), /etc/X11/default-display-manager should contain the name of the currently active display manager.

So something like that should work:

dm=$(basename "$(cat /etc/X11/default-display-manager)")
service $dm restart

Otherwise, I don't think there is a standardized way of doing so

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .