2

I'd like to start the busybox udhcpd service using systemd.

I have a simple /etc/udhcpd.conf file:

start           192.168.8.20    #default: 192.168.0.20
end             192.168.8.254   #default: 192.168.0.254
interface       wlan0

Here's my /lib/systemd/system/udhcpd.service

[Unit]
Description=DHCP Service

[Service]
ExecStart=/usr/sbin/udhcpd /etc/countx-udhcpd.conf
ExecStartPre=/usr/bin/ip-up.sh

[Install]
WantedBy=multi-user.target

Here's my /usr/bin/ip-up.sh

#!/bin/sh

ip addr add 192.168.8.1 dev wlan0
ip link set wlan0 up

When I run the scripts manually, everything works properly.

But when I run the scripts with systemd, it fails.

systemctl start udhcpd

This is what works:

/usr/bin/udhcpd-ip-up.sh
/usr/sbin/udhcpd /etc/countx-udhcpd.conf

Anyone get this working with systemd?

1 Answers1

1

I got this working with a few modifications.

First I had to use the -f flag when starting udhcpd from systemd. This is putting udhcpd into the foreground. Though this makes no sense, it works.

Second, I need to wait for the networking to come up before running this.

Below are my fixes that get things working in /lib/systemd/system/udhcpd.service

[Unit]
Description=DHCP Service
# wait for network to come up before we run
After=network.target

[Service]
# -f means foreground--not sure why, but it works now
ExecStart=/usr/sbin/udhcpd -f /etc/countx-udhcpd.conf
ExecStartPre=/usr/bin/udhcpd-ip-up.sh

[Install]
WantedBy=multi-user.target

All the other files above are needed. They work properly as is.

  • 2
    You need to set `-f` because by default systemd services are of `Type=simple` meaning that systemd expect the process NOT to fork, this is the preferred way of running a daemon in systemd. If your process has to fork, you need to set the type of the service to `Type=forking` – Bigon Jun 11 '18 at 23:09