forked from HDFGroup/hsds
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrunall.sh
More file actions
executable file
·199 lines (176 loc) · 6.19 KB
/
Copy pathrunall.sh
File metadata and controls
executable file
·199 lines (176 loc) · 6.19 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
config_value() {
# For given key return env variable, override.yml value, config.yml value in that order
# Not a proper yaml parser, but works for simple config we have
key=$1
yaml_key=`echo $key | awk '{ print tolower($0) }'`
# check for environment variable
rv="${!key}"
if [[ -z $rv ]] && [[ -f $OVERRIDE_FILE ]] ; then
# check override yaml
rv=`grep "^${yaml_key}" $OVERRIDE_FILE | awk '{ print $2 }'`
fi
if [[ -z $rv ]] ; then
# check config yaml
rv=`grep "^${yaml_key}" $CONFIG_FILE | awk '{ print $2 }'`
fi
if [ "$rv" = "null" ]; then
rv= # treat yml null as empty string
fi
if [[ ${PRINT_CONFIG} ]]; then
echo "${key}=${rv}"
fi
[[ -z $rv ]] && return 1 || return 0
}
# script to startup hsds service
if [[ $# -eq 1 ]] && ([[ $1 == "-h" ]] || [[ $1 == "--help" ]]); then
echo "Usage: runall.sh [--no-docker] [--stop] [--config] [count] "
exit 1
fi
if [[ $# -gt 0 ]] ; then
if [[ $1 == "--no-docker" ]] ; then
[[ -z $LOG_DIR ]] && echo "need to set LOG_DIR environment variable" && exit 1
export NO_DOCKER=1
if [[ $# -gt 1 ]] ; then
export CORES=$2
fi
elif [[ $1 == "--stop" ]]; then
echo "stopping"
elif [[ $1 == "--config" ]]; then
PRINT_CONFIG=1
else
export CORES=$1
fi
fi
if [[ ${CORES} ]] ; then
export DN_CORES=${CORES}
else
export DN_CORES=1
fi
if [[ -z $SN_CORES ]] ; then
# Use 1 SN_CORE unless there's an environment variable set
export SN_CORES=1
fi
CONFIG_FILE="admin/config/config.yml"
OVERRIDE_FILE="admin/config/override.yml"
# get config values
config_value "LOG_LEVEL" && export LOG_LEVEL=$rv
config_value "AWS_S3_GATEWAY" && export AWS_S3_GATEWAY=$rv
config_value "AWS_IAM_ROLE" && export AWS_IAM_ROLE=$rv
config_value "AWS_ACCESS_KEY_ID" && export AWS_ACCESS_KEY_ID=$rv
config_value "AWS_SECRET_ACCESS_KEY" && export AWS_SECRET_ACCESS_KEY=$rv
config_value "AWS_REGION" && export AWS_REGION=$rv
config_value "AZURE_CONNECTION_STRING" && export AZURE_CONNECTION_STRING=$rv
config_value "ROOT_DIR" && export ROOT_DIR=$rv
config_value "BUCKET_NAME" && export BUCKET_NAME=$rv
config_value "HSDS_ENDPOINT" && export HSDS_ENDPOINT=$rv
config_value "RESTART_POLICY" && export RESTART_POLICY=$rv
config_value "PUBLIC_DNS" && export PUBLIC_DNS=$rv
config_value "HEAD_PORT" && export HEAD_PORT=$rv
config_value "HEAD_RAM" && export HEAD_RAM=$rv
config_value "DN_PORT" && export DN_PORT=$rv
config_value "DN_RAM" && export DN_RAM=$rv
config_value "SN_PORT" && export SN_PORT=$rv
config_value "SN_RAM" && export SN_RAM=$rv
config_value "RANGEGET_PORT" && export RANGEGET_PORT=$rv
config_value "RANGEGET_RAM" && export RANGEGET_RAM=$rv
if [[ ${NO_DOCKER} ]]; then
# setup extra envs needed when not using docker
export TARGET_SN_COUNT=$SN_CORES
export TARGET_DN_COUNT=$DN_CORES
export HEAD_ENDPOINT=http://localhost:5100
export PYTHONUNBUFFERED="1"
[[ -z ${SN_PORT} ]] && export SN_PORT=80
[[ -z ${PASSWORD_FILE} ]] && export PASSWORD_FILE=${PWD}/admin/config/passwd.txt
[[ -z ${CONFIG_DIR} ]] && export CONFIG_DIR=${PWD}/admin/config/
# TBD - this script needs updating to run multiple SN, DN nodes
export SN_CORES=1
export DN_CORES=1
else
# check that docker-compose is available
docker-compose --version >/dev/null || exit 1
if [[ -z ${COMPOSE_PROJECT_NAME} ]]; then
export COMPOSE_PROJECT_NAME=hsds # use "hsds_" as prefix for container names
fi
fi
[[ -z ${BUCKET_NAME} ]] && echo "No default bucket set - did you mean to export BUCKET_NAME?"
[[ -z ${HSDS_ENDPOINT} ]] && echo "HSDS_ENDPOINT is not set" && exit 1
if [[ ${AWS_S3_GATEWAY} ]]; then
COMPOSE_FILE="admin/docker/docker-compose.aws.yml"
echo "AWS_S3_GATEWAY set, using ${COMPOSE_FILE}"
elif [[ ${AZURE_CONNECTION_STRING} ]]; then
COMPOSE_FILE="admin/docker/docker-compose.azure.yml"
echo "AZURE_CONNECTION_STRING set, using ${COMPOSE_FILE}"
else
COMPOSE_FILE="admin/docker/docker-compose.posix.yml"
echo "no AWS or AZURE env set, using ${COMPOSE_FILE}"
if [[ -z ${ROOT_DIR} ]]; then
export ROOT_DIR=$PWD/data
echo "no ROOT_DIR env set, using $ROOT_DIR directory for storage"
fi
if [[ ! -d ${ROOT_DIR} ]]; then
echo "creating directory ${ROOT_DIR}"
mkdir ${ROOT_DIR}
fi
if [[ ! -d ${ROOT_DIR}/${BUCKET_NAME} ]]; then
echo "creating directory ${ROOT_DIR}/${BUCKET_NAME}"
mkdir ${ROOT_DIR}/${BUCKET_NAME}
fi
fi
if [[ -z ${PUBLIC_DNS} ]] ; then
if [[ ${HSDS_ENDPOINT} == "https://"* ]] ; then
export PUBLIC_DNS=${HSDS_ENDPOINT:8}
elif [[ ${HSDS_ENDPOINT} == "http://"* ]] ; then
export PUBLIC_DNS=${HSDS_ENDPOINT:7}
else
echo "Invalid HSDS_ENDPOINT: ${HSDS_ENDPOINT}" && exit 1
fi
fi
if [[ -z $AWS_IAM_ROLE ]] && [[ $AWS_S3_GATEWAY ]]; then
# if not using s3 or S3 without EC2 IAM roles, need to define AWS access keys
[[ -z ${AWS_ACCESS_KEY_ID} ]] && echo "Need to set AWS_ACCESS_KEY_ID or AWS_IAM_ROLE" && exit 1
[[ -z ${AWS_SECRET_ACCESS_KEY} ]] && echo "Need to set AWS_SECRET_ACCESS_KEY" && exit 1
fi
if [[ ${PRINT_CONFIG} ]]; then
echo "use $0 without --config option to actually start/stop service"
exit 0
fi
if [[ $NO_DOCKER ]] ; then
echo "no docker startup"
echo "starting head node"
hsds-headnode >${LOG_DIR}/head.log 2>&1 &
sleep 1
echo "starting service node"
hsds-servicenode >${LOG_DIR}/sn.log 2>&1 &
sleep 1
echo "starting data node"
hsds-datanode >${LOG_DIR}/dn.log 2>&1 &
else
if [[ $# -eq 1 ]] && [[ $1 == "--stop" ]]; then
# use the compose file to shutdown the sevice
echo "Running docker-compose -f ${COMPOSE_FILE} down"
docker-compose -f ${COMPOSE_FILE} down
exit 0 # can quit now
else
echo "Running docker-compose -f ${COMPOSE_FILE} up"
docker-compose -f ${COMPOSE_FILE} up -d --scale sn=${SN_CORES} --scale dn=${DN_CORES}
fi
fi
# wait for the server to be ready
for i in {1..120}
do
STATUS_CODE=`curl -s -o /dev/null -w "%{http_code}" http://localhost:${SN_PORT}/about`
if [[ $STATUS_CODE == "200" ]]; then
echo "service ready!"
break
else
echo "${i}: waiting for server startup (status: ${STATUS_CODE}) "
sleep 1
fi
done
if [[ $STATUS_CODE != "200" ]]; then
echo "service failed to start"
echo "SN_1 logs:"
docker logs --tail 100 hsds_sn_1
exit 1
fi