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
|
2008-07-13 00:02:16 +02:00
|
|
|
ERL=@erl@
|
|
|
|
INSTALLUSER=@installuser@
|
2007-05-21 05:41:13 +02:00
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# parse command line parameters
|
|
|
|
ARGS=
|
|
|
|
while [ $# -ne 0 ] ; do
|
|
|
|
PARAM=$1
|
|
|
|
shift
|
|
|
|
case $PARAM in
|
|
|
|
--) break ;;
|
2009-05-16 00:08:00 +02:00
|
|
|
--node) ERLANG_NODE_ARG=$1; shift ;;
|
2008-11-23 17:41:50 +01:00
|
|
|
--config-dir) ETCDIR=$1 ; shift ;;
|
2008-01-01 11:53:05 +01:00
|
|
|
--config) EJABBERD_CONFIG_PATH=$1 ; shift ;;
|
2008-07-16 12:55:50 +02:00
|
|
|
--ctl-config) EJABBERDCTL_CONFIG_PATH=$1 ; shift ;;
|
|
|
|
--logs) LOGS_DIR=$1 ; shift ;;
|
2008-07-13 21:10:01 +02:00
|
|
|
--spool) SPOOLDIR=$1 ; shift ;;
|
2008-01-01 11:53:05 +01:00
|
|
|
*) ARGS="$ARGS $PARAM" ;;
|
|
|
|
esac
|
|
|
|
done
|
2007-05-21 05:41:13 +02:00
|
|
|
|
2008-11-23 17:41:50 +01:00
|
|
|
# Define ejabberd variable if they have not been defined from the command line
|
|
|
|
if [ "$ETCDIR" = "" ] ; then
|
|
|
|
ETCDIR=@SYSCONFDIR@/ejabberd
|
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_CONFIG_PATH" = "" ] ; then
|
|
|
|
EJABBERD_CONFIG_PATH=$ETCDIR/ejabberd.cfg
|
|
|
|
fi
|
2008-11-26 19:02:41 +01:00
|
|
|
if [ "$EJABBERDCTL_CONFIG_PATH" = "" ] ; then
|
|
|
|
EJABBERDCTL_CONFIG_PATH=$ETCDIR/ejabberdctl.cfg
|
|
|
|
fi
|
|
|
|
[ -f "$EJABBERDCTL_CONFIG_PATH" ] && . "$EJABBERDCTL_CONFIG_PATH"
|
2008-11-23 17:41:50 +01:00
|
|
|
if [ "$LOGS_DIR" = "" ] ; then
|
|
|
|
LOGS_DIR=@LOCALSTATEDIR@/log/ejabberd
|
|
|
|
fi
|
|
|
|
if [ "$SPOOLDIR" = "" ] ; then
|
|
|
|
SPOOLDIR=@LOCALSTATEDIR@/lib/ejabberd
|
|
|
|
fi
|
2009-01-20 20:42:08 +01:00
|
|
|
if [ "$EJABBERD_DOC_PATH" = "" ] ; then
|
|
|
|
EJABBERD_DOC_PATH=@DOCDIR@
|
|
|
|
fi
|
2009-05-16 00:08:00 +02:00
|
|
|
if [ "$ERLANG_NODE_ARG" != "" ] ; then
|
|
|
|
ERLANG_NODE=$ERLANG_NODE_ARG
|
|
|
|
fi
|
2008-11-23 17:41:50 +01:00
|
|
|
|
2008-07-13 00:02:16 +02:00
|
|
|
# check the proper system user is used
|
|
|
|
ID=`id -g`
|
|
|
|
EJID=`id -g $INSTALLUSER`
|
|
|
|
EXEC_CMD="false"
|
|
|
|
if [ $ID -eq 0 ] ; then
|
2010-01-05 20:43:03 +01:00
|
|
|
EXEC_CMD="su ${INSTALLUSER} -p -c"
|
2008-07-13 00:02:16 +02:00
|
|
|
fi
|
|
|
|
if [ "$ID" -eq "$EJID" ] ; then
|
|
|
|
EXEC_CMD="sh -c"
|
|
|
|
fi
|
|
|
|
if [ "$EXEC_CMD" = "false" ] ; then
|
|
|
|
echo "This command can only be run by root or the user $INSTALLUSER" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
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-04-01 11:07:29 +02:00
|
|
|
if [ "$FIREWALL_WINDOW" = "" ] ; then
|
|
|
|
KERNEL_OPTS=""
|
|
|
|
else
|
2008-04-01 13:47:51 +02:00
|
|
|
KERNEL_OPTS="-kernel inet_dist_listen_min ${FIREWALL_WINDOW%-*} inet_dist_listen_max ${FIREWALL_WINDOW#*-}"
|
2008-04-01 11:07:29 +02:00
|
|
|
fi
|
|
|
|
|
2009-05-16 00:10:53 +02:00
|
|
|
ERLANG_OPTS="+K $POLL -smp $SMP +P $ERL_PROCESSES $ERL_OPTIONS $KERNEL_OPTS"
|
2008-01-01 11:53:05 +01:00
|
|
|
|
|
|
|
# define additional environment variables
|
2009-03-19 22:28:34 +01:00
|
|
|
if [ "$EJABBERDDIR" = "" ]; then
|
|
|
|
EJABBERDDIR=@LIBDIR@/ejabberd
|
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_EBIN_PATH" = "" ]; then
|
|
|
|
EJABBERD_EBIN_PATH=$EJABBERDDIR/ebin
|
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_PRIV_PATH" = "" ]; then
|
|
|
|
EJABBERD_PRIV_PATH=$EJABBERDDIR/priv
|
|
|
|
fi
|
|
|
|
if [ "$EJABBRD_BIN_PATH" = "" ]; then
|
|
|
|
EJABBERD_BIN_PATH=$EJABBERD_PRIV_PATH/bin
|
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_SO_PATH" = "" ]; then
|
|
|
|
EJABBERD_SO_PATH=$EJABBERD_PRIV_PATH/lib
|
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_MSGS_PATH" = "" ]; then
|
|
|
|
EJABBERD_MSGS_PATH=$EJABBERD_PRIV_PATH/msgs
|
|
|
|
fi
|
2008-07-16 12:55:50 +02:00
|
|
|
|
|
|
|
EJABBERD_LOG_PATH=$LOGS_DIR/ejabberd.log
|
2009-08-31 10:41:56 +02:00
|
|
|
SASL_LOG_PATH=$LOGS_DIR/erlang.log
|
2008-01-01 11:53:05 +01:00
|
|
|
DATETIME=`date "+%Y%m%d-%H%M%S"`
|
2008-07-16 12:55:50 +02:00
|
|
|
ERL_CRASH_DUMP=$LOGS_DIR/erl_crash_$DATETIME.dump
|
2008-07-13 21:10:01 +02:00
|
|
|
ERL_INETRC=$ETCDIR/inetrc
|
|
|
|
HOME=$SPOOLDIR
|
|
|
|
|
|
|
|
# create the home dir with the proper user if doesn't exist, because it stores cookie file
|
|
|
|
[ -d $HOME ] || $EXEC_CMD "mkdir -p $HOME"
|
2007-10-17 04:33:19 +02:00
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# export global variables
|
|
|
|
export EJABBERD_CONFIG_PATH
|
2008-07-16 12:55:50 +02:00
|
|
|
export EJABBERD_MSGS_PATH
|
2008-01-13 23:46:00 +01:00
|
|
|
export EJABBERD_LOG_PATH
|
2008-07-16 12:55:50 +02:00
|
|
|
export EJABBERD_SO_PATH
|
|
|
|
export EJABBERD_BIN_PATH
|
2009-01-20 20:42:08 +01:00
|
|
|
export EJABBERD_DOC_PATH
|
2009-08-24 23:21:04 +02:00
|
|
|
export EJABBERD_PID_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
|
2008-07-13 00:02:16 +02:00
|
|
|
export EXEC_CMD
|
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
|
|
|
{
|
2008-07-13 00:02:16 +02:00
|
|
|
$EXEC_CMD "$ERL \
|
2008-01-01 11:53:05 +01:00
|
|
|
$NAME $ERLANG_NODE \
|
2007-05-21 05:41:13 +02:00
|
|
|
-noinput -detached \
|
2008-07-16 12:55:50 +02:00
|
|
|
-pa $EJABBERD_EBIN_PATH \
|
2008-07-13 21:10:01 +02:00
|
|
|
-mnesia dir \"\\\"$SPOOLDIR\\\"\" \
|
2007-05-21 05:41:13 +02:00
|
|
|
-s ejabberd \
|
2008-07-13 00:02:16 +02: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 "--------------------------------------------------------------------"
|
2009-12-11 20:42:59 +01:00
|
|
|
echo "To bypass permanently this warning, add to ejabberdctl.cfg the line:"
|
|
|
|
echo " EJABBERD_BYPASS_WARNINGS=true"
|
2007-11-26 08:59:35 +01:00
|
|
|
echo "Press any key to continue"
|
2009-12-11 20:42:59 +01:00
|
|
|
if [ "$EJABBERD_BYPASS_WARNINGS" != "true" ] ; then
|
|
|
|
read foo
|
|
|
|
fi
|
2007-10-17 04:33:19 +02:00
|
|
|
echo ""
|
2008-07-13 00:02:16 +02:00
|
|
|
$EXEC_CMD "$ERL \
|
2009-07-06 16:09:03 +02:00
|
|
|
$NAME debug-${ERLANG_NODE} \
|
2008-01-01 11:53:05 +01:00
|
|
|
-remsh $ERLANG_NODE \
|
2009-07-06 16:08:57 +02:00
|
|
|
-hidden \
|
2008-07-13 00:02:16 +02:00
|
|
|
$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 "--------------------------------------------------------------------"
|
2009-12-11 20:42:59 +01:00
|
|
|
echo "To bypass permanently this warning, add to ejabberdctl.cfg the line:"
|
|
|
|
echo " EJABBERD_BYPASS_WARNINGS=true"
|
2007-11-26 08:59:35 +01:00
|
|
|
echo "Press any key to continue"
|
2009-12-11 20:42:59 +01:00
|
|
|
if [ "$EJABBERD_BYPASS_WARNINGS" != "true" ] ; then
|
|
|
|
read foo
|
|
|
|
fi
|
2007-10-17 04:33:19 +02:00
|
|
|
echo ""
|
2008-07-13 00:02:16 +02:00
|
|
|
$EXEC_CMD "$ERL \
|
2008-01-01 11:53:05 +01:00
|
|
|
$NAME $ERLANG_NODE \
|
2008-07-16 12:55:50 +02:00
|
|
|
-pa $EJABBERD_EBIN_PATH \
|
2008-07-13 21:10:01 +02:00
|
|
|
-mnesia dir \"\\\"$SPOOLDIR\\\"\" \
|
2008-01-01 11:53:05 +01:00
|
|
|
-s ejabberd \
|
2008-07-13 00:02:16 +02:00
|
|
|
$ERLANG_OPTS $ARGS \"$@\""
|
2007-05-21 05:41:13 +02:00
|
|
|
}
|
|
|
|
|
2008-10-12 14:00:20 +02:00
|
|
|
help ()
|
|
|
|
{
|
|
|
|
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:"
|
2008-11-23 17:41:50 +01:00
|
|
|
echo " --config-dir dir Config ejabberd: $ETCDIR"
|
2008-10-12 14:00:20 +02:00
|
|
|
echo " --config file Config ejabberd: $EJABBERD_CONFIG_PATH"
|
|
|
|
echo " --ctl-config file Config ejabberdctl: $EJABBERDCTL_CONFIG_PATH"
|
|
|
|
echo " --logs dir Directory for logs: $LOGS_DIR"
|
|
|
|
echo " --spool dir Database spool dir: $SPOOLDIR"
|
|
|
|
echo " --node nodename ejabberd node name: $ERLANG_NODE"
|
|
|
|
echo ""
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2008-07-15 23:43:22 +02:00
|
|
|
COMMAND=$@
|
2008-07-13 00:02:16 +02:00
|
|
|
$EXEC_CMD "$ERL \
|
2009-07-06 16:09:03 +02:00
|
|
|
$NAME ctl-${ERLANG_NODE} \
|
2007-05-21 05:41:13 +02:00
|
|
|
-noinput \
|
2009-07-06 16:08:57 +02:00
|
|
|
-hidden \
|
2008-07-16 12:55:50 +02:00
|
|
|
-pa $EJABBERD_EBIN_PATH \
|
2008-07-15 23:43:22 +02:00
|
|
|
-s ejabberd_ctl -extra $ERLANG_NODE $COMMAND"
|
2008-01-01 11:53:05 +01:00
|
|
|
result=$?
|
|
|
|
case $result in
|
|
|
|
0) :;;
|
2008-10-12 14:00:20 +02:00
|
|
|
1) :;;
|
|
|
|
2) help;;
|
|
|
|
3) help;;
|
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
|
|
|
|
}
|
|
|
|
|
2009-08-24 21:43:52 +02:00
|
|
|
# stop epmd if there is no other running node
|
|
|
|
stop_epmd()
|
|
|
|
{
|
|
|
|
epmd -names | grep -q name || epmd -kill
|
|
|
|
}
|
|
|
|
|
|
|
|
# allow sync calls
|
|
|
|
wait_for_status()
|
|
|
|
{
|
|
|
|
# args: status try delay
|
|
|
|
# return: 0 OK, 1 KO
|
|
|
|
timeout=$2
|
|
|
|
status=4
|
|
|
|
while [ $status -ne $1 ]; do
|
|
|
|
sleep $3
|
|
|
|
let timeout=timeout-1
|
|
|
|
[ $timeout -eq 0 ] && {
|
|
|
|
status=$1
|
|
|
|
} || {
|
|
|
|
ctl status > /dev/null
|
|
|
|
status=$?
|
|
|
|
}
|
|
|
|
done
|
|
|
|
[ $timeout -eq 0 ] && {
|
|
|
|
status=1
|
|
|
|
} || {
|
|
|
|
status=0
|
|
|
|
}
|
|
|
|
return $status
|
|
|
|
}
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
case $ARGS in
|
|
|
|
' start') start;;
|
|
|
|
' debug') debug;;
|
|
|
|
' live') live;;
|
2009-08-24 21:43:52 +02:00
|
|
|
' started') wait_for_status 0 30 2;; # wait 30x2s before timeout
|
|
|
|
' stopped') wait_for_status 3 15 2; stop_epmd;; # wait 15x2s before timeout
|
2008-01-01 11:53:05 +01:00
|
|
|
*) ctl $ARGS;;
|
2007-05-21 05:41:13 +02:00
|
|
|
esac
|