-
Notifications
You must be signed in to change notification settings - Fork 16
/
etcd_bootstrap_script.sh
executable file
·92 lines (85 loc) · 2.46 KB
/
etcd_bootstrap_script.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
#!/bin/sh
VALIDATION_MARKER=/var/etcd/data/validation_marker
# Add self-signed CA to list of root CA-certificates
if [ $ENABLE_TLS = 'true' ]
then
cat /var/etcd/ssl/client/ca/*.crt >> /etc/ssl/certs/ca-certificates.crt
if [ $? -ne 0 ]
then
echo "failed to update root certificate list"
exit 1
fi
fi
trap_and_propagate() {
PID=$1
shift
for sig in "$@" ; do
trap "kill -$sig $PID" "$sig"
done
}
start_managed_etcd(){
rm -rf $VALIDATION_MARKER
CONFIG_FILE=/etc/etcd.conf.yaml
curl --retry 5 --retry-delay 5 --retry-all-errors "$BACKUP_ENDPOINT/config" -o $CONFIG_FILE
minimumsize=50
actualsize=$(wc -c <$CONFIG_FILE)
if [ $actualsize -le $minimumsize ]; then
echo "downloaded config file size is less than $(minimumsize) bytes"
exit 1
fi
etcd --config-file $CONFIG_FILE &
ETCDPID=$!
trap_and_propagate $ETCDPID INT TERM
wait $ETCDPID
RET=$?
echo $RET > $VALIDATION_MARKER
exit $RET
}
check_and_start_etcd(){
while true;
do
wget "$BACKUP_ENDPOINT/initialization/status" -S -O status;
STATUS=$(cat status);
case $STATUS in
"New")
wget "$BACKUP_ENDPOINT/initialization/start?mode=$1$FAIL_BELOW_REVISION_PARAMETER" -S -O - ;;
"Progress")
sleep 1;
continue;;
"Failed")
sleep 1;
continue;;
"Successful")
echo "Bootstrap preprocessing end time: $(date)"
start_managed_etcd
break
;;
*)
sleep 1;
;;
esac;
done
}
umask 0077
if [ $? -ne 0 ]
then
echo "failed to set umask to 0077"
exit 1
fi
echo "Bootstrap preprocessing start time: $(date)"
if [ ! -f $VALIDATION_MARKER ] ;
then
echo "No $VALIDATION_MARKER file. Perform complete initialization routine and start etcd."
check_and_start_etcd full
else
echo "$VALIDATION_MARKER file present. Check return status and decide on initialization"
run_status=$(cat $VALIDATION_MARKER)
echo "$VALIDATION_MARKER content: $run_status"
if [ $run_status = '143' ] || [ $run_status = '130' ] || [ $run_status = '0' ] ; then
echo "Requesting sidecar to perform sanity validation"
check_and_start_etcd sanity
else
echo "Requesting sidecar to perform full validation"
check_and_start_etcd full
fi
fi