Force rc.local to wait for network

I am trying to force a script wait for network readiness, following the suggestions @DBMandrake provided here:

My first attempt uses the (simpler looking) approach to make the whole rc.local launch wait for network. Unfortunately, it did not work. Here is what I did:

  1. created a directory rc.local.service.d, and confirmed it has the same permissions as all the other directories here (rwxr-xr-x root root).

  2. created a local.conf file inside the new directory. The permissions here seem to match those on local.conf in other directories, like bluetooth.service.d (rw-r–r-- root root), so I think this is OK.

  3. in local.conf, I added only the lines specified:

  4. commented out the sleep 10 delay I had previously inserted into rc.local as a first workaround.

  5. rebooted

  6. the network problems came back :frowning:

    Error while loading service
    Unable to find the server at api.twilio.com

I do not know how to confirm for certain, but it seems to me that rc.local did not wait for the network to be ready? The reasons I think this are:

  • if I manually run rc.local at this point (sudo /etc/rc.local), it starts correctly. I assume this is because by now the network is up.
  • if I add back sleep 10 to rc.local, everythink works correctly again on reboot.

Am I doing something wrong with the network-online.target approach?

Did you also enable wait for network in the networking settings in My OSMC ?

As far as I know, yes. I believe I have always used OSMC with that option enabled, but admittedly I was working from CLI and did not explicitly check. Is there a way to check using SSH? Otherwise I will double-check in GUI later.

sudo systemctl status connman-wait-for-network.service

The service should be enabled.

BTW I have not tried the modifications to rc.local.service that I suggested but I see no reason why it shouldn’t work.

Confirmed wait for network is enabled:

@DBMandrake I spent some time today reading the documentation on systemd. I think that to be consistent with the corresponding service, the filename needs to be rc-local.service.d instead of rc.local.service.d (i.e. dash instead of dot).

Once I made the change, I was able to remove the artificial sleep statement in rc.local and my process still worked fine - presumably waiting for network before proceeding.

I can also see that rc-local.service correctly recognizes the new dependencies:

osmc@osmc:/etc/systemd/system$ systemctl show rc-local.service | grep network Wants=network-online.target system.slice After=network.target network-online.target systemd-journald.socket basic.target

Thanks again! Next I’ll look into defining a whole new service just for my script, removing it from rc.local altogether.

Interesting find! I had not notice this before but both names are present, however one is a symlink:

-rw-r--r-- 1 root root 633 Nov 27 06:30 rc-local.service
lrwxrwxrwx 1 root root  16 Nov 27 06:31 rc.local.service -> rc-local.service

Apparently because rc-local.service is the real service name, this is the one that you must override with the drop in.