<div dir="ltr"><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Oct 29, 2024 at 4:50 AM Adam Nielsen <<a href="mailto:a.nielsen@shikadi.net">a.nielsen@shikadi.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
I'm having some problems getting a systemd unit to start during system<br>
boot.  Can anyone advise what I'm doing wrong?<br>
<br>
The service starts fine if I run `systemctl start myservice`, the issue<br>
is that it fails to start during boot.<br>
<br>
The service runs off a network share, so if it starts too early in the<br>
boot process the share is not mounted and it fails for that reason and<br>
systemd does not try to restart it later, despite the unit file saying<br>
to restart forever.<br></blockquote><div><br></div><div>Units are only restarted when they are already running and their daemon process fails; they're never "retried" when conditions or dependencies change when the unit never reached 'starting' at all.<br></div><div><br></div><div>If systemd itself is responsible for the mount (i.e. there is a fstab entry or a .mount unit), then your service can have a dependency on it, and can be ordered to wait until the mount succeeds (either using explicit Requires= & After= on the .mount, or the combined RequiresMountsFor= that you already have).</div><div><br></div><div>(The RequiresMountsFor would internally expand to [Unit] Requires=mnt-share.mount After=mnt-share.mount, or something along those lines.)<br></div><div><br></div><div>But if the mount just randomly shows up by some external means, that won't happen – the .mount unit didn't exist at boot time, the dependency wasn't met and that's the end of story. In this case, you have to do the *opposite* – if you want systemd to react to the event of the mount showing up, then your service has to be a dependency of the mount.</div><div><br></div><div>Even externally established mounts have virtual .mount units in systemd, so if you want your service to be started by the *event* of /mnt/share being mounted, [Install] WantedBy=mnt-share.mount would achieve that.</div></div><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr">Mantas Mikulėnas</div></div></div>