Making Systemd Start A Service After Sshd?

Home » CentOS » Making Systemd Start A Service After Sshd?
CentOS 4 Comments

Hi folks,

For complicated reasons, I’d like to have a service (lightdm) start after sshd starts. (This is on CentOS 7.) I’ve tried adding “sshd.service”
to the lists of “Active=” and “Require=” items in
/etc/systemd/system/lightdm.service (which started as a copy of
/usr/lib/systemd/system/lightdm.service), but these changes don’t seem to have any effect. Sshd still starts long after lightdm starts.

Any suggestions? For what it’s worth, here’s the entire lightdm.service file:

Description=Light Display Manager Documentation=man:lightdm(1)
Conflicts=getty@tty1.service After=systemd-user-sessions.service getty@tty1.service plymouth-quit.service livesys-late.service sshd.service sshd.service

ExecStart=/usr/sbin/lightdm Restart=always IgnoreSIGPIPE=no BusName=org.freedesktop.DisplayManager


Thanks for any help.

4 thoughts on - Making Systemd Start A Service After Sshd?

  • Stijn De Weirdt writes:

    You’re right! But correcting that doesn’t change the behavior. Sshd still starts after lightdm.


  • Hi again,

    I’m starting to get to the bottom of it. It looks like the file in
    /etc/systemd/system is being ignored. I noticed this when I did a:

    systemctl show -p “After” lightdm.service

    and saw that it didn’t show sshd.service as a depencency. After editing the original copy of lightdm.service in /usr/lib/systemd/system and adding sshd.service there, things work as expected.

    Now the question is why does /etc/systemd/system/lightdm.service get ignored? Ahh! I think I see the answer to that, too. It looks like this directory contains a symbolic link called dislay-manager.service which points to the original lightdm.service. The thing that’s being started at boot time is “display-manager.service”!

    Yep, that does seem to be the case:
    I put the original lightdm.service back to its pristine state, made
    /etc/systemd/system/display-manager.service a symlink to my modified lightdm.service file in /etc/systemd/system and rebooted, and things work as expected.

    Now my only worry is that this symlink will get pointed back at the original file the next time an updated lightdm is installed….


  • Testing that it works on reboot is a good thing to test, but it is not the minimum necessary test.

    I wonder if you are forgetting “systemctl daemon-reload”? Unlike with SysV init, changes to /usr/lib/systemd/system don’t immediately take effect. You have to tell systemd to reload the configuration files when they change.