forked from adobe-platform/mesos-systemd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init
executable file
·106 lines (92 loc) · 3.41 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
#!/usr/bin/bash -x
# BEGINNING BOOTSTRAP SCRIPT
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
HOMEDIR=$(eval echo "~`whoami`")
source /etc/environment || :
# determine version
if [ -z "$1" ]; then
VERSION="v2"
else
VERSION="$1"
fi
# Control and Bastion tiers - must form an etcd2 cluster first
if [ "$NODE_ROLE" = "control" ] || [ "$NODE_ROLE" = "bastion" ]; 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
# 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 profile.d
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/.
# SETUP SCRIPTS
for script in $(ls ${SCRIPTDIR}/$VERSION/setup|grep -e '.sh$')
do
sudo ${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 || :
# The klam-ssh.sh script must run after seed-etcd.sh
sudo ${SCRIPTDIR}/$VERSION/util/klam-ssh.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