Comment 20 for bug 1448657

Revision history for this message
LyckeleB (lyckeleb) wrote :

However, the service still couldn't create a PID-file after a reboot. So I tweaked a little bit longer.

It turns out that the isc-dhcp-server is started before the temporary filesystem "/run".
The lines "Wants=local-fs.target", "After=local-fs.target" and "sleep 3 ; \" solves that.

Security by apparmor requires the creation of the PID-file in "/{,var/}run/{,dhcp-server/}dhcpd{,6}.pid rw,". The lines
    "if [ ! -d /run/dhcp-server ]; then mkdir -p /run/dhcp-server; fi; \"
    "chown root:dhcpd /run/dhcp-server; \"
    "chmod ug=rwx,o=rx /run/dhcp-server; \"
    "sleep 1; \"
enables this.

This tweaking resulted in the following "/etc/systemd/system/isc-dhcp-server.services" file.

========================================================

[Unit]
Description=ISC DHCP IPv4 server
Documentation=man:dhcpd(8)
Wants=network-online.target
Wants=local-fs.target
After=network-online.target
After=local-fs.target
After=time-sync.target
ConditionPathExists=/etc/default/isc-dhcp-server
ConditionPathIsMountPoint=/run
ConditionPathExists=|/etc/ltsp/dhcpd.conf
ConditionPathExists=|/etc/dhcp/dhcpd.conf

[Service]
EnvironmentFile=/etc/default/isc-dhcp-server
RuntimeDirectory=dhcp-server
# The leases files need to be root:dhcpd even when dropping privileges
ExecStart=/bin/sh -ec '\
    sleep 3 ; \
    CONFIG_FILE=/etc/dhcp/dhcpd.conf; \
    if [ -f /etc/ltsp/dhcpd.conf ]; then CONFIG_FILE=/etc/ltsp/dhcpd.conf; fi; \
    if [ ! -d /run/dhcp-server ]; then mkdir -p /run/dhcp-server; fi; \
    chown root:dhcpd /run/dhcp-server; \
    chmod ug=rwx,o=rx /run/dhcp-server; \
    sleep 1; \
    if [ ! "$DHCPDv4_PID" ] ; then DHCPDv4_PID=/run/dhcp-server/dhcpd.pid; fi; \
    [ -e /var/lib/dhcp/dhcpd.leases ] || touch /var/lib/dhcp/dhcpd.leases; \
    chown root:dhcpd /var/lib/dhcp /var/lib/dhcp/dhcpd.leases; \
    chmod 775 /var/lib/dhcp ; chmod 664 /var/lib/dhcp/dhcpd.leases; \
    exec dhcpd -user dhcpd -group dhcpd -f -4 -pf $DHCPDv4_PID -cf $CONFIG_FILE $INTERFACESv4'

[Install]
WantedBy=multi-user.target

==================================================

I hope this helps. Any suggestion to improve this service-file is appreciated :)