/
cassandra
executable file
·166 lines (150 loc) · 5.39 KB
/
cassandra
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
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
# OPTIONS:
# -f: start in foreground
# -p <filename>: log the pid to a file (useful to kill it later)
# CONTROLLING STARTUP:
#
# This script relies on few environment variables to determine startup
# behavior, those variables are:
#
# CLASSPATH -- A Java classpath containing everything necessary to run.
# JVM_OPTS -- Additional arguments to the JVM for heap size, etc
# CASSANDRA_CONF -- Directory containing Cassandra configuration files.
#
# As a convenience, a fragment of shell is sourced in order to set one or
# more of these variables. This so-called `include' can be placed in a
# number of locations and will be searched for in order. The lowest
# priority search path is the same directory as the startup script, and
# since this is the location of the sample in the project tree, it should
# almost work Out Of The Box.
#
# Any serious use-case though will likely require customization of the
# include. For production installations, it is recommended that you copy
# the sample to one of /usr/share/cassandra/cassandra.in.sh,
# /usr/local/share/cassandra/cassandra.in.sh, or
# /opt/cassandra/cassandra.in.sh and make your modifications there.
#
# Another option is to specify the full path to the include file in the
# environment. For example:
#
# $ CASSANDRA_INCLUDE=/path/to/in.sh cassandra -p /var/run/cass.pid
#
# Note: This is particularly handy for running multiple instances on a
# single installation, or for quick tests.
#
# Finally, developers and enthusiasts who frequently run from an SVN
# checkout, and do not want to locally modify bin/cassandra.in.sh, can put
# a customized include file at ~/.cassandra.in.sh.
#
# If you would rather configure startup entirely from the environment, you
# can disable the include by exporting an empty CASSANDRA_INCLUDE, or by
# ensuring that no include files exist in the aforementioned search list.
# Be aware that you will be entirely responsible for populating the needed
# environment variables.
# If an include wasn't specified in the environment, then search for one...
if [ "x$CASSANDRA_INCLUDE" = "x" ]; then
# Locations (in order) to use when searching for an include file.
for include in /usr/share/cassandra/cassandra.in.sh \
/usr/local/share/cassandra/cassandra.in.sh \
/opt/cassandra/cassandra.in.sh \
~/.cassandra.in.sh \
`dirname $0`/cassandra.in.sh; do
if [ -r $include ]; then
. $include
break
fi
done
# ...otherwise, source the specified include.
elif [ -r $CASSANDRA_INCLUDE ]; then
. $CASSANDRA_INCLUDE
fi
# Use JAVA_HOME if set, otherwise look for java in PATH
if [ -x $JAVA_HOME/bin/java ]; then
JAVA=$JAVA_HOME/bin/java
else
JAVA=`which java`
fi
if [ -z $CASSANDRA_CONF -o -z $CLASSPATH ]; then
echo "You must set the CASSANDRA_CONF and CLASSPATH vars" >&2
exit 1
fi
# Special-case path variables.
case "`uname`" in
CYGWIN*)
CLASSPATH=`cygpath -p -w "$CLASSPATH"`
CASSANDRA_CONF=`cygpath -p -w "$CASSANDRA_CONF"`
;;
esac
launch_service()
{
pidpath=$1
foreground=$2
props=$3
cassandra_parms="-Dstorage-config=$CASSANDRA_CONF"
if [ "x$pidpath" != "x" ]; then
cassandra_parms="$cassandra_parms -Dcassandra-pidfile=$pidpath"
fi
# The cassandra-foreground option will tell CassandraDaemon not
# to close stdout/stderr, but it's up to us not to background.
if [ "x$foreground" != "x" ]; then
cassandra_parms="$cassandra_parms -Dcassandra-foreground=yes"
$JAVA $JVM_OPTS $cassandra_parms -cp $CLASSPATH $props \
org.apache.cassandra.thrift.CassandraDaemon
# Startup CassandraDaemon, background it, and write the pid.
else
exec $JAVA $JVM_OPTS $cassandra_parms -cp $CLASSPATH $props \
org.apache.cassandra.thrift.CassandraDaemon <&- &
[ ! -z $pidpath ] && printf "%d" $! > $pidpath
fi
return $?
}
# Parse any command line options.
args=`getopt fhp:bD: "$@"`
eval set -- "$args"
while true; do
case "$1" in
-p)
pidfile="$2"
shift 2
;;
-f)
foreground="yes"
shift
;;
-h)
echo "Usage: $0 [-f] [-h] [-p pidfile] [-b]"
exit 0
;;
-D)
properties="$properties -D$2"
shift 2
;;
--)
shift
break
;;
*)
echo "Error parsing arguments!" >&2
exit 1
;;
esac
done
# Start up the service
launch_service "$pidfile" "$foreground" "$properties"
exit $?
# vi:ai sw=4 ts=4 tw=0 et