-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
neo4j.m4
executable file
·323 lines (272 loc) · 8.62 KB
/
neo4j.m4
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#!/usr/bin/env bash
# Copyright (c) 2002-2018 "Neo Technology,"
# Network Engine for Objects in Lund AB [http://neotechnology.com]
#
# This file is part of Neo4j.
#
# Neo4j is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Callers may provide the following environment variables to customize this script:
# * JAVA_HOME
# * JAVA_CMD
# * NEO4J_HOME
# * NEO4J_CONF
# * NEO4J_START_WAIT
include(src/main/distribution/shell-scripts/bin/neo4j-shared.m4)
setup_arbiter_options() {
is_arbiter() {
compgen -G "${NEO4J_LIB}/neo4j-server-enterprise-*.jar" >/dev/null && \
[[ "$(echo "${dbms_mode:-}" | tr [:lower:] [:upper:])" == "ARBITER" ]]
}
if is_arbiter; then
SHUTDOWN_TIMEOUT=20
MIN_ALLOWED_OPEN_FILES=1
MAIN_CLASS="org.neo4j.server.enterprise.ArbiterEntryPoint"
print_start_message() {
echo "Started in ARBITER mode."
echo "This instance is now joining the cluster."
}
else
SHUTDOWN_TIMEOUT="${NEO4J_SHUTDOWN_TIMEOUT:-120}"
MIN_ALLOWED_OPEN_FILES=40000
MAIN_CLASS="#{neo4j.mainClass}"
print_start_message() {
# Global default
NEO4J_DEFAULT_ADDRESS="${dbms_connectors_default_listen_address:-localhost}"
if [[ "${dbms_connector_http_enabled:-true}" == "false" ]]; then
# Only HTTPS connector enabled
# First read deprecated 'address' setting
NEO4J_SERVER_ADDRESS="${dbms_connector_https_address:-:7473}"
# Overridden by newer 'listen_address' if specified
NEO4J_SERVER_ADDRESS="${dbms_connector_https_listen_address:-${NEO4J_SERVER_ADDRESS}}"
# If it's only a port we need to add the address (it starts with a colon in that case)
case ${NEO4J_SERVER_ADDRESS} in
:*)
NEO4J_SERVER_ADDRESS="${NEO4J_DEFAULT_ADDRESS}${NEO4J_SERVER_ADDRESS}";;
esac
# Add protocol
NEO4J_SERVER_ADDRESS="https://${NEO4J_SERVER_ADDRESS}"
else
# HTTP connector enabled - same as https but different settings
NEO4J_SERVER_ADDRESS="${dbms_connector_http_address:-:7474}"
NEO4J_SERVER_ADDRESS="${dbms_connector_http_listen_address:-${NEO4J_SERVER_ADDRESS}}"
case ${NEO4J_SERVER_ADDRESS} in
:*)
NEO4J_SERVER_ADDRESS="${NEO4J_DEFAULT_ADDRESS}${NEO4J_SERVER_ADDRESS}";;
esac
NEO4J_SERVER_ADDRESS="http://${NEO4J_SERVER_ADDRESS}"
fi
echo "Started neo4j (pid ${NEO4J_PID}). It is available at ${NEO4J_SERVER_ADDRESS}/"
if [[ "$(echo "${dbms_mode:-}" | tr [:lower:] [:upper:])" == "HA" ]]; then
echo "This HA instance will be operational once it has joined the cluster."
else
echo "There may be a short delay until the server is ready."
fi
}
fi
}
check_status() {
if [ -e "${NEO4J_PIDFILE}" ] ; then
NEO4J_PID=$(cat "${NEO4J_PIDFILE}")
kill -0 "${NEO4J_PID}" 2>/dev/null || unset NEO4J_PID
fi
}
check_limits() {
detect_os
if [ "${DIST_OS}" != "macosx" ] ; then
ALLOWED_OPEN_FILES="$(ulimit -n)"
if [ "${ALLOWED_OPEN_FILES}" -lt "${MIN_ALLOWED_OPEN_FILES}" ]; then
echo "WARNING: Max ${ALLOWED_OPEN_FILES} open files allowed, minimum of ${MIN_ALLOWED_OPEN_FILES} recommended. See the Neo4j manual."
fi
fi
}
setup_java_opts() {
JAVA_OPTS=("-server")
if [[ -n "${dbms_memory_heap_initial_size:-}" ]]; then
local mem="${dbms_memory_heap_initial_size}"
if ! [[ ${mem} =~ .*[gGmMkK] ]]; then
mem="${mem}m"
cat >&2 <<EOF
WARNING: dbms.memory.heap.initial_size will require a unit suffix in a
future version of Neo4j. Please add a unit suffix to your
configuration. Example:
dbms.memory.heap.initial_size=512m
^
EOF
fi
JAVA_MEMORY_OPTS+=("-Xms${mem}")
fi
if [[ -n "${dbms_memory_heap_max_size:-}" ]]; then
local mem="${dbms_memory_heap_max_size}"
if ! [[ ${mem} =~ .*[gGmMkK] ]]; then
mem="${mem}m"
cat >&2 <<EOF
WARNING: dbms.memory.heap.max_size will require a unit suffix in a
future version of Neo4j. Please add a unit suffix to your
configuration. Example:
dbms.memory.heap.max_size=512m
^
EOF
fi
JAVA_MEMORY_OPTS+=("-Xmx${mem}")
fi
[[ -n "${JAVA_MEMORY_OPTS:-}" ]] && JAVA_OPTS+=("${JAVA_MEMORY_OPTS[@]}")
if [[ "${dbms_logs_gc_enabled:-}" = "true" ]]; then
JAVA_OPTS+=("-Xloggc:${NEO4J_LOGS}/gc.log" \
"-XX:+UseGCLogFileRotation" \
"-XX:NumberOfGCLogFiles=${dbms_logs_gc_rotation_keep_number:-5}" \
"-XX:GCLogFileSize=${dbms_logs_gc_rotation_size:-20m}")
if [[ -n "${dbms_logs_gc_options:-}" ]]; then
JAVA_OPTS+=(${dbms_logs_gc_options}) # unquoted to split on spaces
else
JAVA_OPTS+=("-XX:+PrintGCDetails" "-XX:+PrintGCDateStamps" "-XX:+PrintGCApplicationStoppedTime" \
"-XX:+PrintPromotionFailure" "-XX:+PrintTenuringDistribution")
fi
fi
if [[ -n "${dbms_jvm_additional:-}" ]]; then
JAVA_OPTS+=(${dbms_jvm_additional}) # unquoted to split on spaces
fi
}
assemble_command_line() {
retval=("${JAVA_CMD}" "-cp" "${CLASSPATH}" "${JAVA_OPTS[@]}" "-Dfile.encoding=UTF-8" "${MAIN_CLASS}" \
"--home-dir=${NEO4J_HOME}" "--config-dir=${NEO4J_CONF}")
}
do_console() {
check_status
if [[ "${NEO4J_PID:-}" ]] ; then
echo "Neo4j is already running (pid ${NEO4J_PID})."
exit 1
fi
echo "Starting Neo4j."
check_limits
build_classpath
assemble_command_line
command_line=("${retval[@]}")
exec "${command_line[@]}"
}
do_start() {
check_status
if [[ "${NEO4J_PID:-}" ]] ; then
echo "Neo4j is already running (pid ${NEO4J_PID})."
exit 0
fi
echo "Starting Neo4j."
check_limits
build_classpath
assemble_command_line
command_line=("${retval[@]}")
nohup "${command_line[@]}" >>"${CONSOLE_LOG}" 2>&1 &
echo "$!" >"${NEO4J_PIDFILE}"
: "${NEO4J_START_WAIT:=5}"
end="$((SECONDS+NEO4J_START_WAIT))"
while true; do
check_status
if [[ "${NEO4J_PID:-}" ]]; then
break
fi
if [[ "${SECONDS}" -ge "${end}" ]]; then
echo "Unable to start. See ${CONSOLE_LOG} for details."
rm "${NEO4J_PIDFILE}"
return 1
fi
sleep 1
done
print_start_message
echo "See ${CONSOLE_LOG} for current status."
}
do_stop() {
check_status
if [[ ! "${NEO4J_PID:-}" ]] ; then
echo "Neo4j not running"
[ -e "${NEO4J_PIDFILE}" ] && rm "${NEO4J_PIDFILE}"
return 0
else
echo -n "Stopping Neo4j."
end="$((SECONDS+SHUTDOWN_TIMEOUT))"
while true; do
check_status
if [[ ! "${NEO4J_PID:-}" ]]; then
echo " stopped"
[ -e "${NEO4J_PIDFILE}" ] && rm "${NEO4J_PIDFILE}"
return 0
fi
kill "${NEO4J_PID}" 2>/dev/null || true
if [[ "${SECONDS}" -ge "${end}" ]]; then
echo " failed to stop"
echo "Neo4j (pid ${NEO4J_PID}) took more than ${SHUTDOWN_TIMEOUT} seconds to stop."
echo "Please see ${CONSOLE_LOG} for details."
return 1
fi
echo -n "."
sleep 1
done
fi
}
do_status() {
check_status
if [[ ! "${NEO4J_PID:-}" ]] ; then
echo "Neo4j is not running"
exit 3
else
echo "Neo4j is running at pid ${NEO4J_PID}"
fi
}
do_version() {
build_classpath
assemble_command_line
command_line=("${retval[@]}" "--version")
exec "${command_line[@]}"
}
main() {
setup_environment
CONSOLE_LOG="${NEO4J_LOGS}/neo4j.log"
NEO4J_PIDFILE="${NEO4J_RUN}/neo4j.pid"
readonly CONSOLE_LOG NEO4J_PIDFILE
setup_java_opts
check_java
setup_arbiter_options
case "${1:-}" in
console)
print_active_database
print_configurable_paths
do_console
;;
start)
print_active_database
print_configurable_paths
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
status)
do_status
;;
--version|version)
do_version
;;
help)
echo "Usage: ${PROGRAM} { console | start | stop | restart | status | version }"
;;
*)
echo >&2 "Usage: ${PROGRAM} { console | start | stop | restart | status | version }"
exit 1
;;
esac
}
main "$@"