1

I created service for strelaysvr:

[Unit]
Description=Syncthing Relay Server
After=network.target

[Service]
ExecStart=/usr/bin/strelaysrv -keys /srv/strelaysrv/keys
User=strelaysrv

[Install]
WantedBy=multi-user.target

and placed it into /srv/strelaysvr/strelaysvr.service, which I symlinked into /etc/systemd/system.

Then went on and systemctl enabled it , systemctl started it, and all works, fine, until reboot: after that, it seems to "disappear":

root@here:~# systemctl start strelaysrv
Failed to start strelaysrv.service: Unit strelaysrv.service not found.
root@here:~# ll /etc/systemd/system/strelaysrv.service 
lrwxrwxrwx 1 root root 34 Apr  2 22:59 /etc/systemd/system/strelaysrv.service -> /srv/strelaysrv/strelaysrv.service
root@here:~# ll /etc/systemd/system/multi-user.target.wants/strelaysrv.service 
lrwxrwxrwx 1 root root 34 Apr  2 23:00 /etc/systemd/system/multi-user.target.wants/strelaysrv.service -> /srv/strelaysrv/strelaysrv.service
root@here:~# ll /srv/strelaysrv/strelaysrv.service
-rw-r--r-- 1 root root 185 Apr  2 22:58 /srv/strelaysrv/strelaysrv.service

But just calling systemctl enable succeeds and I can start it again! What am I doing wrong? Am I hitting a systemd bug?

root@here:~# lsb_release -a |& grep escr
Description:    Debian GNU/Linux 9.4 (stretch)
root@here:~# dpkg -s systemd | grep ersion
Version: 232-25+deb9u3
  • should not there be After=multi-user.target – LinuxSecurityFreak Apr 7 '18 at 17:21
  • 1
    @GAD3R Why? That does not seem like a safe thing to do. Also as I said, I can start the service after I call systemctl enable, so the ownership is right. – Alois Mahdal Apr 7 '18 at 17:58
  • 2
    Is /srv mounted when systemd tries to load the .service file at boot? – Mark Stosberg Apr 7 '18 at 18:41
  • @MarkStosberg Good quesion. /srv is actually a symlink to under /home, which is mounted as UUID=redacted /home ext4 defaults 0 0 in fstab. (My apache vhosts do rely on /srv, nothing except strelaysrv has unit file there, though.) – Alois Mahdal Apr 7 '18 at 19:00
3

The unit file (in this case strelaysrv.service needs to be in a partition that is already mounted when systemd starts, which is not the case in your example, since in the comments you mentioned /srv is a symlink to under /home which is in its own partition.

This comes up fairly often in systemd bug reports, for a recent one see here.

See also the (recently updated) man page for systemctl which states:

The file system where the linked unit files are located must be accessible when systemd is started (e.g. anything underneath /home or /var is not allowed, unless those directories are located on the root file system).

The recommended solution is for you to create a copy of strelaysrv.service under /etc/systemd/system rather than a symlink. That should fix the issue.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.