English
Ask Your Question
2

How to start a systemd service, after DHCP has initialized the IP-Adress? [closed]

asked 2012-07-11 08:34:00 +0000

wis775 gravatar image

updated 2012-08-05 07:17:50 +0000

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?

edit retag flag offensive reopen delete

The question has been closed for the following reason "the question is answered, right answer was accepted" by Akshay
close date 2013-11-01 17:43:34.165385

4 Answers

Sort by ยป oldest newest most voted
6

answered 2013-02-14 16:36:49 +0000

lennart gravatar image

Short answer:

systemctl enable NetworkManager-wait-online.service

Long answer:

http://www.freedesktop.org/wiki/Software/systemd/NetworkTarget

edit flag offensive delete publish link more

Comments

Thanks, that works on Fedora 19!

Fanaz ( 2013-08-04 09:34:56 +0000 )edit
1

answered 2012-08-06 16:37:02 +0000

In the "After" try adding:

dbus-org.freedesktop.NetworkManager.target

That's the name of the NetworkManager service which controls your card and the dhclient.

edit flag offensive delete publish link more

Comments

wonderful - thx

wis775 ( 2012-08-06 18:02:44 +0000 )edit

You'll also want to include Wants=dbus-org.freedesktop.NetworkManager.target to ensure it's in the same transaction. After= only takes effect if two units are already in the same transaction.

David Strauss ( 2012-12-17 17:46:39 +0000 )edit
0

answered 2013-07-05 17:56:03 +0000

Emmanuel Touzery gravatar image

updated 2013-07-05 18:05:08 +0000

Well, on fedora 19 the other solutions didn't work for me (well I didn't try the one that delays all services just for that... I only want to delay minidlna because it's the only problematic service), so i gave up and went for the ugly-but-it-works solution.

I wrote this script:

#!/usr/bin/sh
ip_row=`ifconfig | grep 192`
while [ ! -n "$ip_row" ]
do
  ip_row=`ifconfig | grep 192`
  sleep 2
done

# OK now there an IP...
/usr/sbin/minidlna -f /etc/minidlna.conf -P /var/run/minidlna/minidlna.pid

I know my IP is going to be 192.*, so I relied on that. Once ifconfig returns at least one row containing "192" i know I have an IP. So I make a loop and once I have an IP then I launch minidlna. Works for me.

So then in /usr/lib/systemd/system/minidlna.service I changed the ExecStart row to start this script instead of starting minidlna directly.

Remember to give exe rights to that script (chmod 755), and you can debug any problems by checking in /var/log/messages and by running the very helpful systemctl status command.

edit flag offensive delete publish link more
0

answered 2013-10-31 18:26:38 +0000

sergeygals gravatar image

updated 2013-10-31 18:27:29 +0000

or just add

Restart=always

RestartSec=5

into the [Service] in the /usr/lib/systemd/system/minidlna.service

edit flag offensive delete publish link more

Comments

works perfect on Fedora 20 too. Many thanks!

li737 ( 2014-01-01 16:58:37 +0000 )edit

Use your votes!

  • Use the 30 daily voting points that you get!
  • Up-vote well framed questions that provide enough information to enable people provide answers.
  • Thank your helpers by up-voting their comments and answers to your questions.
  • Down-voting might cost you karma, but you should consider doing so for incorrect or clearly detrimental questions and answers.

Question tools

Follow
1 follower

Stats

Asked: 2012-07-11 08:34:00 +0000

Seen: 6,668 times

Last updated: Oct 31 '13