2007-05-21 05:41:13 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# define default configuration
|
|
|
|
POLL=true
|
|
|
|
SMP=auto
|
|
|
|
ERL_MAX_PORTS=32000
|
|
|
|
ERL_PROCESSES=250000
|
|
|
|
ERL_MAX_ETS_TABLES=1400
|
|
|
|
|
|
|
|
# define default environment variables
|
2007-05-21 05:41:13 +02:00
|
|
|
NODE=ejabberd
|
|
|
|
HOST=localhost
|
2007-10-17 04:33:19 +02:00
|
|
|
ERLANG_NODE=$NODE@$HOST
|
2007-09-27 14:32:05 +02:00
|
|
|
ROOTDIR=@rootdir@
|
2007-11-26 08:59:35 +01:00
|
|
|
EJABBERD_CONFIG_PATH=$ROOTDIR/etc/ejabberd/ejabberd.cfg
|
2008-01-01 11:53:05 +01:00
|
|
|
LOGS_DIR=$ROOTDIR/var/log/ejabberd/
|
2007-10-17 04:33:19 +02:00
|
|
|
EJABBERD_DB=$ROOTDIR/var/lib/ejabberd/db/$NODE
|
2007-05-21 05:41:13 +02:00
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# read custom configuration
|
|
|
|
CONFIG=$ROOTDIR/etc/ejabberd/ejabberdctl.cfg
|
|
|
|
[ -f "$CONFIG" ] && . "$CONFIG"
|
|
|
|
|
|
|
|
# parse command line parameters
|
|
|
|
ARGS=
|
|
|
|
while [ $# -ne 0 ] ; do
|
|
|
|
PARAM=$1
|
|
|
|
shift
|
|
|
|
case $PARAM in
|
|
|
|
--) break ;;
|
|
|
|
--node) ERLANG_NODE=$1; shift ;;
|
|
|
|
--config) EJABBERD_CONFIG_PATH=$1 ; shift ;;
|
|
|
|
--ctl-config) CONFIG=$1 ; shift ;;
|
|
|
|
--logs) LOGS_DIR=$1 ; shift ;;
|
|
|
|
--spool) EJABBERD_DB=$1 ; shift ;;
|
|
|
|
*) ARGS="$ARGS $PARAM" ;;
|
|
|
|
esac
|
|
|
|
done
|
2007-05-21 05:41:13 +02:00
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
NAME=-name
|
|
|
|
[ "$ERLANG_NODE" = "${ERLANG_NODE%.*}" ] && NAME=-sname
|
2007-10-17 04:33:19 +02:00
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
ERLANG_OPTS="+K $POLL -smp $SMP +P $ERL_PROCESSES"
|
|
|
|
|
|
|
|
# define additional environment variables
|
|
|
|
EJABBERD_EBIN=$ROOTDIR/var/lib/ejabberd/ebin
|
|
|
|
EJABBERD_MSGS_PATH=$ROOTDIR/var/lib/ejabberd/priv/msgs
|
|
|
|
EJABBERD_SO_PATH=$ROOTDIR/var/lib/ejabberd/priv/lib
|
2008-03-21 16:42:14 +01:00
|
|
|
EJABBERD_BIN_PATH=$ROOTDIR/var/lib/ejabberd/priv/bin
|
2008-01-01 11:53:05 +01:00
|
|
|
EJABBERD_LOG_PATH=$LOGS_DIR/ejabberd.log
|
|
|
|
SASL_LOG_PATH=$LOGS_DIR/sasl.log
|
|
|
|
DATETIME=`date "+%Y%m%d-%H%M%S"`
|
|
|
|
ERL_CRASH_DUMP=$LOGS_DIR/erl_crash_$DATETIME.dump
|
2008-01-13 23:46:00 +01:00
|
|
|
ERL_INETRC=$ROOTDIR/etc/ejabberd/inetrc
|
2007-10-17 04:33:19 +02:00
|
|
|
HOME=$ROOTDIR/var/lib/ejabberd
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# export global variables
|
|
|
|
export EJABBERD_CONFIG_PATH
|
|
|
|
export EJABBERD_MSGS_PATH
|
2008-01-13 23:46:00 +01:00
|
|
|
export EJABBERD_LOG_PATH
|
2008-01-01 11:53:05 +01:00
|
|
|
export EJABBERD_SO_PATH
|
2008-03-21 16:42:14 +01:00
|
|
|
export EJABBERD_BIN_PATH
|
2008-01-13 23:46:00 +01:00
|
|
|
export ERL_CRASH_DUMP
|
|
|
|
export ERL_INETRC
|
2008-01-01 11:53:05 +01:00
|
|
|
export ERL_MAX_PORTS
|
|
|
|
export ERL_MAX_ETS_TABLES
|
|
|
|
export HOME
|
2007-10-17 04:33:19 +02:00
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
[ -d $EJABBERD_DB ] || mkdir -p $EJABBERD_DB
|
|
|
|
[ -d $LOGS_DIR ] || mkdir -p $LOGS_DIR
|
2007-10-17 04:33:19 +02:00
|
|
|
|
2007-11-26 08:59:35 +01:00
|
|
|
# Compatibility in ZSH
|
|
|
|
#setopt shwordsplit 2>/dev/null
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# start server
|
2007-11-26 08:59:35 +01:00
|
|
|
start ()
|
2007-05-21 05:41:13 +02:00
|
|
|
{
|
|
|
|
erl \
|
2008-01-01 11:53:05 +01:00
|
|
|
$NAME $ERLANG_NODE \
|
2007-05-21 05:41:13 +02:00
|
|
|
-noinput -detached \
|
2007-09-27 14:32:05 +02:00
|
|
|
-pa $EJABBERD_EBIN \
|
2007-05-21 05:41:13 +02:00
|
|
|
-mnesia dir "\"$EJABBERD_DB\"" \
|
|
|
|
-s ejabberd \
|
2008-01-01 11:53:05 +01:00
|
|
|
-sasl sasl_error_logger \{file,\"$SASL_LOG_PATH\"\} \
|
|
|
|
$ERLANG_OPTS $ARGS "$@"
|
2007-05-21 05:41:13 +02:00
|
|
|
}
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# attach to server
|
2007-11-26 08:59:35 +01:00
|
|
|
debug ()
|
2007-05-21 05:41:13 +02:00
|
|
|
{
|
2007-10-17 04:33:19 +02:00
|
|
|
echo "--------------------------------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
echo "IMPORTANT: we will attempt to attach an INTERACTIVE shell"
|
|
|
|
echo "to an already running ejabberd node."
|
|
|
|
echo "If an ERROR is printed, it means the connection was not succesfull."
|
|
|
|
echo "You can interact with the ejabberd node if you know how to use it."
|
|
|
|
echo "Please be extremely cautious with your actions,"
|
|
|
|
echo "and exit immediately if you are not completely sure."
|
|
|
|
echo ""
|
|
|
|
echo "To detach this shell from ejabberd, press:"
|
|
|
|
echo " control+c, control+c"
|
|
|
|
echo ""
|
|
|
|
echo "--------------------------------------------------------------------"
|
2007-11-26 08:59:35 +01:00
|
|
|
echo "Press any key to continue"
|
|
|
|
read foo
|
2007-10-17 04:33:19 +02:00
|
|
|
echo ""
|
|
|
|
erl \
|
2008-01-01 11:53:05 +01:00
|
|
|
$NAME ${NODE}debug \
|
|
|
|
-remsh $ERLANG_NODE \
|
|
|
|
$ERLANG_OPTS $ARGS "$@"
|
2007-10-17 04:33:19 +02:00
|
|
|
}
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# start interactive server
|
2007-11-26 08:59:35 +01:00
|
|
|
live ()
|
2007-10-17 04:33:19 +02:00
|
|
|
{
|
|
|
|
echo "--------------------------------------------------------------------"
|
|
|
|
echo ""
|
|
|
|
echo "IMPORTANT: ejabberd is going to start in LIVE (interactive) mode."
|
|
|
|
echo "All log messages will be shown in the command shell."
|
|
|
|
echo "You can interact with the ejabberd node if you know how to use it."
|
|
|
|
echo "Please be extremely cautious with your actions,"
|
|
|
|
echo "and exit immediately if you are not completely sure."
|
|
|
|
echo ""
|
|
|
|
echo "To exit this LIVE mode and stop ejabberd, press:"
|
|
|
|
echo " q(). and press the Enter key"
|
|
|
|
echo ""
|
|
|
|
echo "--------------------------------------------------------------------"
|
2007-11-26 08:59:35 +01:00
|
|
|
echo "Press any key to continue"
|
|
|
|
read foo
|
2007-10-17 04:33:19 +02:00
|
|
|
echo ""
|
2007-05-21 05:41:13 +02:00
|
|
|
erl \
|
2008-01-01 11:53:05 +01:00
|
|
|
$NAME $ERLANG_NODE \
|
2007-10-17 04:33:19 +02:00
|
|
|
$ERLANG_OPTS \
|
2007-09-27 14:32:05 +02:00
|
|
|
-pa $EJABBERD_EBIN \
|
2007-05-21 05:41:13 +02:00
|
|
|
-mnesia dir "\"$EJABBERD_DB\"" \
|
2008-01-01 11:53:05 +01:00
|
|
|
-s ejabberd \
|
|
|
|
$ERLANG_OPTS $ARGS "$@"
|
2007-05-21 05:41:13 +02:00
|
|
|
}
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# common control function
|
2007-11-26 08:59:35 +01:00
|
|
|
ctl ()
|
2007-05-21 05:41:13 +02:00
|
|
|
{
|
|
|
|
erl \
|
2008-01-01 11:53:05 +01:00
|
|
|
$NAME ejabberdctl \
|
2007-05-21 05:41:13 +02:00
|
|
|
-noinput \
|
2007-09-27 14:32:05 +02:00
|
|
|
-pa $EJABBERD_EBIN \
|
2007-10-17 04:33:19 +02:00
|
|
|
-s ejabberd_ctl -extra $ERLANG_NODE $@
|
2008-01-01 11:53:05 +01:00
|
|
|
result=$?
|
|
|
|
case $result in
|
|
|
|
0) :;;
|
|
|
|
*)
|
|
|
|
echo ""
|
|
|
|
echo "Commands to start an ejabberd node:"
|
|
|
|
echo " start Start an ejabberd node in server mode"
|
|
|
|
echo " debug Attach an interactive Erlang shell to a running ejabberd node"
|
|
|
|
echo " live Start an ejabberd node in live (interactive) mode"
|
|
|
|
echo ""
|
|
|
|
echo "Optional parameters when starting an ejabberd node:"
|
|
|
|
echo " --config file Config file of ejabberd: $EJABBERD_CONFIG_PATH"
|
|
|
|
echo " --ctl-config file Config file of ejabberdctl: $CONFIG"
|
|
|
|
echo " --logs dir Directory for logs: $LOGS_DIR"
|
|
|
|
echo " --spool dir Database spool dir: $EJABBERD_DB"
|
|
|
|
echo "";;
|
2007-10-17 04:33:19 +02:00
|
|
|
esac
|
2008-01-01 11:53:05 +01:00
|
|
|
return $result
|
2007-05-21 05:41:13 +02:00
|
|
|
}
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# display ctl usage
|
2007-11-26 08:59:35 +01:00
|
|
|
usage ()
|
2007-05-21 05:41:13 +02:00
|
|
|
{
|
|
|
|
ctl
|
|
|
|
exit
|
|
|
|
}
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
case $ARGS in
|
|
|
|
' start') start;;
|
|
|
|
' debug') debug;;
|
|
|
|
' live') live;;
|
|
|
|
*) ctl $ARGS;;
|
2007-05-21 05:41:13 +02:00
|
|
|
esac
|