Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 8098c33bd5
Fetching contributors…

Cannot retrieve contributors at this time

executable file 359 lines (332 sloc) 12.716 kb
#!/bin/bash
# Copyright 2007-2011 Zuse Institute Berlin
#
# 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.
prefix=@prefix@
exec_prefix=@exec_prefix@
datarootdir=@datarootdir@
ERL=@ERL@
EPMD=@EPMD@
# /bin
BINDIR=@bindir@
# /etc/scalaris/
ETCDIR=@sysconfdir@/scalaris
# /lib/scalaris/
SCALARISDIR=@libdir@/scalaris
# /lib/scalaris/ebin
BEAMDIR=@libdir@/scalaris/ebin
# /lib/scalaris/docroot
DOCROOTDIR=$SCALARISDIR/docroot
# /share/doc/scalaris
DOCDIR=@docdir@
# /share/java
JAVADIR=@datarootdir@/java
# /var/log/scalaris
LOGDIR=@localstatedir@/log/scalaris
# /usr/bin/scalaris
SCALARISCLIENT=${exec_prefix}/bin/scalaris
TOKEFLAGS="@ERLANG_TOKE_FLAGS@"
# default values (commandline options change these parameters)
NODE_NAME=node1
daemonize=0
first=0
first_quorum=0
verbose=0
port=""
yaws_port=""
join_at=""
start_mgmt_server=0
start_dht_node="" # "dht_node"
usage(){
echo "usage: scalarisctl [options] [services] <cmd>"
echo " options:"
echo " -h - print this help message"
echo " -d - daemonize"
echo " -f - first node (to start a new Scalaris instead of joining one) (not with -q)"
echo " -q - elect first node from known hosts (not with -f)"
echo " -n <name> - Erlang process name (default 'node')"
echo " -p <port> - TCP port for the Scalaris node"
echo " -y <port> - TCP port for the built-in webserver"
echo " -k <key> - join at the given key"
echo " -v - verbose"
echo " services:"
echo " -m - global Scalaris management server"
echo " -s - Scalaris node (see also -f)"
echo " commands:"
echo " checkinstallation"
echo " - test installation"
echo " start - start services (see -m and -s)"
echo " stop - stop a scalaris process defined by its name (see -n)"
echo " restart - restart a scalaris process by its name (see -n)"
echo ""
echo " list - list locally running Erlang VMs"
echo " debug - connect to a running node via an Erlang shell"
echo ""
exit $1
}
fix_paths() {
ABSPATH="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
DIRNAME=`dirname $ABSPATH`
# is this a svn checkout or an (rpm/deb/manual) installation?
if [ "$DIRNAME" != "$BINDIR" ]; then
# scalaris
SCALARISDIR=`dirname $DIRNAME`
# /etc/scalaris/
ETCDIR=$SCALARISDIR/bin
# scalaris/ebin
BEAMDIR=$SCALARISDIR/ebin
# scalaris/docroot
DOCROOTDIR=$SCALARISDIR/docroot
# scalaris/log
LOGDIR=$SCALARISDIR/log
# /usr/bin/scalaris
SCALARISCLIENT="$SCALARISDIR/java-api/scalaris --noconfig"
fi
}
# only get cookie from scalarisctl.conf if installed!
get_cookie() {
ABSPATH="$(cd "${0%/*}" 2>/dev/null; echo "$PWD"/"${0##*/}")"
DIRNAME=`dirname $ABSPATH`
if [ "$DIRNAME" = "$BINDIR" ]; then
# system config
. ${ETCDIR}/scalarisctl.conf
# load user scalaris configuration (overrides system config)
if [ -f "$HOME/.scalaris/scalarisctl.conf" ] ; then
. $HOME/.scalaris/scalarisctl.conf
fi
fi
echo -n ${cookie:-"chocolate chip cookie"}
}
checkinstallation() {
$ERL -noinput -eval 'halt(0).'
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo "ERROR: erl could not be run"
echo "We were trying to run: erl -noinput -eval 'halt(0).'"
exit 1
fi
if [ ! -s `which erl` ]; then
echo "ERROR: your erl executable is of size zero bytes: `which erl`"
echo "ls -l `which erl`"
exit 1
fi
$ERL -noinput -name checkinstallation -eval 'halt(0).' > /dev/null
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo "ERROR: erl could not create a Erlang VM named 'checkinstallation'"
echo "Are you already running a Scalaris boot server?"
echo "'scalarisctl list' gives you a list of currently registered Erlang VMs"
echo "We were trying to run: erl -noinput -name checkinstallation -eval 'halt(0).'"
fi
$ERL -noinput -eval 'case catch crypto:start() of ok -> halt(0); _ -> halt(1) end.'
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo "ERROR: erlang could not start the crypto module"
echo "We were trying to run: $ERL -noinput -eval 'case catch crypto:start() of ok -> halt(0); _ -> halt(1) end.'"
exit 1
fi
if [ -e $ETCDIR/scalaris.cfg ]; then
$ERL -noinput -eval "case file:consult(\"$ETCDIR/scalaris.cfg\") of {error, _} -> halt(1); _ -> halt(0) end"
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo "ERROR: there is a syntax error in: $ETCDIR/scalaris.cfg"
echo "We were trying to run: $ERL -noinput -eval \"A = file:consult(\"$ETCDIR/scalaris.cfg\"), io:format(\"~p~n\", [A]), halt(0) end\""
exit 1
fi
else
echo "ERROR: there is no config file: $ETCDIR/scalaris.cfg"
fi
if [ -e $ETCDIR/scalaris.local.cfg ]; then
$ERL -noinput -eval "case file:consult(\"$ETCDIR/scalaris.local.cfg\") of {error, _} -> halt(1); _ -> halt(0) end"
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo "ERROR: there is a syntax error in: $ETCDIR/scalaris.local.cfg"
echo "We were trying to run: $ERL -noinput -eval \"A = file:consult(\"$ETCDIR/scalaris.local.cfg\"), io:format(\"~p~n\", [A]), halt(0) end\""
exit 1
fi
fi
$ERL -noinput -pa $BEAMDIR -eval 'case {code:ensure_loaded(mgmt_server), code:ensure_loaded(dht_node)} of {{module,mgmt_server},{module,dht_node}} -> halt(0); X -> halt(1) end.'
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo "ERROR: could not find Scalaris' beam files"
echo "We were trying to run: $ERL -noinput -pa $BEAMDIR -eval 'case {code:ensure_loaded(mgmt_server), code:ensure_loaded(dht_node)} of {{module,mgmt_server},{module,dht_node}} -> halt(0); X -> halt(1) end.'"
exit 1
fi
$SCALARISCLIENT > /dev/null 2>/dev/null
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo -n "INFO: could not find Scalaris' Java-API files. "
echo "You won't be able to use the 'scalaris' command line script to access Scalaris."
echo " 'make java' will build the Java-API"
echo "We were trying to run: $SCALARISCLIENT"
else
ERLANGHOST=`$ERL -noinput -name boot -eval "io:format(\"~p~n\", [node()]), halt(0)."`
JAVAHOST="'boot@`$SCALARISCLIENT -lh`'"
if [ "$ERLANGHOST" != "$JAVAHOST" ]; then
echo "WARNING: the hostnames reported by Erlang and Java do not match. You won't be"
echo " able to connect to erlang using the Java-API through scalaris.jar. Also, the"
echo " java unit tests will probably not work."
echo " The java-api/scalaris script will work around this by asking erlang for its"
echo " hostname and using this for both."
echo " If you implement your own application either do not use \"@localhost\" in the"
echo " scalaris.properties file or set the scalaris.erlang.nodename system property"
echo " with the correct hostname (only the domain name part after the \"@\") or fix"
echo " your hostname setup system-wide."
echo " Please refer to your system's manual to set your hostname, e.g. change the"
echo " values in /etc/hosts or /etc/hostname, and check that it is consistent with"
echo " the DNS."
echo "erlang: $ERL -noinput -name boot -eval \"io:format(\"~p~n\", [node()]), halt(0).\""
echo " -> $ERLANGHOST"
echo "java: $SCALARISCLIENT -lh"
echo " -> $JAVAHOST"
fi
fi
CHECKCONFIGMSG=`$ERL -noinput -pa $BEAMDIR \
-eval "config:start_link([\"$ETCDIR/scalaris.cfg\", \"$ETCDIR/scalaris.local.cfg\"]), halt(0)."`
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo "$CHECKCONFIGMSG"
echo "ERROR: some parameters in the config files are wrong or missing"
echo "We were trying to run: $ERL -noinput -pa $BEAMDIR -eval \"config:start_link([\"$ETCDIR/scalaris.cfg\", \"$ETCDIR/scalaris.local.cfg\"]), halt(0).\""
exit 1
fi
exit 0
}
scalarisstart(){
$ERL -noinput -name $NODE_NAME -eval 'halt(0).' 2>/dev/null > /dev/null
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo ""
echo "ERROR: erl could not create a Erlang VM named '$NODE_NAME'"
echo "Are you already running a Scalaris server with this name?"
echo "You can change the name by the -n option (see -h)."
echo "'scalarisctl list' gives you a list of currently registered Erlang VMs"
echo "We were trying to run: erl -noinput -name $NODE_NAME -eval 'halt(0).'"
exit 1
fi
if [ $daemonize -ne 0 ]; then
BACKGROUND="-detached"
fi
local tmp
tmp=""
if [ $first -eq 1 ]; then
tmp="$tmp -scalaris first true"
fi
if [ $first_quorum -eq 1 ]; then
tmp="$tmp -scalaris first_quorum true"
fi
if [ "$port" != "" ]; then
tmp="$tmp -scalaris port $port"
fi
if [ "$yaws_port" != "" ]; then
tmp="$tmp -scalaris yaws_port $yaws_port"
fi
if [ "$join_at" != "" ]; then
tmp="$tmp -scalaris join_at $join_at"
fi
if [ $start_mgmt_server -eq 1 ]; then
tmp="$tmp -scalaris start_mgmt_server true"
fi
if [ "$start_dht_node" != "" ]; then
tmp="$tmp -scalaris start_dht_node $start_dht_node"
fi
if [ "$verbose" -eq 1 ]; then
tmp="$tmp -scalaris verbose true"
fi
if [ "$1" == "-v" ]; then
# -v can be given after <cmd> and then is not handled by getopt.
shift
tmp="$tmp -scalaris verbose true"
fi
SCALARIS_ADDITIONAL_PARAMETERS="$SCALARIS_ADDITIONAL_PARAMETERS $tmp"
export YAWSHOME="$HOME/.scalaris/$NODE_NAME"
mkdir -p "$YAWSHOME"
mkdir -p "$LOGDIR/$NODE_NAME"
pushd $BEAMDIR > /dev/null
$ERL -setcookie "$SCALARIS_COOKIE" \
-pa $SCALARISDIR/contrib/yaws/ebin \
-pa $SCALARISDIR/contrib/log4erl/ebin \
-pa $BEAMDIR $TOKEFLAGS $BACKGROUND \
-yaws embedded true \
-scalaris log_path "\"$LOGDIR/$NODE_NAME\"" \
-scalaris docroot "\"$DOCROOTDIR\"" \
-scalaris config "\"$ETCDIR/scalaris.cfg\"" \
-scalaris local_config "\"$ETCDIR/scalaris.local.cfg\"" \
-connect_all false -hidden -name $NODE_NAME \
$SCALARIS_ADDITIONAL_PARAMETERS \
-s scalaris $*;
FAILED=$?
if [ $FAILED -ne 0 ]; then
echo "ERROR: could not start scalaris"
echo " consider running scalarisctl checkinstallation"
exit 1
fi
popd > /dev/null
}
scalarisstop(){
pushd $BEAMDIR > /dev/null
$ERL -setcookie "$SCALARIS_COOKIE" \
-name ctl_$RANDOM \
-pa $BEAMDIR \
-noinput \
-s scalaris cli -extra $NODE_NAME@`hostname -f` stop
popd > /dev/null
}
list_erlang_processes(){
$EPMD -names || echo "could not run epmd"
}
debug(){
# look into epmd -list: boot or node
$ERL -pa $BEAMDIR -setcookie "$SCALARIS_COOKIE" -name rem -remsh $NODE_NAME@`hostname -f` $*
}
fix_paths
SCALARIS_COOKIE="`get_cookie`"
while getopts "dhifqmsvn:p:y:k:" optionName; do
case "$optionName" in
d) daemonize=1;;
f) first=1;;
q) first_quorum=1;;
h) usage 0;;
i) echo "WARN: interactive is now default";;
k) join_at=$OPTARG;;
n) NODE_NAME=$OPTARG;;
p) port=$OPTARG;;
y) yaws_port=$OPTARG;;
m) start_mgmt_server=1;;
s) start_dht_node="dht_node";;
v) echo setting verbose from cli
verbose=1;;
[?]) echo "Wrong parameter $optionName."
usage 1;;
esac
done
shift $(($OPTIND-1))
case $1 in
checkinstallation)
checkinstallation;;
start)
shift
scalarisstart $*;;
stop)
scalarisstop;;
restart)
scalarisstop
shift 1
scalarisstart $*;;
list)
list_erlang_processes $*;;
debug)
shift 1
debug $*;;
*) usage 1;;
esac
Jump to Line
Something went wrong with that request. Please try again.