-
Notifications
You must be signed in to change notification settings - Fork 18
/
init
executable file
·127 lines (110 loc) · 4.05 KB
/
init
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
#!/usr/bin/bash -x
# BEGINNING BOOTSTRAP SCRIPT
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HOMEDIR=$(eval echo "~`whoami`")
source /etc/environment || :
# Turn off coredumps that seem to happen on smaller, overloaded instances leading to closed-loop feedback
sudo /usr/bin/sed -i 's/#Storage=external/Storage=none/' /etc/systemd/coredump.conf
# determine version
if [ -z "$1" ]; then
VERSION="v2"
else
VERSION="$1"
fi
# Control tier - must form an etcd2 cluster first
if [ "$NODE_ROLE" = "control" ]; then
sudo ${SCRIPTDIR}/$VERSION/util/etcd2-setup.sh $SCRIPTDIR
fi
if [ "$NODE_ROLE" = "it-hybrid" ]; then
sudo ${SCRIPTDIR}/itv1/util/etcd2-setup.sh $SCRIPTDIR
fi
if [ "$NODE_ROLE" = "control" ];then
etcdctl get /docker/config/logs-max-size
if [[ $? = 4 ]]; then
etcdctl set /docker/config/logs-max-size 10m
fi
etcdctl get /docker/config/logs-max-file
if [[ $? = 4 ]]; then
etcdctl set /docker/config/logs-max-file 10
fi
fi
# SETUP profile.d - etcdctl.sh needed by iam-proxy for etcdctl call
sudo mkdir /etc/profile.d || :
sudo cp ${SCRIPTDIR}/$VERSION/profile.d/* /etc/profile.d/. 2>/dev/null || :
sudo cp --dereference ${SCRIPTDIR}/$VERSION/profile.d/${NODE_ROLE}/* /etc/profile.d/.
# Worker tier - must run the IAM proxy setup before any other containers
# Version v2 of util scripts does not have this file
if [[ "$NODE_ROLE" = "worker" && -f ${SCRIPTDIR}/$VERSION/util/iam-proxy.sh ]]; then
sudo ${SCRIPTDIR}/$VERSION/util/iam-proxy.sh $SCRIPTDIR
fi
# run appropriate setup-credentials script
# must happen after etcd2 peers so that etcdctl can actually be used
${SCRIPTDIR}/$VERSION/util/setup-credentials.sh || :
# SETUP SCRIPTS
for script in $(ls ${SCRIPTDIR}/$VERSION/setup|grep -e '.sh$')
do
sudo -E ${SCRIPTDIR}/$VERSION/setup/${script}
done
# ETCD OVERRIDES
# This must be after setup scripts are run so that defaults don't overwrite
# custom-provided etcd vals
${SCRIPTDIR}/$VERSION/util/seed-etcd.sh || :
# The mesos-credentials.sh script must run after seed-etcd.sh
sudo ${SCRIPTDIR}/$VERSION/util/mesos-credentials.sh || :
etcdctl get /environment/SCRIPTS-FORK
if [[ $? = 4 ]]; then
# 4 == 404 - key not found
# case where a node is joining a pre-existing cluster
SCRIPTS_REV=$(cd $SCRIPTDIR && git rev-parse HEAD)
etcdctl set /environment/SCRIPTS-FORK adobe-platform
etcdctl set /environment/SCRIPTS-SHA $SCRIPTS_REV
fi
# CURRENT_REV=$(cd $SCRIPTDIR && git rev-parse HEAD)
# CLUSTER_REV=$(etcdctl get /environment/SCRIPTS-SHA)
# if [[ "$CLUSTER_REV" != "$CURRENT_REV" ]]; then
# cd $SCRIPTDIR && git reset --hard && git checkout $CLUSTER_REV
# $SCRIPTDIR/init $1
# exit 0
# fi
# start services specified in $(etcdctl get /environment/services)
# mapped to the /opt directory of these scripts
etcdctl get /environment/services
if [[ $? = 4 ]]; then
etcdctl set /environment/services "sumologic datadog"
fi
for service in $(etcdctl get /environment/services)
do
servicedir=${SCRIPTDIR}/${VERSION}/opt/${service}
if [[ ! -d $servicedir ]]; then
continue
fi
for unit in $(ls $servicedir|grep -e '.service$\|.timer$')
do
sudo fleetctl submit $servicedir/$unit
sudo fleetctl start $unit
done
done
function submit-fleet-unit() {
sudo fleetctl submit $@
while [ $? != 0 ]; do sleep 1; sudo fleetctl submit $@; done
}
# FLEET UNITS SPECIFIC TO THIS NODE
for unit in $(ls ${SCRIPTDIR}/$VERSION/fleet-local/${NODE_ROLE}|grep -e '.service$')
do
submit-fleet-unit ${SCRIPTDIR}/$VERSION/fleet-local/${NODE_ROLE}/${unit}
sudo fleetctl start "${unit%.service}${COREOS_PRIVATE_IPV4}"
done
# GENERAL-PURPOSE UNITS
for unit in $(ls ${SCRIPTDIR}/$VERSION/fleet|grep -e '.service$\|.timer$')
do
submit-fleet-unit ${SCRIPTDIR}/$VERSION/fleet/${unit}
sudo fleetctl start ${SCRIPTDIR}/$VERSION/fleet/${unit}
done
# hack to destroy harmful units on IT
if [ "$NODE_ROLE" = "it-hybrid" ]; then
fleetctl destroy docker-cleanup.timer
fleetctl destroy docker-cleanup.service
fleetctl destroy logrotate.service
fleetctl destroy update-os.service
fleetctl destroy fd-hud.service
fi