-
Notifications
You must be signed in to change notification settings - Fork 0
/
restart.sh
executable file
·69 lines (58 loc) · 1.23 KB
/
restart.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
#!/bin/bash
function usage()
{
echo "Usage:$0 [[ip1] [ip2]...] [-h|--help]"
echo "[[ip1] [ip2]...]"
echo -e "\tIPs of all nodes, use space seperate, if not given then restart osd daemon on current machine."
echo "[-h, --help]"
echo -e "\tget this help info"
}
if ! temp=$(getopt -o h --long help -n 'note' -- "$@" 2>&1)
then
echo "parse arguments failed, $temp"
usage
exit 1
fi
eval set -- "$temp"
while true
do
case "$1" in
-h|--help) usage; exit 1;;
--) shift; break;;#??
*) echo "$1 unknown parameter"; exit 1;;
esac
done
arr_all_nodes=($@)
re_start="
python=\"
import json
s = json.loads('\$(echo \$(sudo ceph node ls osd))')
for osd in s[\\\"\$(hostname)\\\"]:
print osd
\"
osds=\$(echo \"\$python\" | python)
for osd in \$osds
do
echo stopping osd.\$osd
sudo kill \$(ps aux | grep -w \"[c]eph-osd -i \$osd\" | awk '{print \$2}') &> /dev/null
while [ x\"\`ps aux | grep -w \\\"[c]eph-osd -i \$osd\\\"\`\" != x ]
do
#echo stopping osd.\$osd
sleep 1
done
sudo ceph-osd -i \$osd
done
"
len=${#arr_all_nodes[@]}
if [ x"$len" = x0 ]
then
echo "re-starting osd on `hostname`..."
eval "$re_start"
exit $?
fi
for node in ${arr_all_nodes[@]}
do
echo "re-starting osd on $node..."
ssh $node "$re_start"
done
exit 0