~andreserl/maas/packaging_bzr1693

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
description "MAAS instance of ISC DHCP server"
author "Jeroen Vermeulen <jtv@canonical.com>"

start on runlevel [2345]
stop on runlevel [!2345]

env CONFIG_FILE=/etc/maas/dhcpd.conf
env PID_DIR=/run/maas/dhcp
env PID_FILE=/run/maas/dhcp/dhcpd.pid
env LEASES_DIR=/var/lib/maas/dhcp
env LEASES_FILE=/var/lib/maas/dhcp/dhcpd.leases

# This is where we write what interfaces dhcpd should listen on.
env INTERFACES_FILE=/var/lib/maas/dhcpd-interfaces

pre-start script
    if [ ! -f $CONFIG_FILE ]; then
        echo "$CONFIG_FILE does not exist.  Aborting."
        stop
        exit 0
    fi

    if [ ! -f $INTERFACES_FILE ]; then
        echo "$INTERFACES_FILE does not exist.  Aborting."
        stop
        exit 0
    fi

    if ! /usr/sbin/dhcpd -t -q -4 -cf $CONFIG_FILE > /dev/null 2>&1; then
        echo "dhcpd self-test failed.  Please fix the config file."
        echo "The error was: "
        /usr/sbin/dhcpd -t -4 -cf $CONFIG_FILE
        stop
        exit 0
    fi
end script

respawn
script
    INTERFACES=`cat "${INTERFACES_FILE}"`

    # Allow dhcp server to write lease and pid file.
    mkdir -p $PID_DIR
    chown dhcpd:dhcpd $PID_DIR

    # As of Quantal, the leases file must be owned by root:root (even though
    # the daemon will run under an unprivileged user).
    # In Precise, ownership was supposed to be dhcpd:dhcpd.
    #
    # maas packages on saucy are only supported with newer isc-dhcp via
    # the cloud-archive.  See bug 1231693 for more information, including
    # a patch that would actually work to support all, but is complex.
    
    mkdir -p $LEASES_DIR
    chown root:root $LEASES_DIR
    [ -e $LEASES_FILE ] || touch $LEASES_FILE
    for LFILE in $LEASES_FILE $LEASES_FILE~; do
        if [ -e $LFILE ]; then
            chown root:root $LFILE
            chmod a+r $LFILE
        fi
    done

    exec /usr/sbin/dhcpd -user dhcpd -group dhcpd -f -q -4 -pf $PID_FILE -cf $CONFIG_FILE -lf $LEASES_FILE $INTERFACES
end script