forked from frandallfarmer/neohabitat
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun
executable file
·95 lines (83 loc) · 3.26 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
#!/bin/bash
# Starts a Neoclassical Habitat server and Habitat protocol bridge.
set -o 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=$(git rev-parse --show-toplevel)
VERSION=$(cat ${GIT_BASE_DIR}/target/classes/version.txt)
# Sets default config values if there are no environment-level overrides.
DEBUG_PORT="${NEOHABITAT_DEBUG_PORT-1985}"
MONGO_HOST="${NEOHABITAT_MONGO_HOST-127.0.0.1:27017}"
BRIDGE_HOST="${NEOHABITAT_BRIDGE_HOST-0.0.0.0}"
BRIDGE_PORT="${NEOHABITAT_BRIDGE_PORT-1337}"
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_PORT-0.0.0.0}"
DEBUGGER_PORT="${NEOHABITAT_DEBUGGER_PORT-1898}"
SHUTDOWN_PASSWORD="${NEOHABITAT_SHUTDOWN_PASSWORD-figleaf}"
SHOULD_BACKGROUND_BRIDGE="${NEOHABITAT_SHOULD_BACKGROUND_BRIDGE-true}"
SHOULD_ENABLE_DEBUGGER="${NEOHABITAT_SHOULD_ENABLE_DEBUGGER-false}"
SHOULD_RUN_BRIDGE="${NEOHABITAT_SHOULD_RUN_BRIDGE-true}"
SHOULD_RUN_NEOHABITAT="${NEOHABITAT_SHOULD_RUN_NEOHABITAT-true}"
SHOULD_UPDATE_SCHEMA="${NEOHABITAT_SHOULD_UPDATE_SCHEMA-true}"
PORT_RESV_TCP="${NEOHABITAT_PORT_RESV_TCP-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=()
if [ "${SHOULD_ENABLE_DEBUGGER}" == true ]; then
echo " - Enabling JMX debugging for Neohabitat..."
JVM_ARGS+=("-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=${DEBUGGER_PORT}")
fi
if [ "${SHOULD_UPDATE_SCHEMA}" == true ]; then
cd ${GIT_BASE_DIR}/${SCHEMA_DIR}
retry 60 "make clean"
cd ..
fi
# Starts the Habitat-to-Elko bridge process if requested.
if [ "${SHOULD_RUN_BRIDGE}" == true ]; then
if [ "${SHOULD_BACKGROUND_BRIDGE}" == true ]; then
supervisor -w bridge -- ${GIT_BASE_DIR}/bridge/Habitat2ElkoBridge.js -l "${BRIDGE_HOST}:${BRIDGE_PORT}" -m "${MONGO_HOST}/elko" -c "${DEFAULT_CONTEXT}" -t debug &
else
supervisor -w bridge -- ${GIT_BASE_DIR}/bridge/Habitat2ElkoBridge.js -l "${BRIDGE_HOST}:${BRIDGE_PORT}" -m "${MONGO_HOST}/elko" -c "${DEFAULT_CONTEXT}" -t debug
fi
fi
# Starts the Habitat Elko server if requested.
if [ "${SHOULD_RUN_NEOHABITAT}" == true ]; then
echo " - Running Neohabitat Elko server with args: ${BASE_ARGS[@]}"
java "${JVM_ARGS[@]}" -jar ${GIT_BASE_DIR}/target/neohabitat-${VERSION}.jar "${BASE_ARGS[@]}" "${@}"
fi