-
Notifications
You must be signed in to change notification settings - Fork 42
/
run
executable file
·150 lines (132 loc) · 4.46 KB
/
run
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
#!/bin/bash
# Starts a Neoclassical Habitat server and Habitat protocol bridge.
set -exo pipefail
trap 'kill %1; kill %2' SIGINT
function retry() {
local n=0
local try=$1
local cmd="${@: 2}"
[[ $# -le 1 ]] && {
echo "Usage $0 <retry_number> <command>";
}
until [[ $n -ge $try ]]
do
$cmd && break || {
echo "Command Fail.."
((n++))
echo "retry $n ::"
sleep 1;
}
done
}
GIT_BASE_DIR="/neohabitat"
VERSION="0.1.0-SNAPSHOT"
# Sets default config values if there are no environment-level overrides.
DEBUG_PORT="${NEOHABITAT_DEBUG_PORT:=1985}"
MONGO_HOST="${NEOHABITAT_MONGO_HOST:=neohabitatmongo:27017}"
BRIDGE_HOST="${NEOHABITAT_BRIDGE_HOST:=0.0.0.0}"
BRIDGE_PORT="${NEOHABITAT_BRIDGE_PORT:=1337}"
BRIDGE_ELKO_HOST="${NEOHABITAT_BRIDGE_ELKO_HOST:=neohabitat:9000}"
DEFAULT_CONTEXT="${NEOHABITAT_DEFAULT_CONTEXT:=context-Downtown_5f}"
SCHEMA_DIR="${NEOHABITAT_SCHEMA_DIR:=db}"
SERVER_HOST="${NEOHABITAT_SERVER_HOST:=0.0.0.0}"
SERVER_NAME="${NEOHABITAT_SERVER_NAME:=neohabitat}"
SERVER_BIND="${NEOHABITAT_SERVER_HOST:=0.0.0.0}"
DEBUGGER_PORT="${NEOHABITAT_DEBUGGER_PORT:=5005}"
SHUTDOWN_PASSWORD="${NEOHABITAT_SHUTDOWN_PASSWORD:=figleaf}"
SHOULD_BACKGROUND_BRIDGE="${NEOHABITAT_SHOULD_BACKGROUND_BRIDGE:=true}"
SHOULD_ENABLE_DEBUGGER="${NEOHABITAT_SHOULD_ENABLE_DEBUGGER:=false}"
SHOULD_ENABLE_CRON="${NEOHABITAT_SHOULD_ENABLE_CRON:=true}"
SHOULD_RUN_BRIDGE="${NEOHABITAT_SHOULD_RUN_BRIDGE:=true}"
SHOULD_RUN_NEOHABITAT="${NEOHABITAT_SHOULD_RUN_NEOHABITAT:=true}"
SHOULD_RUN_PUSHSERVER="${NEOHABITAT_SHOULD_RUN_PUSHSERVER:=true}"
SHOULD_UPDATE_SCHEMA="${NEOHABITAT_SHOULD_UPDATE_SCHEMA:=false}"
PORT_RESV_TCP="${NEOHABITAT_PORT_RESV_TCP:=9000}"
#HABIPROXY_ELKO_HOST="${NEOHABITAT_HABIPROXY_ELKO_HOST:=neohabitat}"
#HABIPROXY_ELKO_PORT="${NEOHABITAT_HABIPROXY_ELKO_PORT:=9000}"
BASE_ARGS=(
org.elkoserver.server.context.ContextServerBoot
trace_cont=DEBUG
trace_comm=EVENT
# Forcibly logs to stdout to comply with 12 Factor App guidelines.
tracelog_dir=/plz/log/to/stdout
tracelog_tag=context
conf.listen.host="${SERVER_HOST}:${PORT_RESV_TCP}"
conf.listen.bind="${SERVER_BIND}:${PORT_RESV_TCP}"
conf.listen.protocol=tcp
conf.comm.jsonstrictness=true
conf.context.entrytimeout=999999
conf.context.odb=mongo
conf.context.odb.mongo.hostport="${MONGO_HOST}"
conf.context.objstore=org.elkoserver.objdb.store.mongostore.MongoObjectStore
conf.context.name="${SERVER_NAME}"
conf.context.shutdownpassword="${SHUTDOWN_PASSWORD}"
conf.msgdiagnostics=true
)
JVM_ARGS=(
-DDEBUG.MONGO=true
-DDB.TRACE=true
)
function start_bridge() {
cd ${GIT_BASE_DIR}/bridge && npm run supervisor-bridge-docker -- \
-l ${BRIDGE_HOST}:${BRIDGE_PORT} \
-e ${BRIDGE_ELKO_HOST} \
-m ${MONGO_HOST}/elko \
-c ${DEFAULT_CONTEXT} \
-t debug 2>&1 | tee bridge.log
}
function start_pushserver() {
if [[ "${NODE_ENV}" == "production" ]]; then
(cd "${GIT_BASE_DIR}/pushserver" && npm run start 2>&1 | tee ../pushserver.log)
else
(cd "${GIT_BASE_DIR}/pushserver" && npm run debug 2>&1 | tee ../pushserver.log)
fi
}
function start_elko_server() {
mvn package
java "${JVM_ARGS[@]}" \
-jar ${GIT_BASE_DIR}/target/neohabitat-${VERSION}.jar \
"${BASE_ARGS[@]}" \
"${@}" 2>&1 | tee elko_server.log
}
if [ "${SHOULD_ENABLE_CRON}" == true ]; then
echo " - Starting cron daemon..."
crond -i
else
echo "${SHOULD_ENABLE_CRON}"
echo " - Skipping cron.."
fi
if [ "${SHOULD_ENABLE_DEBUGGER}" == true ]; then
echo " - Enabling JMX debugging for Neohabitat..."
JVM_ARGS+=(
"-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"
)
fi
#Build/Rebuild the database if EITHER environment forces it OR the db doesn't exist yet.
cd "${GIT_BASE_DIR}/${SCHEMA_DIR}"
if [ "${SHOULD_UPDATE_SCHEMA}" == true ]; then
retry 60 "make fast"
else
npm run dbUtils -- "${NEOHABITAT_MONGO_HOST}" testElko || {
echo " - No 'elko' database found, so applying all Neohabitat schema..."
retry 60 "make fast"
}
fi
cd "${GIT_BASE_DIR}"
# Starts the Habitat-to-Elko bridge process if requested.
if [ "${SHOULD_RUN_BRIDGE}" == true ]; then
if [ "${SHOULD_BACKGROUND_BRIDGE}" == true ]; then
start_bridge &
else
start_bridge
fi
fi
# Starts the Exhibit's HTML push server if requested.
if [ "${SHOULD_RUN_PUSHSERVER}" == true ]; then
start_pushserver &
fi
# Starts the Habitat Elko server if requested.
if [ "${SHOULD_RUN_NEOHABITAT}" == true ]; then
echo " - Running Neohabitat Elko server with args: ${BASE_ARGS[@]}"
start_elko_server
fi