[systemd-devel] Unable to get service to wait for a mount before starting

Adam Nielsen a.nielsen at shikadi.net
Tue Oct 29 02:10:54 UTC 2024


Hi all,

I'm having some problems getting a systemd unit to start during system
boot.  Can anyone advise what I'm doing wrong?

The service starts fine if I run `systemctl start myservice`, the issue
is that it fails to start during boot.

The service runs off a network share, so if it starts too early in the
boot process the share is not mounted and it fails for that reason and
systemd does not try to restart it later, despite the unit file saying
to restart forever.

I tried using ConditionPathExists=/mnt/share/something however because
the path does not exist when the service is run during boot, the unit
is never started and it is not retried later when the path does exist.

I tried using RequiresMountsFor=/mnt/share however again, if it runs too
early in the boot process the mount is not there and the unit fails to
start, and is not retried (logs just say "Job myservice.service/start
failed with result 'dependency'.")

Currently I have to wait until the machine has booted, SSH into it, and
then use systemctl to start the service.  I'm sure there must be a way
to get this service to start automatically during boot, however I
haven't yet worked it out.

Any suggestions how I can indicate that the service should start after
a specific path is mounted?

Many thanks,
Adam.

```
[Unit]
Description=Run my code
Wants=network-online.target
After=network-online.target

# Don't rate limit, keep restarting forever
StartLimitIntervalSec=0

# Does not work
RequiresMountsFor=/mnt/share

[Service]
WorkingDirectory=/mnt/share/code
ExecStart=/usr/bin/node mycode.js

Restart=always
# Wait before restarting
RestartSec=10

[Install]
WantedBy=multi-user.target
```


More information about the systemd-devel mailing list