This repository has been archived by the owner on Nov 30, 2021. It is now read-only.
/
boot
executable file
·145 lines (116 loc) · 5.39 KB
/
boot
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
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
#
# This script is designed to be run inside the container
#
# fail hard and fast even on pipelines
set -eo pipefail
# set debug based on envvar
[[ $DEBUG ]] && set -x
# configure etcd
export ETCD_PORT=${ETCD_PORT:-4001}
export ETCD="$HOST:$ETCD_PORT"
export ETCD_PATH=${ETCD_PATH:-/deis/store/gateway}
export HOST_ETCD_PATH=${HOST_ETCD_PATH:-/deis/store/gateway/hosts/$HOST}
export ETCD_TTL=${ETCD_TTL:-10}
# wait for etcd to be available
until etcdctl --no-sync -C $ETCD ls >/dev/null 2>&1; do
echo "waiting for etcd at $ETCD..."
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done
# wait until etcd has discarded potentially stale values
sleep $(($ETCD_TTL+1))
# wait for confd to run once and install initial templates
until confd -onetime -node $ETCD --confdir /app --interval 5 --quiet >/dev/null 2>/dev/null; do
echo "store-gateway: waiting for confd to write initial templates..."
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done
# set the number of placement groups for the default pools - they come up with defaults that are too low
if ! etcdctl --no-sync -C $ETCD get /deis/store/defaultPoolsConfigured >/dev/null 2>&1 ; then
echo "store-gateway: setting pg_num values for default pools..."
function set_until_success {
set +e
echo "store-gateway: checking pool $1..."
if ! ceph osd pool get $1 pg_num | grep "pg_num: $2" ; then
ceph osd pool set $1 pg_num $2 2>/dev/null
PG_SET=$?
until [[ $PG_SET -eq 0 ]]; do
sleep 5
ceph osd pool set $1 pg_num $2 2>/dev/null
PG_SET=$?
done
fi
if ! ceph osd pool get $1 pgp_num | grep "pgp_num: $2" ; then
ceph osd pool set $1 pgp_num $2 2>/dev/null
PGP_SET=$?
until [[ $PGP_SET -eq 0 ]]; do
sleep 5
ceph osd pool set $1 pgp_num $2 2>/dev/null
PGP_SET=$?
done
fi
set -e
}
PG_NUM=`etcdctl --no-sync -C $ETCD get /deis/store/pgNum`
set_until_success data ${PG_NUM}
set_until_success rbd ${PG_NUM}
set_until_success metadata ${PG_NUM}
etcdctl --no-sync -C $ETCD set /deis/store/defaultPoolsConfigured youBetcha >/dev/null
fi
# we generate a key for the gateway. we can do this because we have the client key templated out
if ! etcdctl --no-sync -C $ETCD get /deis/store/gatewayKeyring >/dev/null 2>&1 ; then
ceph-authtool --create-keyring /etc/ceph/ceph.client.radosgw.keyring
chmod +r /etc/ceph/ceph.client.radosgw.keyring
ceph-authtool /etc/ceph/ceph.client.radosgw.keyring -n client.radosgw.gateway --gen-key
ceph-authtool -n client.radosgw.gateway --cap osd 'allow rwx' --cap mon 'allow rwx' /etc/ceph/ceph.client.radosgw.keyring
ceph -k /etc/ceph/ceph.client.admin.keyring auth add client.radosgw.gateway -i /etc/ceph/ceph.client.radosgw.keyring
etcdctl --no-sync -C $ETCD set /deis/store/gatewayKeyring < /etc/ceph/ceph.client.radosgw.keyring >/dev/null
else
etcdctl --no-sync -C $ETCD get /deis/store/gatewayKeyring > /etc/ceph/ceph.client.radosgw.keyring
chmod +r /etc/ceph/ceph.client.radosgw.keyring
fi
if ! radosgw-admin user info --uid=deis >/dev/null 2>&1 ; then
radosgw-admin user create --uid=deis --display-name="Deis" >/dev/null
fi
radosgw-admin user info --uid=deis >/etc/ceph/user.json
# store the access key and secret key for consumption by other services
ACCESS_KEY=`cat /etc/ceph/user.json | python -c 'import json,sys;obj=json.load(sys.stdin);print json.dumps(obj["keys"][0]["access_key"]);' | tr -d '"'`
SECRET_KEY=`cat /etc/ceph/user.json | python -c 'import json,sys;obj=json.load(sys.stdin);print json.dumps(obj["keys"][0]["secret_key"]);' | tr -d '"'`
etcdctl --no-sync -C $ETCD set $ETCD_PATH/accessKey ${ACCESS_KEY} >/dev/null
etcdctl --no-sync -C $ETCD set $ETCD_PATH/secretKey ${SECRET_KEY} >/dev/null
# spawn the service in the background
echo "Starting RADOS gateway..."
/etc/init.d/radosgw start
# smart shutdown on SIGINT and SIGTERM
function on_exit() {
/etc/init.d/radosgw stop
exit 0
}
trap on_exit INT TERM
# spawn confd in the background to update services based on etcd changes
confd -node $ETCD --confdir /app --interval 5 --quiet --watch &
CONFD_PID=$!
echo deis-store-gateway running...
# publish the service to etcd using the injected EXTERNAL_PORT
if [[ ! -z $EXTERNAL_PORT ]]; then
# configure service discovery
PORT=${PORT:-8888}
PROTO=${PROTO:-tcp}
set +e
# wait for the service to become available on PUBLISH port
sleep 1 && while [[ -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do sleep 1; done
# while the port is listening, publish to etcd
while [[ ! -z $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".$PUBLISH\" && \$1 ~ \"$PROTO.?\"") ]] ; do
if etcdctl --no-sync -C $ETCD mk ${ETCD_PATH}/masterLock $HOST --ttl $ETCD_TTL >/dev/null 2>&1 \
|| [[ `etcdctl --no-sync -C $ETCD get ${ETCD_PATH}/masterLock` == "$HOST" ]] ; then
etcdctl --no-sync -C $ETCD set $ETCD_PATH/host $HOST --ttl $ETCD_TTL >/dev/null
etcdctl --no-sync -C $ETCD set $ETCD_PATH/port $EXTERNAL_PORT --ttl $ETCD_TTL >/dev/null
etcdctl --no-sync -C $ETCD update ${ETCD_PATH}/masterLock $HOST --ttl $ETCD_TTL >/dev/null
fi
etcdctl --no-sync -C $ETCD set $HOST_ETCD_PATH/host $HOST --ttl $ETCD_TTL >/dev/null
etcdctl --no-sync -C $ETCD set $HOST_ETCD_PATH/port $EXTERNAL_PORT --ttl $ETCD_TTL >/dev/null
sleep $(($ETCD_TTL/2)) # sleep for half the TTL
done
# if the loop quits, something went wrong
exit 1
fi
wait