-
Notifications
You must be signed in to change notification settings - Fork 28
/
couchbase-server.sh.in
287 lines (236 loc) · 6.78 KB
/
couchbase-server.sh.in
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
#! /usr/bin/env bash
#
# Copyright (c) 2010-2018, Couchbase, 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.
SOFTWARE_VERSION="@PRODUCT_VERSION@"
if [ x"${SOFTWARE_VERSION}" = "x" ]
then
SOFTWARE_VERSION="unsupported developer build"
fi
ENTERPRISE=`echo @BUILD_ENTERPRISE@ | tr '[:upper:]' '[:lower:]'`
if [ x"${ENTERPRISE}" = "xtrue" ]
then
SOFTWARE_VERSION="${SOFTWARE_VERSION} (EE)"
else
SOFTWARE_VERSION="${SOFTWARE_VERSION} (CE)"
fi
PATH="@PREFIX@/bin":$PATH
export PATH
ERL_LIBS="@PREFIX@/lib/ns_server/erlang/lib:@PREFIX@/lib/couchdb/erlang/lib:@PREFIX@/lib/couchdb/plugins"
export ERL_LIBS
CB_EBIN_PATH="@PREFIX@/lib/ns_server/erlang/lib/ns_babysitter/ebin"
DEFAULT_CONFIG_DIR="@PREFIX@/etc/couchdb/default.d"
DEFAULT_CONFIG_FILE="@PREFIX@/etc/couchdb/default.ini"
LOCAL_CONFIG_DIR="@PREFIX@/etc/couchdb/local.d"
LOCAL_CONFIG_FILE="@PREFIX@/etc/couchdb/local.ini"
PIDFILE="@PREFIX@/var/lib/couchbase/couchbase-server.pid"
COOKIEFILE="@PREFIX@/var/lib/couchbase/couchbase-server.babysitter.cookie"
NODEFILE="@PREFIX@/var/lib/couchbase/couchbase-server.babysitter.node"
STATIC_CONFIG_PATH="@PREFIX@/etc/couchbase/static_config"
couch_start_arguments=""
LD_LIBRARY_PATH="@PREFIX@/lib":"@PREFIX@/lib/memcached":$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
ERL_CRASH_DUMP_BASE=erl_crash.dump.$(date +%s).$$
ERL_CRASH_DUMP=$ERL_CRASH_DUMP_BASE.babysitter
export ERL_CRASH_DUMP_BASE
export ERL_CRASH_DUMP
ERL_FULLSWEEP_AFTER=512
export ERL_FULLSWEEP_AFTER
# For some obscure reason erl requires HOME environment variable to be set.
if [ -z "$HOME" ]
then
export HOME=/tmp
fi
_check_nofile () {
if [ `ulimit -n` -lt 70000 ]
then
cat <<EOF
The maximum number of open files for the couchbase user is set too low.
It must be at least 70000.
EOF
if [ -f /etc/security/limits.conf ]
then
cat <<EOF
Normally this can be increased by adding the following lines to
/etc/security/limits.conf:
couchbase soft nofile <value>
couchbase hard nofile <value>
Where <value> is greater than 70000. The procedure may be totally
different if you're running so called "non-root/non-sudo install" or
if you've built Couchbase Server from source.
EOF
fi
fi
}
_check_inet_mode() {
OUTPUT=`erl \
-pa $CB_EBIN_PATH \
-noshell \
-setcookie nocookie \
-run ns_babysitter_bootstrap ipv6_from_static_config $STATIC_CONFIG_PATH`
if [ $? -ne 0 ]
then
echo $OUTPUT
exit 1
fi
if [ $OUTPUT == "true" ]; then
if [ x"${ENTERPRISE}" = "xtrue" ]
then
VM_NAME='babysitter_of_ns_1@::1'
PROTO_DIST='inet6_tcp'
else
echo "IPv6 is supported only in enterprise edition"
exit 1
fi
else
VM_NAME='[email protected]'
PROTO_DIST='inet_tcp'
fi
}
_prepare_datadir () {
datadir="@PREFIX@/var/lib/couchbase"
test -d "$datadir" || mkdir -p "$datadir"
cd "$datadir"
}
_maybe_start_epmd () {
# Initialize distributed erlang on the system (i.e. epmd)
erl -noshell -setcookie nocookie -sname init -run init stop 2>&1 > /dev/null
if [ $? -ne 0 ]
then
exit 1
fi
}
_add_config_file () {
couch_start_arguments="$couch_start_arguments $1"
}
_add_config_dir () {
for file in "$1"/*.ini; do
if [ -r "$file" ]; then
_add_config_file "$file"
fi
done
}
_load_config () {
_add_config_file "$DEFAULT_CONFIG_FILE"
_add_config_dir "$DEFAULT_CONFIG_DIR"
_add_config_file "$LOCAL_CONFIG_FILE"
_add_config_dir "$LOCAL_CONFIG_DIR"
if [ "$COUCHDB_ADDITIONAL_CONFIG_FILE" != '' ]
then
_add_config_file "$COUCHDB_ADDITIONAL_CONFIG_FILE"
fi
}
_drop_old_crashdumps () {
KEEP="`ls -1 erl_crash.dump.* 2>/dev/null | sort | tail -n 10`"
for file in erl_crash.dump.*; do
if [[ "$KEEP" != *$file* ]]; then
rm -f $file
fi
done
}
_start() {
_check_nofile
_prepare_datadir
_maybe_start_epmd
_load_config
# note: we depend on pwd being $datadir from _prepare_datadir
_drop_old_crashdumps
umask 007
exec erl \
+A 16 \
-smp enable \
-kernel inet_dist_listen_min 21100 inet_dist_listen_max 21299 \
error_logger false \
global_enable_tracing true \
-sasl sasl_error_logger false \
-hidden \
-name $VM_NAME \
-proto_dist $PROTO_DIST \
-setcookie nocookie \
$* \
-run ns_babysitter_bootstrap -- \
-couch_ini $couch_start_arguments \
-ns_babysitter cookiefile "\"$COOKIEFILE\"" \
-ns_babysitter nodefile "\"$NODEFILE\"" \
-ns_babysitter pidfile "\"$PIDFILE\"" \
-ns_server config_path "\"$STATIC_CONFIG_PATH\""
}
_stop() {
[ -f "$COOKIEFILE" -a -f "$NODEFILE" ] || return 1
cookie=`cat "$COOKIEFILE"`
node=`cat "$NODEFILE"`
erl \
-name executioner@executioner \
-proto_dist $PROTO_DIST \
-noshell \
-hidden \
-setcookie "$cookie" \
-eval "ns_babysitter_bootstrap:remote_stop('$node')"
errcode=$?
if [ $errcode -eq 0 ]; then
rm "$COOKIEFILE" "$NODEFILE"
epmd -kill >/dev/null
fi
return $errcode
}
usage() {
cat <<EOF
couchbase-server is a script to start/stop the Couchbase server.
Usage: $0 [options]
Special options:
--help, -h Print this help text
--version, -v Print software Version
-k Stop couchbase Server
All other options and arguments will be passed to the Couchbase
server and should NOT be used unless you know what you're doing.
EOF
}
_parse_options () {
# the getopt lack support for longopts..
if [ "$1" == "--version" ]
then
echo "Couchbase Server ${SOFTWARE_VERSION}"
exit 0
fi
if [ "$1" == "--help" ]
then
usage
exit 0
fi
# set +e
while getopts "kvh" opt
do
case $opt in
k)
_stop
exit $?
;;
v)
echo "Couchbase Server ${SOFTWARE_VERSION}"
exit 0
;;
h)
usage
exit 0
;;
*)
break
;;
esac
done
_start $*
}
_check_inet_mode
_parse_options $*