On Tue, 29 Oct 2024 at 02:50, Adam Nielsen <a.niel...@shikadi.net> wrote:
> 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? > I had a similar requirement and the way I implemented it was to create a systemd.mount for the NFS mount and then ensure that I have the mount in the "After" and add a " Requires" in the service that will depend on the mount. An example below: After=network.target nfs.mount Requires=nfs.mount I hope this helps. Kind regards Henti