-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.sh
executable file
·106 lines (89 loc) · 3.84 KB
/
entrypoint.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env sh
# MIT License
#
# (C) Copyright 2021-2022 Hewlett Packard Enterprise Development LP
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
set -ex
echo "Running $1"
if [ "$1" = 'sls-init' ]; then
# This directory has to exist. Hopefully a persistent storage is mounted here.
if [ ! -d "/persistent_migrations" ]; then
echo "Missing directory /persistent_migrations"
exit 1
fi
# Make sure the migrations make their way to the persistent mounted storage.
cp /migrations/*.sql /persistent_migrations/
echo "Migrations copied to persistent location."
elif [ "$1" = 'sls-loader' ]; then
if [ "${USE_S3_DNS_HACK}" = 'true' ]; then
# Build up a list of all of the nameservers for k8s and the PIT/LiveCD nameservers.
# So if k8s DNS is not aware of rgw-vip, then we will fall back to the PIT/LiveCD nameserver
# which should be able to resolve the address.
echo "resolv.conf from NCN:"
echo "${PIT_NAMESERVER}"
# Get a list of all of the nameservers avaiable:
k8s_nameservers=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
pit_nameservers=$(echo "${PIT_NAMESERVER}" | grep nameserver | awk '{print $2}')
all_nameservers=$(printf "%s\n%s\n" "${k8s_nameservers}" "${pit_nameservers}" )
S3_HOSTNAME=$(basename ${S3_ENDPOINT})
S3_IP=""
if [ -z "${S3_DNS_LOOKUP_ATTEMPTS}" ]; then
S3_DNS_LOOKUP_ATTEMPTS=30
fi
# Query each nameserver until we can determine an IP address
for attempt in $(seq ${S3_DNS_LOOKUP_ATTEMPTS}); do
# Try each nameserver
echo "Lookup attempt $attempt of ${S3_DNS_LOOKUP_ATTEMPTS}"
for nameserver in $all_nameservers; do
echo "Using $nameserver to lookup $S3_HOSTNAME"
exit_code=0
S3_IP=$(dig +short "@$nameserver" "$S3_HOSTNAME") || exit_code=$?
if [ "$exit_code" -ne 0 ]; then
echo "Lookup had non-zero status code: $exit_code"
elif [ -n "$S3_IP" ]; then
echo "Lookup succeeded: $S3_IP"
break 2 # break out of both loops
fi
echo "Lookup failed"
done
echo "Sleeping 1 seconds before next lookup attempt"
sleep 1
done
if [ -z "$S3_IP" ]; then
echo "All lookup attempts failed, exiting"
exit 1
fi
# HACK: We are always assuming that we need to use HTTPS, and there is no port
# on the given S3_ENDPOINT value. If on vshasta, the DNS hack should be disabled
export S3_ENDPOINT="https://${S3_IP}"
echo "New S3_ENDPOINT: ${S3_ENDPOINT}"
fi
# If the loader is called then we have to do some prep work. First, pull the SLS file out of S3.
sls-s3-downloader
echo 'Configs downloaded from S3.'
# Now attempt to load the downlaoded sls_input_file.json into SLS.
sls-loader
echo "SLS has been loaded."
# Perform a migration of SLS
sls-migrator
echo "SLS has been migrated."
exit 0
fi
exec "$@"