Mopidy service at boot

I am using mopidy as a service on my raspberry, connected to wifi. I am noticing that qhen I reboot the raspi, Spotify and other onine services are not available, and they fail. I always ahave to restart mopidy service manually after a reboot. Looking at the logs it seems that mopidy starts before dhcpd added a default route. How can I let mopidy service to start only when a stable connection is reached?

Dec 25 10:19:50 pab mopidy[420]: INFO     Starting Mopidy 2.3.1
Dec 25 10:19:50 pab mopidy[420]: INFO     Loading config from builtin defaults
Dec 25 10:19:50 pab mopidy[420]: INFO     Loading config from /etc/mopidy/mopidy.conf
Dec 25 10:19:50 pab mopidy[420]: INFO     Loading config from command line options
Dec 25 10:19:51 pab mopidy[420]: INFO     Enabled extensions: spotify, mpd, alsamixer, http, alarmcl
ock, stream, spotify_tunigo, m3u, scrobbler, podcast-itunes, internetarchive, iris, cd, softwaremixe
r, local-sqlite, file, local-images, podcast, local, tunein, soundcloud
Dec 25 10:19:51 pab mopidy[420]: INFO     Disabled extensions: none
Dec 25 10:19:52 pab mopidy[420]: INFO     Starting Mopidy mixer: SoftwareMixer
Dec 25 10:19:52 pab mopidy[420]: INFO     Mixer volume set to 90
Dec 25 10:19:52 pab mopidy[420]: INFO     Starting Mopidy audio
Dec 25 10:19:52 pab mopidy[420]: INFO     Starting Mopidy backends: StreamBackend, M3UBackend, FileB
ackend, LocalBackend, TuneInBackend, SpotifyBackend, SpotifyTunigoBackend, SoundCloudBackend, Podcas
tBackend, iTunesPodcastBackend, InternetArchiveBackend, CdBackend
Dec 25 10:19:52 pab mopidy[420]: INFO     Audio output set to "alsasink"
Dec 25 10:19:52 pab mopidy[420]: INFO     Loaded 598 local tracks using images
Dec 25 10:19:52 pab mopidy[420]: ERROR    SoundCloud API request failed: HTTPSConnectionPool(host='a
pi.soundcloud.com', port=443): Max retries exceeded with url: /me?client_id=93e33e327fd8a9b77becd179
652272e2 (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x73089af0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution',))
Dec 25 10:19:53 pab mopidy[420]: INFO     Starting Mopidy core
Dec 25 10:19:53 pab mopidy[420]: ERROR    Spotify login error: <ErrorType.OTHER_PERMANENT: 10>
Dec 25 10:19:53 pab mopidy[420]: INFO     Starting Mopidy frontends: MpdFrontend, HttpFrontend, ScrobblerFrontend, IrisFrontend
Dec 25 10:19:53 pab mopidy[420]: INFO     MPD server running at [::ffff:0.0.0.0]:6600
Dec 25 10:19:53 pab mopidy[420]: INFO     HTTP server running at [::ffff:0.0.0.0]:6680
Dec 25 10:19:53 pab mopidy[420]: ERROR    Error during Last.fm setup: NetworkError: [Errno -3] Temporary failure in name resolution
Dec 25 10:19:53 pab mopidy[420]: INFO     Starting Iris 3.43.0
Dec 25 10:19:53 pab mopidy[420]: INFO     Starting GLib mainloop
Dec 25 10:19:55 pab dhcpcd[373]: wlan0: using static address 192.168.1.59/24

One of the options in raspi-config (somewhere, advanced?) is to wait for network during boot. Is that enabled?

Ooops! It was not. Thank you

I wish they’d made it the default in Raspbian and better handled the cases where the network is missing. I think maybe they did it to showcase how each RPi generation is faster (boots faster). We could add it to our docs but we’ve already got quite a bit of stuff there and we need to stop somewhere. I’d probably merge a PR with it if someone’s feels strongly.

If you’re starting mopidy as a systemd service then you could also specify After=network.target in the unit.