-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartup.sh
More file actions
executable file
·184 lines (145 loc) · 7.65 KB
/
startup.sh
File metadata and controls
executable file
·184 lines (145 loc) · 7.65 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
#!/bin/bash
set -e
IFC=$(ifconfig | grep '^[a-z0-9]' | awk '{print $1}' | grep -e ns -e eth0)
IP_ADDRESS=$(ifconfig $IFC | grep 'inet addr' | awk -F : {'print $2'} | awk {'print $1'})
echo "This node has an IP of " $IP_ADDRESS
env
if [ -z "$DATABASE_HOST" ]; then
echo "Please start this container with a Postgres database using '-e DATABASE_HOST=192.168.27.xxx'"
exit 1
fi
if [ -z "$DATABASE_NAME" ]; then
DATABASE_NAME=ibm_ucdp
fi
if [ -z "$DATABASE_PORT" ]; then
DATABASE_PORT=5432
fi
if [ -z "$DOCKER_HOST" ]; then
DOCKER_HOST=localhost
fi
if [ -z "$DOCKER_PORT" ]; then
DOCKER_HOST=2375
fi
# Escape characters which might confuse the regex in sed below
DATABASE_CONNECTION_URL=`echo "jdbc\:postgresql\://${DATABASE_HOST}\:${DATABASE_PORT}/${DATABASE_NAME}" | sed -e 's/[]\/$*.^|[]/\\\\&/g'`
sed -i "s/\(hibernate\.connection\.url=\).*\$/\1${DATABASE_CONNECTION_URL}/" /opt/ibm-ucd-patterns/conf/server/server.properties
if [ -n $DATABASE_USER ]; then
sed -i "s/\(hibernate\.connection\.username=\).*\$/\1${DATABASE_USER}/" /opt/ibm-ucd-patterns/conf/server/server.properties
fi
if [ -n $DATABASE_PASS ]; then
sed -i "s/\(hibernate\.connection\.password=\).*\$/\1${DATABASE_PASS}/" /opt/ibm-ucd-patterns/conf/server/server.properties
fi
sed -i "s/\(install\.server\.web\.host=\).*\$/\1${WEB_SERVER_HOSTNAME}/" /opt/ibm-ucd-patterns/conf/server/server.properties
PUBLIC_URL=`echo "http\://${WEB_SERVER_HOSTNAME}\:9080/landscaper" | sed -e 's/[]\/$*.^|[]/\\\\&/g'`
sed -i "s/\(public\.url=\).*\$/\1${PUBLIC_URL}/" /opt/ibm-ucd-patterns/conf/server/server.properties
# Gitblit url
GITBLIT_URL=`echo "http\://${WEB_SERVER_HOSTNAME}\:9080/gitblit" | sed -e 's/[]\/$*.^|[]/\\\\&/g'`
sed -i "s/\(com\.ibm\.landscaper\.gitblit\.url=\).*\$/\1${GITBLIT_URL}/" /opt/ibm-ucd-patterns/conf/server/server.properties
# Using insecure connection for now for filesystem
VERSIONED_FILESYSTEM_API_URL=`echo "http\://${WEB_SERVER_HOSTNAME}\:9080/landscaper" | sed -e 's/[]\/$*.^|[]/\\\\&/g'`
sed -i "s/\(versioned-filesystem-client\.ribbon\.listOfServers=\).*\$/\1${VERSIONED_FILESYSTEM_API_URL}/" /opt/ibm-ucd-patterns/conf/server/versioned-filesystem-client.properties
sed -i "s/WEB_SERVER_HOSTNAME/${WEB_SERVER_HOSTNAME}/" /opt/ibm-ucd-patterns/conf/server/engine-services-client.properties
sed -i "s/WEB_SERVER_HOSTNAME/${WEB_SERVER_HOSTNAME}/" /opt/ibm-ucd-patterns/conf/server/server.properties
if [ -n "$DOCKER_HOST" ]; then
if [ -z "$DOCKER_PORT" ]; then
DOCKER_PORT=2376
fi
sed -i "s/DOCKER_REMOTE_URL/${DOCKER_HOST}\:${DOCKER_PORT}/" /opt/ibm-ucd-patterns/conf/server/docker-api-client.properties
if [ -z "$DOCKER_PROTO" ]; then
DOCKER_PROTO="https"
fi
echo "com.ibm.patterns.docker.remote.url=${DOCKER_PROTO}\://${DOCKER_HOST}\:${DOCKER_PORT}" >> /opt/ibm-ucd-patterns/conf/server/config.properties
else
# Delete value
echo "TIP: You can associate this container with a Docker Remote API endpoint to enable Heat-based multiple-node docker designs in the editor."
echo "TIP: To enable the integration add -e DOCKER_HOST={docker host} [-e DOCKER_PORT={2376 by default}] [-e DOCKER_PROTO={https by default}]"
sed -i "s/DOCKER_REMOTE_URL//" /opt/ibm-ucd-patterns/conf/server/docker-api-client.properties
fi
if [ -n "$ENGINE_HOST" ]; then
echo "$ENGINE_HOST $ENGINE_HOST" >> /etc/hosts
# linked to an engine, configure appropriately
sed -i "s/ENGINE_ENV_PUBLIC_HOSTNAME/${ENGINE_HOST}/" /root/seed.sql
sed -i "s/ENGINE_PORT_8004_TCP_PORT/${ENGINE_8004_PORT}/" /root/seed.sql
sed -i "s/ENGINE_PORT_5000_TCP_PORT/${ENGINE_5000_PORT}/" /root/seed.sql
sed -i "s|KEYSTONE_URL|${KEYSTONE_URL}|g" /root/seed.sql
DATABASE_SEED_DATA_DIR="/opt/ibm-ucd-patterns/opt/tomcat/webapps/landscaper/WEB-INF/database/translations"
DATABASE_LOCALE="en_us"
DATABASE_SEED_DATA_FILE="${DATABASE_SEED_DATA_DIR}/${DATABASE_LOCALE}/ur-seed-data.sql"
echo "INFO: Defaulting to US English Locale (en_us). If this is the wrong locale,
some information may not be pre-populated in your designer."
if [ -f "$DATABASE_SEED_DATA_FILE" ]; then
echo "Updating default seed data with linked container information for the ENGINE."
cat /root/seed.sql >> $DATABASE_SEED_DATA_FILE
echo "UPDATED FILE within container: " $DATABASE_SEED_DATA_FILE
else
echo "ERROR: The default seed data file was not found within the container:"
echo ""
echo "MISSING FILE within container: $DATABASE_SEED_DATA_FILE"
echo "Configure the default engine using the following command:
psql -u $DATABASE_USER -p$DATABASE_PASS \
-D$DATABASE_NAME -h $ENGINE_ENV_PUBLIC_HOSTNAME\
-P $DATABASE_PORT -f seed.sql"
echo "Use the following seed.sql:"
cat /root/seed.sql
fi
else
echo "WARN: Either no engine was linked, or the engine did not specify an alias for its PUBLIC_HOSTNAME."
echo "TIP: When you launch the engine container, use '-e PUBLIC_HOSTNAME={host alias}' "
echo " where the host alias may be 'boot2docker' or a user defined host alias defined in your /etc/hosts."
fi
if [ -n "$DEPLOY_SERVER_HOST" ]; then
DEPLOY_SERVER_URL="${DEPLOY_SERVER_PROTO}://${DEPLOY_SERVER_HOST}:${DEPLOY_SERVER_PORT}"
echo "Registering Blueprint Designer with UrbanCode Deploy server ${DEPLOY_SERVER_URL}"
if [ -z "$DEPLOY_SERVER_AUTH_TOKEN" ]; then
# UCD Server takes a few seconds to startup. If we call this function too early it will fail
# loop until it succeeds or fail after # of attempts
attempt=1
until [ -n "$DEPLOY_SERVER_AUTH_TOKEN" ]; do
attempt=$(($attempt + 1))
sleep 10
echo "requesting auth token for BlueprintDesigner on UCD ${DEPLOY_SERVER_URL}..."
cat << EOF > authtoken
{
"userId":"20000000000000000000000001000000",
"expDate":"2017-10-12T04:00:00.000Z",
"expTime":"1970-01-01T08:15:00.000Z",
"description":"",
"host":"",
"expiration":1507792500000
}
EOF
DEPLOY_SERVER_AUTH_TOKEN=$(curl -k -u admin:admin \
-X PUT \
-d @authtoken \
"${DEPLOY_SERVER_URL}/security/authtoken" | python -c \
"import json; import sys;
data=json.load(sys.stdin);
print data['token']")
if [ "$attempt" -gt "60" ]; then
echo "Failed to request auth token on UCD server ${DEPLOY_SERVER_URL}. Unable to automatically integrate blueprintdesiger with UCD server."
exit 1
fi
done
fi
echo "Registering UrbanCode Deploy server: "
echo "DEPLOY_SERVER_URL=${DEPLOY_SERVER_URL}"
echo "DEPLOY_SERVER_AUTH_TOKEN=${DEPLOY_SERVER_AUTH_TOKEN}"
sed -i "s|DEPLOY_SERVER_URL|${DEPLOY_SERVER_URL}|g" /opt/ibm-ucd-patterns/conf/server/config.properties
sed -i "s|DEPLOY_SERVER_AUTH_TOKEN|${DEPLOY_SERVER_AUTH_TOKEN}|g" /opt/ibm-ucd-patterns/conf/server/config.properties
else
echo "TIP: Pass ENV variables at startup via -e DEPLOY_SERVER_HOST=192.168.27.100 [DEPLOY_SERVER_PORT|DEPLOY_SERVER_PROTO] to automatically register it with this patterns container."
fi
if [ -n "$LOG_CONFIG" ]; then
CONFIG_DIR=/opt/ibm-ucd-patterns/conf/server
for log in `ls $CONFIG_DIR/*.properties`; do
echo "************************************************************************"
echo "BEGIN CONFIG FILE: $log"
echo "************************************************************************"
cat "$log"
echo "" # Ensure that a line break occurs before the suffix text
echo "************************************************************************"
echo "END CONFIG FILE: $log"
echo "************************************************************************"
done
fi
/usr/local/bin/wait-for-it.sh --host=$DATABASE_HOST --port=$DATABASE_PORT --timeout=60 -- /usr/local/bin/wait-for-it.sh --host=$ENGINE_HOST --port=$ENGINE_8004_PORT --timeout=60 -- /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf