File: ltsp-dhcpd.init

package info (click to toggle)
ltsp 5.2.4-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 4,932 kB
  • ctags: 271
  • sloc: sh: 5,267; ansic: 1,048; perl: 225; python: 211; lex: 152; makefile: 112; yacc: 59
file content (156 lines) | stat: -rwxr-xr-x 3,463 bytes parent folder | download | duplicates (10)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/bin/sh
#
### BEGIN INIT INFO
# Provides: ltsp-dhcpd
# Default-Start:
# Default-Stop: 0 1 6
# Should-Start:
# Required-Start: $network
# Required-Stop:
# Short-Description: Start and stop the DHCP server
# Description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP)
#              server.
### END INIT INFO
#
# The fields below are left around for legacy tools (will remove later).
#
# chkconfig: - 98 35
# description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP) \
#              server
# processname: dhcpd
# config: /etc/ltsp/dhcpd.conf
# config: /var/lib/dhcpd/dhcpd.leases
# pidfile: /var/run/dhcpd.pid

. /etc/init.d/functions

RETVAL=0

prog=dhcpd
dhcpd=/usr/sbin/dhcpd
lockfile=/var/lock/subsys/ltsp-dhcpd
pidfile=/var/run/ltsp-dhcpd.pid

[ -f /etc/sysconfig/ltsp-dhcpd ] && . /etc/sysconfig/ltsp-dhcpd

# if the user specified a different config file, make sure we reference it
findConfig() {
    for arg in $DHCPDARGS ; do
        if [ "$found" = 1 ]; then
            [ -f "$arg" ] && echo "$arg"
            return
        fi
        if [ "$arg" = "-cf" ]; then
            found=1
            continue
        fi
    done
    echo "/etc/ltsp/dhcpd.conf"
}

conf="$(findConfig "$DHCPDARGS")"
if [ ! "$found" ]; then
   DHCPDARGS="$DHCPARGS -cf $conf"
fi

if [ ! -f /var/lib/dhcpd/dhcpd.leases ] ; then
    mkdir -p /var/lib/dhcpd
    touch /var/lib/dhcpd/dhcpd.leases
    [ -x /sbin/restorecon ] && [ -d /selinux ] && /sbin/restorecon /var/lib/dhcp/dhcpd.leases >/dev/null 2>&1
fi

configtest() {
    [ -x $dhcpd ] || return 5
    [ -f $conf ] || return 6
    $dhcpd -q -t -cf $conf
    RETVAL=$?
    return $RETVAL
}

start() {
    [ -x $dhcpd ] || return 5
    [ -f $conf ] || return 6

    pidofproc $prog >/dev/null 2>&1
    RETVAL=$?
    [ $RETVAL -eq 0 ] && return $RETVAL

    echo -n "Starting ltsp-$prog:"
    daemon $dhcpd $DHCPDARGS 2>/dev/null
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch $lockfile

    # Ugly Hack!  Live LTSP Server needs something to copy ssh keys into the client chroot *once* after sshd generated its keys on first boot.
    # Putting this here for now because we have nowhere else to put it at the moment, and it is harmless.
    if [ -e /etc/ltsp/DELETE-ME-WHEN-DONE-need-to-copy-sshkeys ]; then
        /usr/sbin/ltsp-update-sshkeys
        rm -f /etc/ltsp/DELETE-ME-WHEN-DONE-need-to-copy-sshkeys
    fi
    return $RETVAL
}

stop() {
    pidofproc $prog >/dev/null 2>&1
    if [ $? -ne 0 ]; then
        RETVAL=7
        return $RETVAL
    fi

    echo -n "Shutting down ltsp-$prog:"
    killproc $prog
    RETVAL=$?

    [ $RETVAL = 0 ] && success || failure
    echo
    [ $RETVAL = 0 ] && rm -f $lockfile
    return $RETVAL
}

if [ ! -x $dhcdbd ]; then
    RETVAL=5
    exit $RETVAL
fi

if [ $# -gt 1 ]; then
    RETVAL=2
    exit $RETVAL
fi

case "$1" in
    start)
        start
        RETVAL=$?
        ;;
    stop)
        stop
        RETVAL=$?
        ;;
    restart|force-reload)
        stop; start
        RETVAL=$?
        ;;
    try-restart|reload)
        RETVAL=3
        ;;
    condrestart)
        if [ -f $lockfile ]; then
            stop && start
            RETVAL=$?
        fi
        ;;
    configtest)
        configtest
        RETVAL=$?
        ;;
    status)
        status $dhcpd
        RETVAL=$?
        ;;
    *)
        echo "Usage: $0 {start|stop|restart|condrestart|configtest|status}"
        RETVAL=3
        ;;
esac

exit $RETVAL