-
Notifications
You must be signed in to change notification settings - Fork 4
/
restart-dhcp-clients.sh
executable file
·64 lines (52 loc) · 2.54 KB
/
restart-dhcp-clients.sh
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
#!/bin/bash
########################################################################
#
# RE-INITIATE FULL DHCPv4 and DHCPv6 DISCOVER SEQUENCES :
# - force RELEASE of udhcpc (DHCPv4 client) via SIGUSR2
# - properly stop both udhcpc and odhcp6c via SIGTERM
# - both will be automaticaly restarted by ubios-udapi-server
#
########################################################################
DHCP4C_BIN="udhcpc" # Unifi's binary name (not path) for DHCPv4 client
DHCP6C_BIN="odhcp6c" # Unifi's binary name (not path) for DHCPv6 client
###########################################################
# MESSAGE UTILITIES #
###########################################################
green='\E[32m'; red='\E[31m'; yellow='\E[33m'; clear='\E[0m'
colorGreen() { printf "$green$1$clear"; }
colorRed() { printf "$red$1$clear"; }
colorYellow() { printf "$yellow$1$clear"; }
errExit() {
>&2 echo "$HDR $(colorRed 'ERROR:') $1"
exit 1
}
###########################################################
# MAIN SECTION #
###########################################################
HDR="[restart-dhcp-clients]" # header set in all messages
[[ "$1" == "-f" ]] && opt_follow=1 || opt_follow=0
if ps -o cmd= -C ${DHCP6C_BIN} &>/dev/null; then
dhcpv6_process=${DHCP6C_BIN}
elif ps -o cmd= -C ${DHCP6C_BIN}-org &>/dev/null; then
dhcpv6_process=${DHCP6C_BIN}-org
else
echo "$HDR $(colorYellow 'NOTE:') DHCPv6 client process is not running, it needs to be activated in the WAN settings"
dhcpv6_process=""
fi
if [[ -n "${dhcpv6_process}" ]]; then
echo "$HDR $(colorGreen 'Restarting DHCPv4 (udhcpc) and DHCPv6 (odhcp6c) clients') to take updates into account"
echo "$HDR (this will initiate a DHCPv4+v6 Discover process, and should not interrupt your connection...)"
else
echo "$HDR $(colorGreen 'Restarting DHCPv4 (udhcpc) client')"
echo "$HDR (this will initiate a DHCPv4 Discover process, and should not interrupt your connection...)"
fi
killall -s SIGUSR2 ${DHCP4C_BIN} # Force DHCPv4 RELEASE before restarting udhcpc because Unifi doesn't set the -R option
sleep 1 #....and ISP wants a proper RELEASE of both v4 and v6 leases before re-discover etc..
killall ${DHCP4C_BIN} ${dhcpv6_process}
if [[ $opt_follow -eq 1 ]]; then
tail -f /var/log/daemon.log | grep -E 'dhcpc|odhcp6c|dhcpv6-mod'
else
echo "$HDR Restart done, you can now check dhcp client logs with :"
echo "grep -E 'dhcpc|odhcp6c|dhcpv6-mod' /var/log/daemon.log"
fi
exit 0