2014-06-20 14:33:48 +02:00
|
|
|
#!/bin/bash
|
2007-05-21 05:41:13 +02:00
|
|
|
|
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
|
2013-06-18 15:56:28 +02:00
|
|
|
FIREWALL_WINDOW=""
|
|
|
|
INET_DIST_INTERFACE="127.0.0.1"
|
|
|
|
ERLANG_NODE=ejabberd@localhost
|
2013-04-08 11:12:54 +02:00
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# define default environment variables
|
2013-06-18 15:56:28 +02:00
|
|
|
SCRIPT_DIR=`cd ${0%/*} && pwd`
|
2013-04-08 11:12:54 +02:00
|
|
|
ERL={{erl}}
|
|
|
|
INSTALLUSER={{installuser}}
|
2007-05-21 05:41:13 +02:00
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
# Compatibility in ZSH
|
|
|
|
#setopt shwordsplit 2>/dev/null
|
|
|
|
|
|
|
|
# check the proper system user is used if defined
|
|
|
|
if [ "$INSTALLUSER" != "" ] ; then
|
|
|
|
EXEC_CMD="false"
|
|
|
|
for GID in `id -G`; do
|
|
|
|
if [ $GID -eq 0 ] ; then
|
|
|
|
EXEC_CMD="su $INSTALLUSER -p -c"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ `id -g` -eq `id -g $INSTALLUSER` ] ; 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 4
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
EXEC_CMD="sh -c"
|
|
|
|
fi
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# parse command line parameters
|
2013-06-18 15:56:28 +02:00
|
|
|
ARGS=""
|
2008-01-01 11:53:05 +01:00
|
|
|
while [ $# -ne 0 ] ; do
|
|
|
|
PARAM=$1
|
|
|
|
shift
|
|
|
|
case $PARAM in
|
|
|
|
--) break ;;
|
2013-06-18 15:56:28 +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
|
2013-04-08 11:12:54 +02:00
|
|
|
ETCDIR={{sysconfdir}}/ejabberd
|
2008-11-23 17:41:50 +01:00
|
|
|
fi
|
2008-11-26 19:02:41 +01:00
|
|
|
if [ "$EJABBERDCTL_CONFIG_PATH" = "" ] ; then
|
|
|
|
EJABBERDCTL_CONFIG_PATH=$ETCDIR/ejabberdctl.cfg
|
|
|
|
fi
|
2013-06-18 15:56:28 +02:00
|
|
|
if [ -f "$EJABBERDCTL_CONFIG_PATH" ] ; then
|
|
|
|
. "$EJABBERDCTL_CONFIG_PATH"
|
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_CONFIG_PATH" = "" ] ; then
|
2013-08-12 14:25:05 +02:00
|
|
|
EJABBERD_CONFIG_PATH=$ETCDIR/ejabberd.yml
|
2013-06-18 15:56:28 +02:00
|
|
|
fi
|
2008-11-23 17:41:50 +01:00
|
|
|
if [ "$LOGS_DIR" = "" ] ; then
|
2013-04-08 11:12:54 +02:00
|
|
|
LOGS_DIR={{localstatedir}}/log/ejabberd
|
2008-11-23 17:41:50 +01:00
|
|
|
fi
|
|
|
|
if [ "$SPOOLDIR" = "" ] ; then
|
2013-04-08 11:12:54 +02:00
|
|
|
SPOOLDIR={{localstatedir}}/lib/ejabberd
|
2008-11-23 17:41:50 +01:00
|
|
|
fi
|
2009-01-20 20:42:08 +01:00
|
|
|
if [ "$EJABBERD_DOC_PATH" = "" ] ; then
|
2013-04-08 11:12:54 +02:00
|
|
|
EJABBERD_DOC_PATH={{docdir}}
|
2009-01-20 20:42:08 +01:00
|
|
|
fi
|
2009-05-16 00:08:00 +02:00
|
|
|
if [ "$ERLANG_NODE_ARG" != "" ] ; then
|
|
|
|
ERLANG_NODE=$ERLANG_NODE_ARG
|
2013-03-14 10:33:02 +01:00
|
|
|
NODE=${ERLANG_NODE%@*}
|
2009-05-16 00:08:00 +02:00
|
|
|
fi
|
2013-04-08 11:12:54 +02:00
|
|
|
if [ "{{release}}" != "true" ] ; then
|
|
|
|
if [ "$EJABBERDDIR" = "" ] ; then
|
2013-06-18 15:56:28 +02:00
|
|
|
EJABBERDDIR={{libdir}}/ejabberd
|
2013-04-08 11:12:54 +02:00
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_EBIN_PATH" = "" ] ; then
|
2013-06-18 15:56:28 +02:00
|
|
|
EJABBERD_EBIN_PATH=$EJABBERDDIR/ebin
|
2013-04-08 11:12:54 +02:00
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_PRIV_PATH" = "" ] ; then
|
2013-06-18 15:56:28 +02:00
|
|
|
EJABBERD_PRIV_PATH=$EJABBERDDIR/priv
|
2013-04-08 11:12:54 +02:00
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_BIN_PATH" = "" ] ; then
|
2013-06-18 15:56:28 +02:00
|
|
|
EJABBERD_BIN_PATH=$EJABBERD_PRIV_PATH/bin
|
2013-04-08 11:12:54 +02:00
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_SO_PATH" = "" ] ; then
|
2013-06-18 15:56:28 +02:00
|
|
|
EJABBERD_SO_PATH=$EJABBERD_PRIV_PATH/lib
|
2013-04-08 11:12:54 +02:00
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_MSGS_PATH" = "" ] ; then
|
2013-06-18 15:56:28 +02:00
|
|
|
EJABBERD_MSGS_PATH=$EJABBERD_PRIV_PATH/msgs
|
2013-04-08 11:12:54 +02:00
|
|
|
fi
|
2009-03-19 22:28:34 +01:00
|
|
|
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
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
# define erl parameters
|
|
|
|
ERLANG_OPTS="+K $POLL -smp $SMP +P $ERL_PROCESSES $ERL_OPTIONS"
|
|
|
|
KERNEL_OPTS=""
|
|
|
|
if [ "$FIREWALL_WINDOW" != "" ] ; then
|
|
|
|
KERNEL_OPTS="${KERNEL_OPTS} -kernel inet_dist_listen_min ${FIREWALL_WINDOW%-*} inet_dist_listen_max ${FIREWALL_WINDOW#*-}"
|
|
|
|
fi
|
|
|
|
if [ "$INET_DIST_INTERFACE" != "" ] ; then
|
2013-06-18 19:35:55 +02:00
|
|
|
INET_DIST_INTERFACE2="$(echo $INET_DIST_INTERFACE | sed 's/\./,/g')"
|
|
|
|
if [ "$INET_DIST_INTERFACE" != "$INET_DIST_INTERFACE2" ] ; then
|
2013-06-19 17:28:05 +02:00
|
|
|
INET_DIST_INTERFACE2="{$INET_DIST_INTERFACE2}"
|
2013-06-18 19:35:55 +02:00
|
|
|
fi
|
2013-06-19 17:28:05 +02:00
|
|
|
KERNEL_OPTS="${KERNEL_OPTS} -kernel inet_dist_use_interface \"${INET_DIST_INTERFACE2}\""
|
2013-06-18 15:56:28 +02:00
|
|
|
fi
|
|
|
|
if [ "$ERLANG_NODE" = "${ERLANG_NODE%.*}" ] ; then
|
|
|
|
NAME="-sname"
|
|
|
|
else
|
|
|
|
NAME="-name"
|
|
|
|
fi
|
2007-10-17 04:33:19 +02:00
|
|
|
|
2014-07-02 10:41:12 +02:00
|
|
|
# define ejabberd environment parameters
|
2014-07-20 13:24:28 +02:00
|
|
|
if [ "$EJABBERD_CONFIG_PATH" != "${EJABBERD_CONFIG_PATH%.yml}" ] ; then
|
2014-07-02 10:41:12 +02:00
|
|
|
rate=$(grep log_rate_limit $EJABBERD_CONFIG_PATH | cut -d':' -f2 | sed 's/ *//')
|
|
|
|
rotate=$(grep log_rotate_size $EJABBERD_CONFIG_PATH | cut -d':' -f2 | sed 's/ *//')
|
|
|
|
count=$(grep log_rotate_count $EJABBERD_CONFIG_PATH | cut -d':' -f2 | sed 's/ *//')
|
|
|
|
date=$(grep log_rotate_date $EJABBERD_CONFIG_PATH | cut -d':' -f2 | sed 's/ *//')
|
|
|
|
else
|
|
|
|
rate=$(grep log_rate_limit $EJABBERD_CONFIG_PATH | cut -d',' -f2 | sed 's/ *//;s/}\.//')
|
|
|
|
rotate=$(grep log_rotate_size $EJABBERD_CONFIG_PATH | cut -d',' -f2 | sed 's/ *//;s/}\.//')
|
|
|
|
count=$(grep log_rotate_count $EJABBERD_CONFIG_PATH | cut -d',' -f2 | sed 's/ *//;s/}\.//')
|
|
|
|
date=$(grep log_rotate_date $EJABBERD_CONFIG_PATH | cut -d',' -f2 | sed 's/ *//;s/}\.//')
|
|
|
|
fi
|
|
|
|
[ -z "$rate" ] || EJABBERD_OPTS="log_rate_limit $rate"
|
|
|
|
[ -z "$rotate" ] || EJABBERD_OPTS="${EJABBERD_OPTS} log_rotate_size $rotate"
|
|
|
|
[ -z "$count" ] || EJABBERD_OPTS="${EJABBERD_OPTS} log_rotate_count $count"
|
|
|
|
[ -z "$date" ] || EJABBERD_OPTS="${EJABBERD_OPTS} log_rotate_date '$date'"
|
|
|
|
[ -z "$EJABBERD_OPTS" ] || EJABBERD_OPTS="-ejabberd ${EJABBERD_OPTS}"
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
# create the ejabberd home dir with the proper user if doesn't exist
|
|
|
|
# then change to that directory readable by INSTALLUSER to
|
2010-03-18 12:57:21 +01:00
|
|
|
# prevent "File operation error: eacces." messages
|
2013-06-18 15:56:28 +02:00
|
|
|
[ -d $HOME ] || $EXEC_CMD "mkdir -p $HOME"
|
2010-03-18 12:57:21 +01:00
|
|
|
cd $HOME
|
|
|
|
|
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
|
2011-05-31 12:26:44 +02:00
|
|
|
export ERL_EPMD_ADDRESS
|
2008-01-13 23:46:00 +01:00
|
|
|
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
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# start server
|
2013-06-18 15:56:28 +02:00
|
|
|
start()
|
2007-05-21 05:41:13 +02:00
|
|
|
{
|
2013-06-18 15:56:28 +02:00
|
|
|
check_start
|
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\\\"\" \
|
2010-06-24 12:12:13 +02:00
|
|
|
$KERNEL_OPTS \
|
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
|
2013-06-18 15:56:28 +02:00
|
|
|
debug()
|
2007-05-21 05:41:13 +02:00
|
|
|
{
|
2009-12-11 20:42:59 +01:00
|
|
|
if [ "$EJABBERD_BYPASS_WARNINGS" != "true" ] ; then
|
2014-07-11 12:34:52 +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 successful."
|
|
|
|
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 "--------------------------------------------------------------------"
|
|
|
|
echo "To bypass permanently this warning, add to $EJABBERDCTL_CONFIG_PATH the line:"
|
|
|
|
echo " EJABBERD_BYPASS_WARNINGS=true"
|
|
|
|
echo "Press any key to continue"
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
read foo
|
2009-12-11 20:42:59 +01:00
|
|
|
fi
|
2007-10-17 04:33:19 +02:00
|
|
|
echo ""
|
2010-02-12 22:11:15 +01:00
|
|
|
TTY=`tty | sed -e 's/.*\///g'`
|
2008-07-13 00:02:16 +02:00
|
|
|
$EXEC_CMD "$ERL \
|
2010-02-12 20:50:56 +01:00
|
|
|
$NAME debug-${TTY}-${ERLANG_NODE} \
|
2008-01-01 11:53:05 +01:00
|
|
|
-remsh $ERLANG_NODE \
|
2009-07-06 16:08:57 +02:00
|
|
|
-hidden \
|
2010-06-24 12:12:13 +02:00
|
|
|
$KERNEL_OPTS \
|
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
|
2013-06-18 15:56:28 +02:00
|
|
|
live()
|
2007-10-17 04:33:19 +02:00
|
|
|
{
|
2013-06-18 15:56:28 +02:00
|
|
|
check_start
|
2009-12-11 20:42:59 +01:00
|
|
|
if [ "$EJABBERD_BYPASS_WARNINGS" != "true" ] ; then
|
2014-07-11 12:34:52 +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 "--------------------------------------------------------------------"
|
|
|
|
echo "To bypass permanently this warning, add to $EJABBERDCTL_CONFIG_PATH the line:"
|
|
|
|
echo " EJABBERD_BYPASS_WARNINGS=true"
|
|
|
|
echo "Press any key to continue"
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
read foo
|
2009-12-11 20:42:59 +01:00
|
|
|
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\\\"\" \
|
2010-06-24 12:12:13 +02:00
|
|
|
$KERNEL_OPTS \
|
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
|
|
|
}
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
etop()
|
|
|
|
{
|
|
|
|
$EXEC_CMD "$ERL \
|
|
|
|
$NAME debug-${TTY}-${ERLANG_NODE} \
|
|
|
|
-hidden -s etop -s erlang halt -output text -node $ERLANG_NODE"
|
|
|
|
}
|
|
|
|
|
|
|
|
help()
|
2008-10-12 14:00:20 +02:00
|
|
|
{
|
|
|
|
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
|
2013-06-18 15:56:28 +02:00
|
|
|
ctl()
|
2007-05-21 05:41:13 +02:00
|
|
|
{
|
2008-07-15 23:43:22 +02:00
|
|
|
COMMAND=$@
|
2010-01-24 14:39:15 +01:00
|
|
|
|
2010-02-12 20:25:31 +01:00
|
|
|
# Control number of connections identifiers
|
|
|
|
# using flock if available. Expects a linux-style
|
|
|
|
# flock that can lock a file descriptor.
|
|
|
|
MAXCONNID=100
|
2013-04-08 11:12:54 +02:00
|
|
|
CONNLOCKDIR={{localstatedir}}/lock/ejabberdctl
|
2010-02-12 20:25:31 +01:00
|
|
|
FLOCK='/usr/bin/flock'
|
2010-07-12 18:53:16 +02:00
|
|
|
if [ ! -x "$FLOCK" ] || [ ! -d "$CONNLOCKDIR" ] ; then
|
2013-06-18 15:56:28 +02:00
|
|
|
JOT='/usr/bin/jot'
|
|
|
|
if [ ! -x "$JOT" ] ; then
|
|
|
|
# no flock or jot, simply invoke ctlexec()
|
|
|
|
CTL_CONN="ctl-${ERLANG_NODE}"
|
|
|
|
ctlexec $CTL_CONN $COMMAND
|
|
|
|
result=$?
|
|
|
|
else
|
|
|
|
# no flock, but at least there is jot
|
|
|
|
RAND=`jot -r 1 0 $MAXCONNID`
|
|
|
|
CTL_CONN="ctl-${RAND}-${ERLANG_NODE}"
|
|
|
|
ctlexec $CTL_CONN $COMMAND
|
|
|
|
result=$?
|
|
|
|
fi
|
2010-01-24 14:39:15 +01:00
|
|
|
else
|
2013-06-18 15:56:28 +02:00
|
|
|
# we have flock so we get a lock
|
|
|
|
# on one of a limited number of
|
|
|
|
# conn names -- this allows
|
|
|
|
# concurrent invocations using a bound
|
|
|
|
# number of atoms
|
|
|
|
for N in `seq 1 $MAXCONNID`; do
|
|
|
|
CTL_CONN="ejabberdctl-$N"
|
|
|
|
CTL_LOCKFILE="$CONNLOCKDIR/$CTL_CONN"
|
|
|
|
(
|
|
|
|
exec 8>"$CTL_LOCKFILE"
|
|
|
|
if flock --nb 8; then
|
|
|
|
ctlexec $CTL_CONN $COMMAND
|
2010-01-24 14:39:15 +01:00
|
|
|
ssresult=$?
|
|
|
|
# segregate from possible flock exit(1)
|
2013-06-18 15:56:28 +02:00
|
|
|
ssresult=`expr $ssresult \* 10`
|
|
|
|
exit $ssresult
|
|
|
|
else
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-01-24 14:39:15 +01:00
|
|
|
)
|
2013-06-18 15:56:28 +02:00
|
|
|
result=$?
|
|
|
|
if [ $result -eq 1 ] ; then
|
2010-01-24 14:39:15 +01:00
|
|
|
# means we errored out in flock
|
|
|
|
# rather than in the exec - stay in the loop
|
|
|
|
# trying other conn names...
|
2013-06-18 15:56:28 +02:00
|
|
|
badlock=1
|
|
|
|
else
|
|
|
|
badlock=""
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
result=`expr $result / 10`
|
2010-01-24 14:39:15 +01:00
|
|
|
fi
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
if [ "$badlock" ] ;then
|
|
|
|
echo "Ran out of connections to try. Your ejabberd processes" >&2
|
|
|
|
echo "may be stuck or this is a very busy server. For very" >&2
|
|
|
|
echo "busy servers, consider raising MAXCONNID in ejabberdctl">&2
|
|
|
|
exit 1;
|
2010-01-24 14:39:15 +01:00
|
|
|
fi
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
case $result in
|
2013-06-18 15:56:28 +02:00
|
|
|
0) :;;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
ctlexec()
|
2010-01-24 14:39:15 +01:00
|
|
|
{
|
|
|
|
CONN_NAME=$1; shift
|
|
|
|
COMMAND=$@
|
2011-02-09 13:30:01 +01:00
|
|
|
$EXEC_CMD "$ERL \
|
2010-01-24 14:39:15 +01:00
|
|
|
$NAME ${CONN_NAME} \
|
|
|
|
-noinput \
|
|
|
|
-hidden \
|
|
|
|
-pa $EJABBERD_EBIN_PATH \
|
2010-06-24 12:12:13 +02:00
|
|
|
$KERNEL_OPTS \
|
2011-02-09 13:30:01 +01:00
|
|
|
-s ejabberd_ctl -extra $ERLANG_NODE $COMMAND"
|
2010-01-24 14:39:15 +01:00
|
|
|
}
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
# stop epmd if there is no other running node
|
|
|
|
stop_epmd()
|
2007-05-21 05:41:13 +02:00
|
|
|
{
|
2013-06-18 15:56:28 +02:00
|
|
|
epmd -names 2>/dev/null | grep -q name || epmd -kill >/dev/null
|
2007-05-21 05:41:13 +02:00
|
|
|
}
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
# make sure node not already running and node name unregistered
|
|
|
|
check_start()
|
2009-08-24 21:43:52 +02:00
|
|
|
{
|
2013-06-18 15:56:28 +02:00
|
|
|
epmd -names 2>/dev/null | grep -q " ${ERLANG_NODE%@*} " && {
|
|
|
|
ps ux | grep -v grep | grep -q " $ERLANG_NODE " && {
|
|
|
|
echo "ERROR: The ejabberd node '$ERLANG_NODE' is already running."
|
|
|
|
exit 4
|
|
|
|
} || {
|
|
|
|
ps ux | grep -v grep | grep -q beam && {
|
|
|
|
echo "ERROR: The ejabberd node '$ERLANG_NODE' is registered,"
|
|
|
|
echo " but no related beam process has been found."
|
|
|
|
echo "Shutdown all other erlang nodes, and call 'epmd -kill'."
|
|
|
|
exit 5
|
|
|
|
} || {
|
|
|
|
epmd -kill >/dev/null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-24 21:43:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# allow sync calls
|
|
|
|
wait_for_status()
|
|
|
|
{
|
|
|
|
# args: status try delay
|
|
|
|
# return: 0 OK, 1 KO
|
|
|
|
timeout=$2
|
|
|
|
status=4
|
2013-06-18 15:56:28 +02:00
|
|
|
while [ $status -ne $1 ] ; do
|
2009-08-24 21:43:52 +02:00
|
|
|
sleep $3
|
2013-06-18 15:56:28 +02:00
|
|
|
timeout=`expr $timeout - 1`
|
2009-08-24 21:43:52 +02:00
|
|
|
[ $timeout -eq 0 ] && {
|
|
|
|
status=$1
|
|
|
|
} || {
|
|
|
|
ctl status > /dev/null
|
|
|
|
status=$?
|
|
|
|
}
|
|
|
|
done
|
2013-06-18 15:56:28 +02:00
|
|
|
[ $timeout -eq 0 ] && return 1 || return 0
|
2012-06-08 17:33:21 +02:00
|
|
|
}
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
# main handler
|
2008-01-01 11:53:05 +01:00
|
|
|
case $ARGS in
|
|
|
|
' start') start;;
|
|
|
|
' debug') debug;;
|
|
|
|
' live') live;;
|
2013-06-18 15:56:28 +02:00
|
|
|
' etop') etop;;
|
2009-08-24 21:43:52 +02:00
|
|
|
' started') wait_for_status 0 30 2;; # wait 30x2s before timeout
|
2013-06-18 15:56:28 +02:00
|
|
|
' 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
|