We have an internal application with systemd services that we want to deploy outside of the normal systemd directories (/etc/systemd/system and /usr/lib/systemd/system). That location is on another disk (/mnt/data in the example).
The systemd service is enabled by:
systemctl enable /mnt/data/sprinterd.service
which creates a symbolic link in /etc/systemd/system
lrwxrwxrwx. 1 root root 27 Jun 20 22:47 sprinterd.service -> /mnt/data/sprinterd.service
After rebooting, the service is not loaded because the unit file can't be found. From journalctl, first an error that the service failed to load, then after that the mount of the disk where the unit is located.
Cannot add dependency job for unit sprinterd.service, ignoring: Unit sprinterd.service failed to load: No such file or directory.
systemd[1]: Mounted /mnt/data.
From /etc/fstab:
/dev/disk/by-uuid/c55e944f-5c63-48ad-8cd2-bd32d7b35c82 /mnt/data auto nosuid,nodev,nofail,x-gvfs-show 0 0
For completeness the service unit file:
[Unit]
Description=sprinterd
[Service]
Type=simple
Environment=TERM=linux
ExecStart=/srv/s1.erp/bin/sprinterd
Restart=always
RestartSec=5
KillSignal=SIGKILL
[Install]
WantedBy=multi-user.target
I have tested this on RHEL 7 and on openSuSE 13.2.
Is it supported to have a system service unit file on another disk than /etc or /usr?
How could the order of execution between mounting the disk and loading the systemd unit files be changed?
Best Answer
As explained by @StephenHarris the problem is at the moment systemd tries to read the unit, the file that's symlinked isn't available yet
To just have systemd reload the units after it has mounted :
This will cause the units to become available, because this time this time the target of the symlinks is mounted.
But by that time, the list of jobs needing to be run to reach the default.target is already built, and the service won't be started.
To have it also restart your service:
Alternatives:
ExecStart=
&ExecStartPost=
, but it should obviously work withExecStartPre=
&ExecStart=
ExecStart=/bin/systemctl enable /mnt/data/sprinterd.service
instead of daemon-reloadConsistsOf=
orPartOf=
to load all the multiple services.local-fs.target
isn't your best Installation option, obviously.For a more old-school SysVinit-style approach, put the systemctl commands inside
/etc/rc.local
andchmod +x
that file.And then go smuggly post on Devuan's mailing list how you needed SysVInit to fix b0rked SystemD ;-)