How to wait for network

I have been using Mopidy on Raspberry Pis for years. Now I just installed it on a desktop machine with Debian 11. Installation went fine, Configuration is also OK. Everything is working as expected, EXCEPT, that after boot I get this in the Mopidy log:

mopidy.service - Mopidy music server
     Loaded: loaded (/lib/systemd/system/mopidy.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-03-05 14:41:12 EET; 7min ago
    Process: 388 ExecStartPre=/bin/mkdir -p /var/cache/mopidy (code=exited, status=0/SUCCESS)
    Process: 390 ExecStartPre=/bin/chown mopidy:audio /var/cache/mopidy (code=exited, status=0/SUCCESS)
   Main PID: 392 (mopidy)
      Tasks: 13 (limit: 14189)
     Memory: 64.0M
        CPU: 1.658s
     CGroup: /system.slice/mopidy.service
             └─392 /usr/bin/python3 /usr/bin/mopidy --config /usr/share/mopidy/conf.d:/etc/mopidy/mopidy.conf

Mar 05 14:41:14 mcoffice mopidy[392]: INFO     [YouTubeBackend-3] mopidy_youtube file caching not enabled
Mar 05 14:41:14 mcoffice mopidy[392]: INFO     [YouTubeBackend-3] mopidy_youtube using jAPI
Mar 05 14:41:14 mcoffice mopidy[392]: INFO     [Audio-2] mopidy.audio.actor Audio output set to "autoaudiosink"
Mar 05 14:41:14 mcoffice mopidy[392]: INFO     [MainThread] mopidy.commands Starting Mopidy core
Mar 05 14:41:14 mcoffice mopidy[392]: INFO     [MainThread] mopidy.commands Starting Mopidy frontends: YouTubeAutoplayer, YouTubeCoreListener, MpdFrontend, HttpFrontend
Mar 05 14:41:14 mcoffice mopidy[392]: INFO     [MainThread] mopidy_mpd.actor MPD server running at [::]:6600
Mar 05 14:41:14 mcoffice mopidy[392]: ERROR    [MainThread] mopidy.commands Frontend (HttpFrontend) initialization error: HTTP server startup failed: [Errno 99] Cannot assign requested address
Mar 05 14:41:14 mcoffice mopidy[392]: INFO     [MainThread] mopidy.commands Starting GLib mainloop

This line is the error:
Mar 05 14:41:14 mcoffice mopidy[392]: ERROR [MainThread] mopidy.commands Frontend (HttpFrontend) initialization error: HTTP server startup failed: [Errno 99] Cannot assign requested address

When I issue sudo systemctl restart mopidy, the error disappears, and the web interface is working normally. So I suspect something is not ready on the system at the time Mopidy starts.

I read it elsewhere that the service unit should have After=network.target, so I tried adding that to /lib/systemd/system/mopidy.service, but it made no difference. Also, I saw it already had several “wait for items”:

[Unit]
Description=Mopidy music server
After=avahi-daemon.service
After=dbus.service
After=network-online.target
Wants=network-online.target
After=nss-lookup.target
After=pulseaudio.service
After=remote-fs.target
After=sound.target

What else could be the problem?

(Note this is NOT a RPi, but a desktop PC (thin client).)

Thanks for any pointers in advance!

I just put Type=idle in the unit file ([Service] section), and it works correctly after system boot. This is however, overkill. What is the specific “thing” I need to wait for?

There’s good info at NetworkTarget about this.

On a Raspberry Pi, their “wait for network at boot” option in raspi-config solves this in a less generic way. You’d be better off reading the above systemd page, even if Kali Linux doesn’t use systemd there’s good info there.

Thank you, I’m going to do that!!

Indeed: I had to enable the systemd-networkd-wait-online.service service:

sudo systemctl enable systemd-networkd-wait-online.service

Now it works correctly

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.