forked from stargate/stargate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
starctl
executable file
·165 lines (133 loc) · 4.33 KB
/
starctl
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
#!/bin/bash
set -e
if type -p java >/dev/null; then
_java=java
elif [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
_java="$JAVA_HOME/bin/java"
else
echo "\$JAVA_HOME not found"
exit 1
fi
if [[ "$_java" ]]; then
jvmver=$("$_java" -version 2>&1 | awk -F '"' '/version/ {print $2}')
JVM_VERSION=${jvmver%_*}
JVM_PATCH_VERSION=${jvmver#*_}
if [ "$JVM_VERSION" \< "1.8" ] ; then
echo "Stargate requires Java 8u40 or later."
exit 1
fi
if [ "$JVM_VERSION" \< "1.8" ] && [ "$JVM_PATCH_VERSION" -lt 40 ] ; then
echo "Stargate requires Java 8u40 or later."
exit 1
fi
fi
# If STARGATE_HOME wasn't specified in the environment, then search for one...
if [ "x$STARGATE_HOME" == "x" ]; then
STARGATE_HOME="`dirname "$0"`/stargate-lib"
if [[ ! -d $STARGATE_HOME ]]; then
echo "STARGATE_HOME not found"
exit 2
fi
else
if [[ ! -d $STARGATE_HOME ]]; then
echo "STARGATE_HOME: '$STARGATE_HOME' is not a directory"
exit 2
fi
fi
# Look for stargate-starter
STARGATE_STARTER=$(find "$STARGATE_HOME" -type f -iname "stargate-starter*.jar")
if [ ! -e $STARGATE_STARTER ]; then
echo "stargate-starter.jar missing in $STARGATE_HOME"
exit 3
fi
_ip_address() {
# scrape the first non-localhost IP address of the container
# in Swarm Mode, we often get two IPs -- the container IP, and the (shared) VIP, and the container IP should always be first
ip address | awk '
$1 == "inet" && $NF != "lo" {
gsub(/\/.+$/, "", $2)
print $2
exit
}
'
}
# Keep options in arrays for ease of quoting / cmd. line construction.
# Default to the env. variable. Use `eval` to reinterpret quotes embedded in the env. var. value.
eval declare -a JAVA_OPTS=("$JAVA_OPTS")
JAVA_OPTS+=(-Dstargate.libdir="$STARGATE_HOME")
JAVA_OPTS+=(-Djava.awt.headless=true)
declare -a STARGATE_ARGS=("$@")
# Use either command line args or environment variables, don't mix and match or
# else we could end up with unexpected config
if [[ ${#STARGATE_ARGS[@]} -eq 0 ]]; then
echo "Using environment for config"
if [[ ! -z "$CLUSTER_NAME" ]]; then
STARGATE_ARGS+=("--cluster-name" "$CLUSTER_NAME")
fi
if [[ ! -z "$CLUSTER_VERSION" ]]; then
STARGATE_ARGS+=("--cluster-version" "$CLUSTER_VERSION")
fi
if [[ ! -z "$SEED" ]]; then
STARGATE_ARGS+=("--cluster-seed" "$SEED")
fi
if [[ ! -z "$LISTEN" ]]; then
STARGATE_ARGS+=("--listen" "$LISTEN")
else
LISTEN="$(_ip_address)"
STARGATE_ARGS+=("--listen" "$LISTEN")
fi
if [[ ! -z "$SEED_PORT" ]]; then
STARGATE_ARGS+=("--seed-port" "$SEED_PORT")
fi
if [[ ! -z "$DATACENTER_NAME" ]]; then
STARGATE_ARGS+=("--dc" "$DATACENTER_NAME")
fi
if [[ ! -z "$RACK_NAME" ]]; then
STARGATE_ARGS+=("--rack" "$RACK_NAME")
fi
if [[ ! -z "$SIMPLE_SNITCH" ]]; then
STARGATE_ARGS+=("--simple-snitch")
fi
if [[ ! -z "$DSE" ]]; then
STARGATE_ARGS+=("--dse")
fi
if [[ ! -z "$CQL_PORT" ]]; then
STARGATE_ARGS+=("--cql-port" "$CQL_PORT")
fi
if [[ ! -z "$ENABLE_AUTH" ]]; then
STARGATE_ARGS+=("--enable-auth")
fi
if [[ ! -z "$USE_PROXY_PROTOCOL" ]]; then
STARGATE_ARGS+=("--use-proxy-protocol")
fi
if [[ ! -z "$PROXY_DNS_NAME" ]]; then
STARGATE_ARGS+=("--proxy-dns-name" "$PROXY_DNS_NAME")
fi
if [[ ! -z "$PROXY_PORT" ]]; then
STARGATE_ARGS+=("--proxy-port" "$PROXY_PORT")
fi
if [[ "$DEVELOPER_MODE" = true ]] || [[ "$DEVELOPER_MODE" = 1 ]]; then
STARGATE_ARGS+=("--developer-mode")
fi
if [[ ! -z "$EMULATE_DBAAS_DEFAULTS" ]]; then
STARGATE_ARGS+=("--emulate-dbaas-defaults")
fi
if [[ ! -z "$BIND_TO_LISTEN_ADDRESS" ]]; then
STARGATE_ARGS+=("--bind-to-listen-address")
fi
if [[ ! -z "$JMX_PORT" ]]; then
STARGATE_ARGS+=("--jmx-port" "$JMX_PORT")
fi
if [[ ! -z "$DISABLE_DYNAMIC_SNITCH" ]]; then
STARGATE_ARGS+=("--disable-dynamic-snitch")
fi
if [[ ! -z "$DISABLE_MBEAN_REGISTRATION" ]]; then
STARGATE_ARGS+=("--disable-mbean-registration")
fi
fi
declare -a CMD=(java -server)
CMD+=("${JAVA_OPTS[@]}")
CMD+=(-jar "$STARGATE_STARTER")
CMD+=("${STARGATE_ARGS[@]}")
echo "Running" "${CMD[@]}"
exec "${CMD[@]}"