How to start a systemd service, after DHCP has initialized the IP-Adress? [closed]
I have installed minidlna from the rpmfusion-free repository and it doesn't start sucessfully via systemd at system startup.
The start of minidlna via terminal does work.
sudo systemctl start minidlna.service
The short story
My system gets the IP-Adress via DHCP and it seems, that minidlna tries to start, at a time, when still no IP-Adress is assigned to my system through DHCP.
The long story:
With the installation, i got a minidlna.service configuration like this.
/etc/systemd/system/multi-user.target.wants/minidlna.service
[Unit]
Description=MiniDLNA is a DLNA/UPnP-AV server software
After=syslog.target local-fs.target network.target
[Service]
Type=forking
PIDFile=/var/run/minidlna.pid
ExecStart=/usr/sbin/minidlna -f /etc/minidlna.conf
[Install]
WantedBy=multi-user.target
I enabled the service via
sudo systemctl enable minidlna.service
Now, minidlna is trying to start during system startup and fails to start.
This is the status:
sudo systemctl status minidlna.service
minidlna.service - MiniDLNA is a DLNA/UPnP-AV server software Loaded: loaded (/usr/lib/systemd/system/minidlna.service; enabled) Active: failed (Result: exit-code) since Wed, 11 Jul 2012 09:13:13 +0200; 1h 2min ago Process: 782 ExecStart=/usr/sbin/minidlna -f /etc/minidlna.conf (code=exited, status=1/FAILURE) CGroup: name=systemd:/system/minidlna.service
Looking in messages.log, i see, that there must be a problem with the network interface.
NetworkManager[716]: <info> dhclient started with pid 808
NetworkManager[716]: <info> Activation (em1) Stage 3 of 5 (IP Configure Start) complete.
minidlna.service: control process exited, code=exited status=1
...
minidlna.c:369: No MAC address found. Falling back to generic UUID.
getifaddr.c:113: error: Network interface eth0 not found
getifaddr.c:113: error: Network interface eth1 not found
minidlna.c:758: No IP address automatically detected!
...
dhclient[808]: DHCPREQUEST on em1 to 255.255.255.255 port 67 (xid=0x754a3b86)
dhclient[808]: DHCPACK from 10.0.0.138 (xid=0x754a3b86)
NetworkManager[716]: <info> (em1): DHCPv4 state changed preinit -> reboot
The IP-Adress is assigned via DHCP to my system and the messages.log indicates, that the NetworkManager has not finished all steps, when minidlna tries to start.
I think, the overall question must be - How to enforce minidlna, that it starts, after the NetworkManager has completed his work?
Short answer:
systemctl enable NetworkManager-wait-online.service
Long answer:
http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget
Thanks, that works on Fedora 19!