-
Notifications
You must be signed in to change notification settings - Fork 2
/
run
executable file
·131 lines (117 loc) · 3.03 KB
/
run
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
usage() {
echo "usage: run <hosts ... >"
exit 1
}
if [ -z "$*" ]; then
usage
fi
if [ ! -f bootstrap -o ! -f setup -o ! -f maintenance -o ! -f build ]; then
echo "Missing files, in the right directory?"
exit 1
fi
mkdir -p logs
for host in "$@"; do
((
echo "Copying to host ... waiting"
scp -r -i ~/.ssh/dasbot.opendnssec.org \
-oStrictHostKeyChecking=no \
-oPreferredAuthentications=publickey \
-oServerAliveInterval=10 \
-oServerAliveCountMax=12 \
-oConnectTimeout=30 \
-- \
bootstrap \
setup \
maintenance \
build \
keys \
"dasbot@$host": >/dev/null ||
exit 1
echo "Copying to host ... done"
for what in bootstrap setup maintenance build; do
echo "Running $what ... waiting"
echo "Running $what at `date`" >> "logs/$host.log"
rm -rf -- "logs/$host.last.$what"
touch -- "logs/$host.last.$what"
ssh -q -i ~/.ssh/dasbot.opendnssec.org \
-oStrictHostKeyChecking=no \
-oPreferredAuthentications=publickey \
-oServerAliveInterval=10 \
-oServerAliveCountMax=12 \
-oConnectTimeout=30 \
-- \
dasbot@$host \
"./$what 2>&1" >>"logs/$host.last.$what" 2>&1
status="$?"
if [ "$status" = "0" ]; then
try=0
while true; do
if [ $try -gt 10 ]; then
echo "... ERROR unknown at `date`" >> "logs/$host.log"
echo "Running $what ... ERROR unknown: no DONE in last log"
exit 1
fi
if tail -n 1 -- "logs/$host.last.$what" | grep -q '^DONE'; then
break
fi
try=$(( try + 1 ))
sleep 0.5
done
fi
cat -- "logs/$host.last.$what" >> "logs/$host.log"
if [ "$status" != "0" ]; then
echo "... ERROR $status at `date`" >> "logs/$host.log"
echo "Running $what ... ERROR $status:"
tail -n 6 -- "logs/$host.last.$what" | head -n 5
echo "ERROR $status" >>"logs/$host.last.$what"
exit 1
fi
echo "Running $what ... done"
echo "... done at `date`" >> "logs/$host.log"
if tail -n 1 -- "logs/$host.last.$what" | grep -q 'REBOOT'; then
echo "Rebooting ... waiting"
echo "Rebooting at `date`" >> "logs/$host.log"
sleep 120
try=0
while true; do
if [ $try -gt 120 ]; then
echo "Rebooting ... ERROR waited too long"
echo "... ERROR rebooting at `date`" >> "logs/$host.log"
exit 1
fi
up=`ssh -q -i ~/.ssh/dasbot.opendnssec.org \
-oStrictHostKeyChecking=no \
-oPreferredAuthentications=publickey \
-oServerAliveInterval=10 \
-oServerAliveCountMax=12 \
-oConnectTimeout=30 \
-- \
dasbot@$host \
echo OK 2>/dev/null`
if [ "$up" = "OK" ]; then
break
fi
try=$(( try + 1 ))
sleep 10
done
echo "Rebooting ... done"
echo "... done at `date`" >> "logs/$host.log"
fi
done
) | while read line; do
echo "$host: $line"
done) &
done
wait
for host in "$@"; do
last_logs=`ls -1 -- "logs/$host.last."* 2>/dev/null`
if [ -z "$last_logs" ]; then
echo "Missing last log for $host"
exit 1
fi
if tail -n 1 -- "logs/$host.last."* | grep '^ERROR'; then
exit 1
fi
done
exit 0