]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/system/dhcp
apache2: Properly re-execute Apache on restart
[ipfire-2.x.git] / src / initscripts / system / dhcp
1 #!/bin/sh
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6 # #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
11 # #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
16 # #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
19 # #
20 ###############################################################################
21
22 . /etc/sysconfig/rc
23 . $rc_functions
24
25 [ -e "/etc/sysconfig/dhcpd" ] && . /etc/sysconfig/dhcpd
26
27 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
28 eval $(/usr/local/bin/readhash /var/ipfire/dhcp/settings)
29
30 function flush_chains() {
31 iptables -F DHCPGREENINPUT
32 iptables -F DHCPGREENOUTPUT
33 iptables -F DHCPBLUEINPUT
34 iptables -F DHCPBLUEOUTPUT
35 }
36
37 case "$1" in
38 start)
39 flush_chains
40
41 if [ -n "${GREEN_DEV}" -a -e "/var/ipfire/dhcp/enable_green" ]; then
42 LISTEN_INTERFACES+=" ${GREEN_DEV}"
43
44 iptables -A DHCPGREENINPUT -i "${GREEN_DEV}" -j DHCPINPUT
45 iptables -A DHCPGREENOUTPUT -o "${GREEN_DEV}" -j DHCPOUTPUT
46 fi
47 if [ -n "${BLUE_DEV}" -a -e "/var/ipfire/dhcp/enable_blue" ]; then
48 LISTEN_INTERFACES+=" ${BLUE_DEV}"
49
50 iptables -A DHCPBLUEINPUT -i "${BLUE_DEV}" -j DHCPINPUT
51 iptables -A DHCPBLUEOUTPUT -o "${BLUE_DEV}" -j DHCPOUTPUT
52 fi
53
54 boot_mesg "Starting DHCP Server..."
55 loadproc /usr/sbin/dhcpd -q ${LISTEN_INTERFACES}
56
57 # Start Unbound DHCP Lease Bridge unless RFC2136 is used
58 if [ "${DNS_UPDATE_ENABLED}" != on ]; then
59 boot_mesg "Starting Unbound DHCP Leases Bridge..."
60 loadproc /usr/sbin/unbound-dhcp-leases-bridge -d
61 fi
62
63 (sleep 5 && chmod 644 /var/run/dhcpd.pid) & # Fix because silly dhcpd creates its pid with mode 640
64 ;;
65
66 stop)
67 flush_chains
68
69 boot_mesg "Stopping DHCP Server..."
70 killproc -p /var/run/dhcpd.pid /usr/sbin/dhcpd
71 if [ "$(ps -A | grep " dhcpd")" != "" ] ; then
72 # if fail use the hard way ...
73 boot_mesg "Killing DHCP Server..."
74 killall -w -s KILL /usr/sbin/dhcpd > /dev/null 2>&1
75 rm -f /var/run/dhcpd.pid > /dev/null 2>&1
76 echo_ok;
77 fi
78
79 boot_mesg "Stopping Unbound DHCP Leases Bridge..."
80 killproc /usr/sbin/unbound-dhcp-leases-bridge
81 ;;
82
83 reload)
84 boot_mesg "Reloading DHCP Server..."
85 reloadproc /usr/sbin/dhcpd
86 ;;
87
88 restart)
89 $0 stop
90 sleep 1
91 $0 start
92 ;;
93
94 status)
95 statusproc /usr/sbin/dhcpd
96 statusproc /usr/sbin/unbound-dhcp-leases-bridge
97 ;;
98
99 *)
100 echo "Usage: $0 {start|stop|reload|restart|status}"
101 exit 1
102 ;;
103 esac