Catch-all command to restart display manager

display-managerinit-scriptx11

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)?

Best Answer

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

Related Question