-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrebirth.sh
executable file
·112 lines (94 loc) · 2.59 KB
/
rebirth.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
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
#!/bin/bash
# rebirth.sh
#
# A clustered Samba hacking script to kill and restart Samba processes on the
# cluster nodes. This script should be run locally on the individual nodes.
TIMEOUT_SECS=0
DEFAULT_PROCS="ctdbd samba smbd nmbd winbindd"
get_help() {
echo "USAGE: rebirth.sh [<process> ...]
A clustered Samba hacking script to kill and restart Samba processes on the
cluster nodes. This script should be run locally on the individual nodes.
Processes to be killed and restarted can be specified by name as parameters on
the command line. By default, the following list of processes is defined:
$DEFAULT_PROCS
"
}
PROCS=""
RESTART_SAMBA=false
RESTART_CTDB=false
RESTART_WB=false
while [[ $# > 0 ]]; do
PROG="$1"
case $PROG in
ctdb|ctdbd)
PROCS="$PROCS ctdbd"
;;
samba|smb|smbd)
PROCS="$PROCS samba smbd nmbd"
;;
winbind|winbindd|wb)
PROCS="$PROCS winbindd"
;;
all)
PROCS=""
;;
*)
echo "Unknown process: " $PROC
get_help
exit 1
esac
shift
done
PROCS=${PROCS:-"$DEFAULT_PROCS"}
if [[ $PROCS == *"samba"* ]] || [[ $PROCS == *"smbd"* ]] || [[ $PROCS == *"nmbd"* ]]; then
RESTART_SAMBA=true
fi
if [[ $PROCS == *"ctdbd"* ]]; then
RESTART_CTDB=true
fi
if [[ $PROCS == *"winbindd"* ]]; then
RESTART_WB=true
fi
echo "Killing processes [$PROCS]"
killall -9 $PROCS >/dev/null 2>&1
killall -9 $PROCS >/dev/null 2>&1
if $RESTART_SAMBA; then
rm -rf /var/run/witnessd.pid
fi
mkdir -p /var/run/samba
mkdir -p /var/run/ctdb
if $RESTART_CTDB; then
echo -n "Starting CTDB"
bin/default/ctdb/ctdbd --reclock /data/lock-mnt/reclock --pidfile /var/run/ctdb/ctdbd.pid --event-script-dir ctdb/config/events.d/ --public-addresses=/etc/ctdb/public_addresses
N=0
STATUS=$(bin/default/ctdb/ctdb status 2>&1)
NSTATUS=$(echo "$STATUS" | grep "THIS NODE" | awk '{ print $3 }')
until [ "$NSTATUS" == "OK" ] || [ "$NSTATUS" == *"BANNED"* ] || [ "$STATUS" == *"Errno"* ] || [ $N -ge $TIMEOUT_SECS ]; do
echo -n "."
(( N++ ))
sleep 1
STATUS=$(bin/default/ctdb/ctdb status 2>&1)
NSTATUS=$(echo "$STATUS" | grep "THIS NODE" | awk '{ print $3 }')
#echo -n "$NSTATUS"
done
if [ "$NSTATUS" == *"BANNED"* ]; then
echo -e "BANNED?!\nCTDB failed to start, check logs."
exit 1
fi
if [ $N -ge $TIMEOUT_SECS ]; then
echo -e "TIMEOUT!\nCTDB failed to start, check logs."
exit 1
fi
if [ "$STATUS" == *"Errno"* ]; then
echo -e "ERROR!!\nCTDB failed to start, check logs."
echo "$STATUS"
exit 1
fi
echo "OK!"
fi
if $RESTART_SAMBA || $RESTART_WB; then
echo "Starting Samba daemons"
bin/samba >/dev/null 2>&1
fi
echo "Done."