2016-01-04 12:13:18 +01: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=""
|
|
|
|
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}}
|
2015-01-29 18:43:47 +01:00
|
|
|
IEX={{bindir}}/iex
|
2015-03-18 22:26:06 +01:00
|
|
|
EPMD={{bindir}}/epmd
|
2013-04-08 11:12:54 +02:00
|
|
|
INSTALLUSER={{installuser}}
|
2015-10-15 15:08:45 +02:00
|
|
|
ERL_LIBS={{libdir}}
|
2007-05-21 05:41:13 +02:00
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
# 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
|
2014-07-24 15:25:28 +02:00
|
|
|
INSTALLUSER_HOME=$(getent passwd "$INSTALLUSER" | cut -d: -f6)
|
2014-07-27 11:21:55 +02:00
|
|
|
if [ -n "$INSTALLUSER_HOME" ] && [ ! -d "$INSTALLUSER_HOME" ] ; then
|
2014-07-24 17:16:47 +02:00
|
|
|
mkdir -p "$INSTALLUSER_HOME"
|
|
|
|
chown "$INSTALLUSER" "$INSTALLUSER_HOME"
|
|
|
|
fi
|
2014-07-27 11:21:55 +02:00
|
|
|
EXEC_CMD="su $INSTALLUSER -c"
|
2013-06-18 15:56:28 +02:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ `id -g` -eq `id -g $INSTALLUSER` ] ; then
|
2016-02-15 15:21:20 +01:00
|
|
|
EXEC_CMD="bash -c"
|
2013-06-18 15:56:28 +02:00
|
|
|
fi
|
|
|
|
if [ "$EXEC_CMD" = "false" ] ; then
|
|
|
|
echo "This command can only be run by root or the user $INSTALLUSER" >&2
|
|
|
|
exit 4
|
|
|
|
fi
|
|
|
|
else
|
2016-02-15 15:21:20 +01:00
|
|
|
EXEC_CMD="bash -c"
|
2013-06-18 15:56:28 +02:00
|
|
|
fi
|
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# parse command line parameters
|
2016-01-04 12:13:18 +01:00
|
|
|
declare -a ARGS=()
|
2008-01-01 11:53:05 +01:00
|
|
|
while [ $# -ne 0 ] ; do
|
2016-01-04 12:13:18 +01:00
|
|
|
PARAM="$1"
|
2008-01-01 11:53:05 +01:00
|
|
|
shift
|
|
|
|
case $PARAM in
|
|
|
|
--) break ;;
|
2015-12-08 11:25:26 +01:00
|
|
|
--no-timeout) EJABBERD_NO_TIMEOUT="--no-timeout" ;;
|
2013-06-18 15:56:28 +02:00
|
|
|
--node) ERLANG_NODE_ARG=$1 ; shift ;;
|
2014-07-21 15:25:16 +02:00
|
|
|
--config-dir) ETC_DIR="$1" ; shift ;;
|
|
|
|
--config) EJABBERD_CONFIG_PATH="$1" ; shift ;;
|
|
|
|
--ctl-config) EJABBERDCTL_CONFIG_PATH="$1" ; shift ;;
|
|
|
|
--logs) LOGS_DIR="$1" ; shift ;;
|
|
|
|
--spool) SPOOL_DIR="$1" ; shift ;;
|
2016-01-04 12:13:18 +01:00
|
|
|
*) ARGS=("${ARGS[@]}" "$PARAM") ;;
|
2008-01-01 11:53:05 +01:00
|
|
|
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
|
2014-07-21 15:25:16 +02:00
|
|
|
if [ "$ETC_DIR" = "" ] ; then
|
|
|
|
ETC_DIR={{sysconfdir}}/ejabberd
|
2008-11-23 17:41:50 +01:00
|
|
|
fi
|
2008-11-26 19:02:41 +01:00
|
|
|
if [ "$EJABBERDCTL_CONFIG_PATH" = "" ] ; then
|
2014-07-21 15:25:16 +02:00
|
|
|
EJABBERDCTL_CONFIG_PATH=$ETC_DIR/ejabberdctl.cfg
|
2008-11-26 19:02:41 +01:00
|
|
|
fi
|
2013-06-18 15:56:28 +02:00
|
|
|
if [ -f "$EJABBERDCTL_CONFIG_PATH" ] ; then
|
|
|
|
. "$EJABBERDCTL_CONFIG_PATH"
|
|
|
|
fi
|
|
|
|
if [ "$EJABBERD_CONFIG_PATH" = "" ] ; then
|
2014-07-21 15:25:16 +02:00
|
|
|
EJABBERD_CONFIG_PATH=$ETC_DIR/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
|
2014-07-21 15:25:16 +02:00
|
|
|
if [ "$SPOOL_DIR" = "" ] ; then
|
|
|
|
SPOOL_DIR={{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_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
|
2009-03-19 22:28:34 +01:00
|
|
|
fi
|
2008-07-16 12:55:50 +02:00
|
|
|
EJABBERD_LOG_PATH=$LOGS_DIR/ejabberd.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
|
2014-07-21 15:25:16 +02:00
|
|
|
ERL_INETRC=$ETC_DIR/inetrc
|
2008-07-13 21:10:01 +02:00
|
|
|
|
2015-04-27 17:25:07 +02:00
|
|
|
# define mnesia options
|
|
|
|
MNESIA_OPTS="-mnesia dir \"\\\"$SPOOL_DIR\\\"\" $MNESIA_OPTIONS"
|
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
|
2015-01-29 18:43:47 +01:00
|
|
|
IEXNAME="-$NAME"
|
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-21 15:25:16 +02:00
|
|
|
rate=$(sed '/^[ ]*log_rate_limit/!d;s/.*://;s/ *//' $EJABBERD_CONFIG_PATH)
|
|
|
|
rotate=$(sed '/^[ ]*log_rotate_size/!d;s/.*://;s/ *//' $EJABBERD_CONFIG_PATH)
|
|
|
|
count=$(sed '/^[ ]*log_rotate_count/!d;s/.*://;s/ *//' $EJABBERD_CONFIG_PATH)
|
2015-05-18 00:48:56 +02:00
|
|
|
date=$(sed '/^[ ]*log_rotate_date/!d;s/.*://;s/ *//' $EJABBERD_CONFIG_PATH)
|
2014-07-02 10:41:12 +02:00
|
|
|
else
|
2014-07-21 15:25:16 +02:00
|
|
|
rate=$(sed '/^[ ]*log_rate_limit/!d;s/.*,//;s/ *//;s/}\.//' $EJABBERD_CONFIG_PATH)
|
|
|
|
rotate=$(sed '/^[ ]*log_rotate_size/!d;s/.*,//;s/ *//;s/}\.//' $EJABBERD_CONFIG_PATH)
|
|
|
|
count=$(sed '/^[ ]*log_rotate_count/!d;s/.*,//;s/ *//;s/}\.//' $EJABBERD_CONFIG_PATH)
|
2015-05-18 00:48:56 +02:00
|
|
|
date=$(sed '/^[ ]*log_rotate_date/!d;s/.*,//;s/ *//;s/}\.//' $EJABBERD_CONFIG_PATH)
|
2014-07-02 10:41:12 +02:00
|
|
|
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"
|
2015-05-18 00:48:56 +02:00
|
|
|
[ -z "$date" ] || EJABBERD_OPTS="${EJABBERD_OPTS} log_rotate_date '$date'"
|
2014-07-02 10:41:12 +02:00
|
|
|
[ -z "$EJABBERD_OPTS" ] || EJABBERD_OPTS="-ejabberd ${EJABBERD_OPTS}"
|
|
|
|
|
2014-07-21 15:25:16 +02:00
|
|
|
[ -d $SPOOL_DIR ] || $EXEC_CMD "mkdir -p $SPOOL_DIR"
|
|
|
|
cd $SPOOL_DIR
|
2010-03-18 12:57:21 +01:00
|
|
|
|
2008-01-01 11:53:05 +01:00
|
|
|
# export global variables
|
|
|
|
export EJABBERD_CONFIG_PATH
|
2008-01-13 23:46:00 +01:00
|
|
|
export EJABBERD_LOG_PATH
|
2008-07-16 12:55:50 +02:00
|
|
|
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
|
2015-03-24 16:00:56 +01:00
|
|
|
export CONTRIB_MODULES_PATH
|
2015-10-26 22:42:07 +01:00
|
|
|
export CONTRIB_MODULES_CONF_DIR
|
2015-10-15 15:08:45 +02:00
|
|
|
export ERL_LIBS
|
2007-10-17 04:33:19 +02:00
|
|
|
|
2016-03-09 14:25:57 +01:00
|
|
|
shell_escape_str()
|
|
|
|
{
|
|
|
|
if test $# -eq 0; then
|
|
|
|
printf '"" '
|
|
|
|
else
|
|
|
|
shell_escape "$@"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-01-04 12:13:18 +01:00
|
|
|
shell_escape()
|
|
|
|
{
|
|
|
|
local RES=()
|
|
|
|
for i in "$@"; do
|
2016-02-12 23:37:48 +01:00
|
|
|
if test -z "$i"; then
|
|
|
|
printf '"" '
|
|
|
|
else
|
2016-02-15 15:21:20 +01:00
|
|
|
printf '%q ' "$i"
|
2016-02-12 23:37:48 +01:00
|
|
|
fi
|
2016-01-04 12:13:18 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
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
|
2016-01-04 12:13:18 +01:00
|
|
|
CMD="`shell_escape \"$ERL\" \"$NAME\" \"$ERLANG_NODE\"` \
|
|
|
|
-noinput -detached \
|
|
|
|
$MNESIA_OPTS \
|
|
|
|
$KERNEL_OPTS \
|
|
|
|
$EJABBERD_OPTS \
|
|
|
|
-s ejabberd \
|
|
|
|
$ERLANG_OPTS \
|
|
|
|
`shell_escape \"${ARGS[@]}\" \"$@\"`"
|
|
|
|
$EXEC_CMD "$CMD"
|
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()
|
2015-01-29 18:43:47 +01:00
|
|
|
{
|
|
|
|
debugwarning
|
2016-04-21 12:00:51 +02:00
|
|
|
NID=$(uid debug)
|
|
|
|
CMD="`shell_escape \"$ERL\" \"$NAME\" \"$NID\"` \
|
2016-01-04 12:13:18 +01:00
|
|
|
-remsh $ERLANG_NODE \
|
|
|
|
-hidden \
|
|
|
|
$KERNEL_OPTS \
|
|
|
|
$ERLANG_OPTS \
|
|
|
|
`shell_escape \"${ARGS[@]}\" \"$@\"`"
|
|
|
|
$EXEC_CMD "$CMD"
|
2015-01-29 18:43:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# attach to server using Elixir
|
|
|
|
iexdebug()
|
|
|
|
{
|
|
|
|
debugwarning
|
|
|
|
# Elixir shell is hidden as default
|
2016-04-21 12:00:51 +02:00
|
|
|
NID=$(uid debug)
|
|
|
|
CMD="`shell_escape \"$IEX\" \"$IEXNAME\" \"$NID\"` \
|
2016-01-04 12:13:18 +01:00
|
|
|
-remsh $ERLANG_NODE \
|
2016-03-09 14:25:57 +01:00
|
|
|
--erl `shell_escape \"$KERNEL_OPTS\"` \
|
|
|
|
--erl `shell_escape \"$ERLANG_OPTS\"` \
|
|
|
|
--erl `shell_escape \"${ARGS[@]}\"` \
|
|
|
|
--erl `shell_escape_str \"$@\"`"
|
2016-01-04 12:13:18 +01:00
|
|
|
$EXEC_CMD "$CMD"
|
2015-01-29 18:43:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# start interactive server
|
|
|
|
live()
|
|
|
|
{
|
|
|
|
livewarning
|
2016-01-04 12:13:18 +01:00
|
|
|
CMD="`shell_escape \"$ERL\" \"$NAME\" \"${ERLANG_NODE}\"` \
|
|
|
|
$MNESIA_OPTS \
|
|
|
|
$KERNEL_OPTS \
|
|
|
|
$EJABBERD_OPTS \
|
|
|
|
-s ejabberd \
|
|
|
|
$ERLANG_OPTS \
|
|
|
|
`shell_escape \"${ARGS[@]}\" \"$@\"`"
|
|
|
|
$EXEC_CMD "$CMD"
|
2015-01-29 18:43:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# start interactive server with Elixir
|
|
|
|
iexlive()
|
|
|
|
{
|
|
|
|
livewarning
|
2016-03-09 14:25:57 +01:00
|
|
|
echo $@
|
2016-01-04 12:13:18 +01:00
|
|
|
CMD="`shell_escape \"$IEX\" \"$IEXNAME\" \"${ERLANG_NODE}\"` \
|
|
|
|
--erl \"-mnesia dir \\\"$SPOOL_DIR\\\"\" \
|
|
|
|
--erl \"`shell_escape \"$KERNEL_OPTS\"`\" \
|
|
|
|
--erl \"`shell_escape \"$EJABBERD_OPTS\"`\" \
|
|
|
|
--app ejabberd \
|
2016-03-09 14:25:57 +01:00
|
|
|
--erl `shell_escape \"$ERLANG_OPTS\"` \
|
|
|
|
--erl `shell_escape \"${ARGS[@]}\"` \
|
|
|
|
--erl `shell_escape_str \"$@\"`"
|
2016-01-04 12:13:18 +01:00
|
|
|
$EXEC_CMD "$CMD"
|
2015-01-29 18:43:47 +01:00
|
|
|
}
|
|
|
|
|
2015-10-29 19:39:21 +01:00
|
|
|
# start server in the foreground
|
|
|
|
foreground()
|
|
|
|
{
|
|
|
|
check_start
|
2016-01-04 12:13:18 +01:00
|
|
|
CMD="`shell_escape \"$ERL\" \"$NAME\" \"$ERLANG_NODE\"` \
|
|
|
|
-noinput \
|
|
|
|
$MNESIA_OPTS \
|
|
|
|
$KERNEL_OPTS \
|
|
|
|
$EJABBERD_OPTS \
|
|
|
|
-s ejabberd \
|
|
|
|
$ERLANG_OPTS \
|
|
|
|
`shell_escape \"${ARGS[@]}\" \"$@\"`"
|
|
|
|
$EXEC_CMD "$CMD"
|
2015-10-29 19:39:21 +01:00
|
|
|
}
|
|
|
|
|
2015-01-29 18:43:47 +01:00
|
|
|
debugwarning()
|
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 "--------------------------------------------------------------------"
|
2014-07-21 15:25:16 +02:00
|
|
|
echo "To bypass permanently this warning, add to ejabberdctl.cfg the line:"
|
2014-07-11 12:34:52 +02:00
|
|
|
echo " EJABBERD_BYPASS_WARNINGS=true"
|
2015-01-29 18:43:47 +01:00
|
|
|
echo "Press return to continue"
|
2013-06-18 15:56:28 +02:00
|
|
|
read foo
|
2014-07-21 15:25:16 +02:00
|
|
|
echo ""
|
2015-05-22 17:28:40 +02:00
|
|
|
fi
|
2007-10-17 04:33:19 +02:00
|
|
|
}
|
|
|
|
|
2015-01-29 18:43:47 +01:00
|
|
|
livewarning()
|
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 "--------------------------------------------------------------------"
|
2014-07-21 15:25:16 +02:00
|
|
|
echo "To bypass permanently this warning, add to ejabberdctl.cfg the line:"
|
2014-07-11 12:34:52 +02:00
|
|
|
echo " EJABBERD_BYPASS_WARNINGS=true"
|
2015-01-29 18:43:47 +01:00
|
|
|
echo "Press return to continue"
|
2013-06-18 15:56:28 +02:00
|
|
|
read foo
|
2014-07-21 15:25:16 +02:00
|
|
|
echo ""
|
2009-12-11 20:42:59 +01:00
|
|
|
fi
|
2013-06-18 15:56:28 +02:00
|
|
|
}
|
|
|
|
|
2015-05-22 17:28:40 +02:00
|
|
|
etop()
|
|
|
|
{
|
2016-04-21 12:00:51 +02:00
|
|
|
NID=$(uid top)
|
2015-05-22 17:28:40 +02:00
|
|
|
$EXEC_CMD "$ERL \
|
2016-04-21 12:00:51 +02:00
|
|
|
$NAME $NID \
|
2015-05-22 17:28:40 +02:00
|
|
|
-hidden -s etop -s erlang halt -output text -node $ERLANG_NODE"
|
|
|
|
}
|
|
|
|
|
|
|
|
ping()
|
|
|
|
{
|
2016-04-21 12:16:21 +02:00
|
|
|
[ -z "$1" ] && PEER=${ERLANG_NODE} || PEER=$1
|
|
|
|
if [ "$PEER" = "${PEER%.*}" ] ; then
|
2016-03-18 11:08:30 +01:00
|
|
|
PING_NAME="-sname"
|
|
|
|
PING_NODE=$(hostname -s)
|
|
|
|
else
|
|
|
|
PING_NAME="-name"
|
|
|
|
PING_NODE=$(hostname)
|
|
|
|
fi
|
2016-04-21 12:00:51 +02:00
|
|
|
NID=$(uid ping ${PING_NODE})
|
2015-05-22 17:28:40 +02:00
|
|
|
$EXEC_CMD "$ERL \
|
2016-04-21 12:00:51 +02:00
|
|
|
$PING_NAME $NID \
|
|
|
|
-hidden $KERNEL_OPTS $ERLANG_OPTS \
|
2016-04-21 12:16:21 +02:00
|
|
|
-eval 'io:format(\"~p~n\",[net_adm:ping('\"'\"'$PEER'\"'\"')])' \
|
2015-05-22 17:28:40 +02:00
|
|
|
-s erlang halt -output text -noinput"
|
|
|
|
}
|
|
|
|
|
2013-06-18 15:56:28 +02:00
|
|
|
help()
|
2008-10-12 14:00:20 +02:00
|
|
|
{
|
|
|
|
echo ""
|
|
|
|
echo "Commands to start an ejabberd node:"
|
2015-10-29 19:39:21 +01:00
|
|
|
echo " start Start an ejabberd node in server mode"
|
|
|
|
echo " debug Attach an interactive Erlang shell to a running ejabberd node"
|
|
|
|
echo " iexdebug Attach an interactive Elixir shell to a running ejabberd node"
|
|
|
|
echo " live Start an ejabberd node in live (interactive) mode"
|
|
|
|
echo " iexlive Start an ejabberd node in live (interactive) mode, within an Elixir shell"
|
|
|
|
echo " foreground Start an ejabberd node in server mode (attached)"
|
2008-10-12 14:00:20 +02:00
|
|
|
echo ""
|
|
|
|
echo "Optional parameters when starting an ejabberd node:"
|
2014-07-21 15:25:16 +02:00
|
|
|
echo " --config-dir dir Config ejabberd: $ETC_DIR"
|
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"
|
2014-07-21 15:25:16 +02:00
|
|
|
echo " --spool dir Database spool dir: $SPOOL_DIR"
|
2008-10-12 14:00:20 +02:00
|
|
|
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
|
|
|
{
|
2016-04-21 12:00:51 +02:00
|
|
|
NID=$(uid ctl)
|
|
|
|
CMD="`shell_escape \"$ERL\" \"$NAME\" \"$NID\"` \
|
|
|
|
-noinput -hidden $KERNEL_OPTS -s ejabberd_ctl \
|
|
|
|
-extra `shell_escape \"$ERLANG_NODE\"` $EJABBERD_NO_TIMEOUT \
|
|
|
|
`shell_escape \"$@\"`"
|
|
|
|
$EXEC_CMD "$CMD"
|
|
|
|
result=$?
|
2008-01-01 11:53:05 +01:00
|
|
|
case $result in
|
2013-06-18 15:56:28 +02:00
|
|
|
2) help;;
|
|
|
|
3) help;;
|
2016-04-21 12:00:51 +02:00
|
|
|
*) :;;
|
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
|
|
|
}
|
|
|
|
|
2016-04-21 12:00:51 +02:00
|
|
|
uid()
|
2010-01-24 14:39:15 +01:00
|
|
|
{
|
2016-04-21 12:00:51 +02:00
|
|
|
uuid=$(uuidgen 2>/dev/null)
|
|
|
|
[ -z "$uuid" -a -f /proc/sys/kernel/random/uuid ] && uuid=$(</proc/sys/kernel/random/uuid)
|
|
|
|
[ -z "$uuid" ] && uuid=$(printf "%X" $RANDOM$(date +%M%S)$$)
|
|
|
|
uuid=${uuid%%-*}
|
|
|
|
[ $# -eq 0 ] && echo ${uuid}-${ERLANG_NODE}
|
|
|
|
[ $# -eq 1 ] && echo ${uuid}-${1}-${ERLANG_NODE}
|
|
|
|
[ $# -eq 2 ] && echo ${uuid}-${1}@${2}
|
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
|
|
|
{
|
2015-05-22 10:40:24 +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
|
|
|
{
|
2015-03-18 22:26:06 +01:00
|
|
|
$EPMD -names 2>/dev/null | grep -q " ${ERLANG_NODE%@*} " && {
|
2013-06-18 15:56:28 +02:00
|
|
|
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
|
|
|
|
} || {
|
2015-03-18 22:26:06 +01:00
|
|
|
$EPMD -kill >/dev/null
|
2013-06-18 15:56:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
2016-01-04 12:13:18 +01:00
|
|
|
case "${ARGS[0]}" in
|
|
|
|
'start') start;;
|
|
|
|
'debug') debug;;
|
|
|
|
'iexdebug') iexdebug;;
|
|
|
|
'live') live;;
|
|
|
|
'iexlive') iexlive;;
|
|
|
|
'foreground') foreground;;
|
2016-04-21 12:16:21 +02:00
|
|
|
'ping'*) ping ${ARGS[1]};;
|
2016-01-04 12:13:18 +01:00
|
|
|
'etop') etop;;
|
|
|
|
'started') wait_for_status 0 30 2;; # wait 30x2s before timeout
|
|
|
|
'stopped') wait_for_status 3 15 2 && stop_epmd;; # wait 15x2s before timeout
|
|
|
|
*) ctl "${ARGS[@]}";;
|
2007-05-21 05:41:13 +02:00
|
|
|
esac
|