How to start a systemd service after network is established?

I am trying to write a systemd unit to mount a NAS after boot, but it fails during boot because it seems not to wait for the network. After I have booted, I can start the service fine. I already tried to put NetworkManager-wait-online.service, but it still doesn’t work.

[Unit]
Description=cifs mount script
Requires=NetworkManager-wait-online.service
After=NetworkManager-wait-online.service

[Mount]
What=//nas.storage/
Where=/home/user/nas
Options=username=user,password=pw,rw
Type=cifs

[Install]
WantedBy=multi-user.target
After = network-online.target
1 Like

Hi @coldspark,

This is really, really, really nothing more than a haunch, so chances are good that I’m wrong.

Is NetworkManager-wait-online.service the correct service to wait for? I would have thought it’d rather be something like NetworkManager.service. :man_shrugging:

Once again, chances are very good that I’m wrong. That is just a haunch…

That is exactly what I thought! Thank you!

Providing enough and acurate info is the first step in helping others help you better…
(Log lines)

As first reaction i would direct you to:

None of the solutions worked and I ended up writing an automount script, which works well but seems to have the side effect that my system is not shutting down properly as described in this thread. I see that one of the last messages is the unmount of the cifs script. When I disable the script, I can shutdown fine. Any idea why this could be? Could it be that I have to write an unmount service as well?

Here is my script

[Unit]
Description=cifs mount script
ConditionPathExists=/home/user/NAS

[Mount]
What=//fritz.box/FRITZ.NAS/WDCWDS-100T2B0A-00SM50-01/
Where=/home/user/NAS
Options=vers=1.0,username=user,password=pass,rw
Type=cifs
TimeoutIdlesec=10

[Install]
WantedBy=multi-user.target

@TriMoon I was asking a general question. I do post logs when I regard it as necessary.