]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/initscripts/init.d/dhcp
bc0abcee655a5697e66dc99a2dfa3758ee39d56b
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / dhcp
1 #!/bin/sh
2 # Begin $rc_base/init.d/dhcp
3
4 # Based on sysklogd script from LFS-3.1 and earlier.
5 # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org
6 # Modified for IPFire by Michael Tremer - mitch@ipfire.org
7
8 . /etc/sysconfig/rc
9 . $rc_functions
10 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
11
12 function flush_chains() {
13 iptables -F DHCPGREENINPUT
14 iptables -F DHCPGREENOUTPUT
15 iptables -F DHCPBLUEINPUT
16 iptables -F DHCPBLUEOUTPUT
17 }
18
19 case "$1" in
20 start)
21 flush_chains
22
23 if [ -e /var/ipfire/dhcp/enable_green ]; then
24 devices="${GREEN_DEV}"
25
26 iptables -A DHCPGREENINPUT -i "${GREEN_DEV}" -j DHCPINPUT
27 iptables -A DHCPGREENOUTPUT -o "${GREEN_DEV}" -j DHCPOUTPUT
28 fi
29 if [ -e /var/ipfire/dhcp/enable_blue ]; then
30 devices+=" ${BLUE_DEV}"
31
32 iptables -A DHCPBLUEINPUT -i "${BLUE_DEV}" -j DHCPINPUT
33 iptables -A DHCPBLUEOUTPUT -o "${BLUE_DEV}" -j DHCPOUTPUT
34 fi
35
36 boot_mesg "Starting DHCP Server..."
37 loadproc /usr/sbin/dhcpd -q ${devices}
38
39 (sleep 5 && chmod 644 /var/run/dhcpd.pid) & # Fix because silly dhcpd creates its pid with mode 640
40 ;;
41
42 stop)
43 flush_chains
44
45 boot_mesg "Stopping DHCP Server..."
46 killproc -p /var/run/dhcpd.pid /usr/sbin/dhcpd
47 if [ "$(ps -A | grep " dhcpd")" != "" ] ; then
48 # if fail use the hard way ...
49 boot_mesg "Killing DHCP Server..."
50 killall -w -s KILL /usr/sbin/dhcpd > /dev/null 2>&1
51 rm -f /var/run/dhcpd.pid > /dev/null 2>&1
52 echo_ok;
53 exit 0
54 fi
55 ;;
56
57 reload)
58 boot_mesg "Reloading DHCP Server..."
59 reloadproc /usr/sbin/dhcpd
60 ;;
61
62 restart)
63 $0 stop
64 sleep 1
65 $0 start
66 ;;
67
68 status)
69 statusproc /usr/sbin/dhcpd
70 ;;
71
72 *)
73 echo "Usage: $0 {start|stop|reload|restart|status}"
74 exit 1
75 ;;
76 esac
77
78 # End $rc_base/init.d/dhcp