Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 - 1
#!/bin/sh
2
#
3
### BEGIN INIT INFO
4
# Provides: dhcpd
5
# Default-Start:
6
# Default-Stop:
7
# Should-Start: portreserve
8
# Required-Start: $network
9
# Required-Stop:
10
# Short-Description: Start and stop the DHCP server
11
# Description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP)
12
#              server.
13
### END INIT INFO
14
#
15
# The fields below are left around for legacy tools (will remove later).
16
#
17
# chkconfig: - 65 35
18
# description: dhcpd provides the Dynamic Host Configuration Protocol (DHCP) \
19
#              server
20
# processname: dhcpd
21
# config: /etc/dhcp/dhcpd.conf
22
# config: /var/lib/dhcpd/dhcpd.leases
23
# pidfile: /var/run/dhcpd.pid
24
 
25
. /etc/rc.d/init.d/functions
26
 
27
RETVAL=0
28
 
29
prog=dhcpd
30
user=dhcpd
31
group=dhcpd
32
exec=/usr/sbin/dhcpd
33
lockfile=/var/lock/subsys/dhcpd
34
pidfile=/var/run/dhcpd.pid
35
statedir=/var/lib/dhcpd
36
 
37
[ -f /etc/sysconfig/dhcpd ] && . /etc/sysconfig/dhcpd
38
 
39
# if the user specified a different config file, make sure we reference it
40
findConfig() {
41
    for arg in $DHCPDARGS ; do
42
        if [ "$found" = 1 ]; then
43
            [ -f "$arg" ] && echo "$arg"
44
            return
45
        fi
46
        if [ "$arg" = "-cf" ]; then
47
            found=1
48
            continue
49
        fi
50
    done
51
    echo "/etc/dhcp/dhcpd.conf"
52
}
53
 
54
config="$(findConfig "$DHCPDARGS")"
55
 
56
if [ ! -f $statedir/dhcpd.leases ] ; then
57
    mkdir -p $statedir
58
    touch $statedir/dhcpd.leases
59
    [ -x /sbin/restorecon ] && [ -d /selinux ] && /sbin/restorecon $statedir/dhcpd.leases >/dev/null 2>&1
60
fi
61
 
62
configtest() {
63
    [ -x $exec ] || return 5
64
    [ -f $config ] || return 6
65
    $exec -q -t -cf $config
66
    RETVAL=$?
67
    if [ $RETVAL -eq 1 ]; then
68
        $exec -t -cf $config
69
    else
70
        echo "Syntax: OK" >&2
71
    fi
72
    return $RETVAL
73
}
74
 
75
rh_status() {
76
    status -p $pidfile $exec
77
}
78
 
79
rh_status_q() {
80
    rh_status >/dev/null 2>&1
81
}
82
 
83
start() {
84
    [ `id -u` -eq 0 ] || return 4
85
    [ -x $exec ] || return 5
86
    [ -f $config ] || return 6
87
 
88
    rh_status_q && return 0
89
 
90
    echo -n $"Starting $prog: "
91
 
92
    # tell portreserve to release the port
93
    [ -x /sbin/portrelease ] && /sbin/portrelease dhcpd &>/dev/null || :
94
 
95
    daemon --pidfile=$pidfile $exec -user $user -group $group $DHCPDARGS 2>/dev/null
96
    RETVAL=$?
97
 
98
    echo
99
    [ $RETVAL -eq 0 ] && touch $lockfile
100
    return $RETVAL
101
}
102
 
103
stop() {
104
    [ `id -u` -eq 0 ] || return 4
105
 
106
    rh_status_q || return 0
107
 
108
    echo -n $"Shutting down $prog: "
109
    killproc -p $pidfile $prog
110
    RETVAL=$?
111
 
112
    echo
113
    [ $RETVAL -eq 0 ] && rm -f $lockfile
114
    return $RETVAL
115
}
116
 
117
usage() {
118
    echo $"Usage: $0 {start|stop|restart|force-reload|condrestart|try-restart|configtest|status}"
119
}
120
 
121
if [ $# -gt 1 ]; then
122
    exit 2
123
fi
124
 
125
case "$1" in
126
    start)
127
        start
128
        ;;
129
    stop)
130
        stop
131
        ;;
132
    restart|force-reload)
133
        stop ; start
134
        ;;
135
    condrestart|try-restart)
136
        rh_status_q || exit 0
137
        stop ; start
138
        ;;
139
    reload)
140
        usage
141
        # unimplemented feature
142
        exit 3
143
        ;;
144
    configtest)
145
        configtest
146
        ;;
147
    status)
148
        rh_status
149
        ;;
150
    *)
151
        usage
152
        exit 2
153
        ;;
154
esac
155
 
156
exit $?