forked from hazelcast/hazelcast-commandline-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.sh
executable file
·192 lines (169 loc) · 5.36 KB
/
rc.sh
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
#!/bin/bash
#
# Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Starts Hazelcast Remote Controller
#
# Usage:
# Start with default Hazelcast version : ./rc.sh start
# Start with given Hazelcast version : HZ_VERSION=4.3 ./rc.sh start
# Stop : ./rc.sh stop
# Exit immediately on error.
set -e
# Treat unset variables an parameters as an error.
set -u
# Disable printing trace.
set +x
log_info () {
local msg=$1
local ts
ts=$(date "$TIMESTAMP_FMT")
echo "$ts INFO : $msg"
}
log_fatal () {
local msg=$1
local ts
ts=$(date "$TIMESTAMP_FMT")
echo "$ts FATAL: $msg"
exit 1
}
download () {
local repo=$1
local jar_path=$2
local artifact=$3
# Set this to anything in the caller to ignore the download error
local ignore_err=${4:-}
local err
local output
if [ -f "$jar_path" ]; then
log_info "$jar_path already exists, skipping download."
else
log_info "Downloading: $jar_path ($artifact) from: $repo"
set +e
output=$(mvn -q org.apache.maven.plugins:maven-dependency-plugin:2.10:get -DremoteRepositories=$repo -Dartifact=$artifact -Dtransitive=false -Ddest="$jar_path" 2>&1)
err=$?
set -e
if [ $err -ne 0 ]; then
if [ "x$ignore_err" == "x" ]; then
log_fatal "Failed downloading $jar_path ($artifact) from: $repo\nOutput:\n$output"
else
log_info "Ignoring the download error for $jar_path ($artifact) from: $repo"
fi
fi
fi
}
downloadRC () {
local jar_path="hazelcast-remote-controller-${HAZELCAST_RC_VERSION}.jar"
local artifact="com.hazelcast:hazelcast-remote-controller:${HAZELCAST_RC_VERSION}"
download "$SNAPSHOT_REPO" "$jar_path" "$artifact"
classpath="$classpath:$jar_path"
}
downloadTests () {
local jar_path="hazelcast-${HAZELCAST_TEST_VERSION}-tests.jar"
local artifact="com.hazelcast:hazelcast:${HAZELCAST_TEST_VERSION}:jar:tests"
download "$SNAPSHOT_REPO" "$jar_path" "$artifact"
classpath="$classpath:$jar_path"
}
downloadHazelcast () {
local jar_path="hazelcast-${HZ_VERSION}.jar"
local artifact="com.hazelcast:hazelcast:${HZ_VERSION}"
download "${repo}" "$jar_path" "$artifact"
classpath="$classpath:$jar_path"
}
downloadSQL () {
local jar_path="hazelcast-sql-${HZ_VERSION}.jar"
local artifact="com.hazelcast:hazelcast-sql:${HZ_VERSION}"
download "${repo}" "$jar_path" "$artifact" ignore
classpath="$classpath:$jar_path"
}
downloadHazelcastEnterprise () {
local jar_path="hazelcast-enterprise-${HAZELCAST_ENTERPRISE_VERSION}.jar"
local artifact="com.hazelcast:hazelcast-enterprise:${HAZELCAST_ENTERPRISE_VERSION}"
download "${enterprise_repo}" "$jar_path" "$artifact"
classpath="$classpath:$jar_path"
}
downloadTestsEnterprise () {
local jar_path="hazelcast-enterprise-${HAZELCAST_ENTERPRISE_VERSION}-tests.jar"
local artifact="com.hazelcast:hazelcast-enterprise:${HAZELCAST_ENTERPRISE_VERSION}:jar:tests"
download "${enterprise_repo}" "$jar_path" "$artifact"
classpath="$classpath:$jar_path"
}
startRC () {
if [ -f "$PID_FILE" ]; then
log_fatal "PID file $PID_FILE exists. Is there an another instance of Hazelcast Remote Controller running?"
fi
if [[ "${HZ_VERSION}" == *-SNAPSHOT ]]
then
repo=${SNAPSHOT_REPO}
enterprise_repo=${ENTERPRISE_SNAPSHOT_REPO}
else
repo=${RELEASE_REPO}
enterprise_repo=${ENTERPRISE_RELEASE_REPO}
fi
classpath=""
java_opts="-Dhazelcast.phone.home.enabled=false com.hazelcast.remotecontroller.Main --use-simple-server"
# Download Remote Controller
downloadRC
# Download Hazelcast Community jars
downloadTests
downloadHazelcast
# Download the SQL jar
downloadSQL
if [ "x${HAZELCAST_ENTERPRISE_KEY:-}" != "x" ]; then
# Download Hazelcast Enterprise jars
downloadHazelcastEnterprise
downloadTestsEnterprise
java_opts="-Dhazelcast.enterprise.license.key=${HAZELCAST_ENTERPRISE_KEY} $java_opts"
fi
java_opts="-cp ${classpath} $java_opts"
log_info "Starting Remote Controller in the background..."
log_info "Run '$0 stop' to stop the controller."
java $java_opts &
pid=$!
echo "$pid" > "$PID_FILE"
}
stopRC () {
if [ -f "$PID_FILE" ]; then
pid=$(cat "$PID_FILE")
log_info "Stopping $pid ..."
kill -9 $pid
rm "$PID_FILE"
fi
}
help () {
echo "Usage: ./rc.sh [start|stop]"
exit 1
}
TIMESTAMP_FMT="+%Y-%m-%d %H:%M:%S"
PID_FILE="test.pid"
HZ_VERSION="${HZ_VERSION:-5.3.1}"
HAZELCAST_TEST_VERSION=${HZ_VERSION}
HAZELCAST_ENTERPRISE_VERSION=${HZ_VERSION}
HAZELCAST_RC_VERSION="0.8-SNAPSHOT"
SNAPSHOT_REPO="https://oss.sonatype.org/content/repositories/snapshots"
RELEASE_REPO="http://repo1.maven.apache.org/maven2"
ENTERPRISE_RELEASE_REPO="https://repository.hazelcast.com/release/"
ENTERPRISE_SNAPSHOT_REPO="https://repository.hazelcast.com/snapshot/"
case "${1:-}" in
start)
startRC
;;
stop)
stopRC
;;
*)
help
;;
esac