Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/processone/ejabberd.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'ejabberdctl.template')
-rwxr-xr-xejabberdctl.template177
1 files changed, 95 insertions, 82 deletions
diff --git a/ejabberdctl.template b/ejabberdctl.template
index 33f8b0959..d585d66f7 100755
--- a/ejabberdctl.template
+++ b/ejabberdctl.template
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# define default configuration
POLL=true
@@ -42,19 +42,20 @@ else
fi
# parse command line parameters
-ARGS=""
+declare -a ARGS=()
while [ $# -ne 0 ] ; do
- PARAM=$1
+ PARAM="$1"
shift
case $PARAM in
--) break ;;
+ --no-timeout) EJABBERD_NO_TIMEOUT="--no-timeout" ;;
--node) ERLANG_NODE_ARG=$1 ; shift ;;
--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 ;;
- *) ARGS="$ARGS $PARAM" ;;
+ *) ARGS=("${ARGS[@]}" "$PARAM") ;;
esac
done
@@ -155,21 +156,30 @@ export ERL_INETRC
export ERL_MAX_PORTS
export ERL_MAX_ETS_TABLES
export CONTRIB_MODULES_PATH
+export CONTRIB_MODULES_CONF_DIR
export ERL_LIBS
+shell_escape()
+{
+ local RES=()
+ for i in "$@"; do
+ printf '%q ' "$i"
+ done
+}
+
# start server
start()
{
check_start
- $EXEC_CMD "$ERL \
- $NAME $ERLANG_NODE \
- -noinput -detached \
- -pa $EJABBERD_EBIN_PATH \
- $MNESIA_OPTS \
- $KERNEL_OPTS \
- $EJABBERD_OPTS \
- -s ejabberd \
- $ERLANG_OPTS $ARGS \"$@\""
+ 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"
}
# attach to server
@@ -177,12 +187,13 @@ debug()
{
debugwarning
TTY=`tty | sed -e 's/.*\///g'`
- $EXEC_CMD "$ERL \
- $NAME debug-${TTY}-${ERLANG_NODE} \
- -remsh $ERLANG_NODE \
- -hidden \
- $KERNEL_OPTS \
- $ERLANG_OPTS $ARGS \"$@\""
+ CMD="`shell_escape \"$ERL\" \"$NAME\" \"debug-${TTY}-${ERLANG_NODE}\"` \
+ -remsh $ERLANG_NODE \
+ -hidden \
+ $KERNEL_OPTS \
+ $ERLANG_OPTS \
+ `shell_escape \"${ARGS[@]}\" \"$@\"`"
+ $EXEC_CMD "$CMD"
}
# attach to server using Elixir
@@ -191,39 +202,57 @@ iexdebug()
debugwarning
TTY=`tty | sed -e 's/.*\///g'`
# Elixir shell is hidden as default
- $EXEC_CMD "$IEX \
- $IEXNAME debug-${TTY}-${ERLANG_NODE} \
- --remsh $ERLANG_NODE \
- --erl \"$KERNEL_OPTS\" \
- --erl \"$ERLANG_OPTS\" --erl \"$ARGS\" --erl \"$@\""
+ CMD="`shell_escape \"$IEX\" \"$IEXNAME\" \"debug-${TTY}-${ERLANG_NODE}\"` \
+ -remsh $ERLANG_NODE \
+ --erl \"`shell_escape \"$KERNEL_OPTS\"\" \
+ --erl \"`shell_escape \"$ERLANG_OPTS\"\" \
+ --erl \"`shell_escape \"${ARGS[@]}\"\" \
+ --erl \"`shell_escape \"$@\"\""
+ $EXEC_CMD "$CMD"
}
# start interactive server
live()
{
livewarning
- $EXEC_CMD "$ERL \
- $NAME $ERLANG_NODE \
- -pa $EJABBERD_EBIN_PATH \
- $MNESIA_OPTS \
- $KERNEL_OPTS \
- $EJABBERD_OPTS \
- -s ejabberd \
- $ERLANG_OPTS $ARGS \"$@\""
+ CMD="`shell_escape \"$ERL\" \"$NAME\" \"${ERLANG_NODE}\"` \
+ $MNESIA_OPTS \
+ $KERNEL_OPTS \
+ $EJABBERD_OPTS \
+ -s ejabberd \
+ $ERLANG_OPTS \
+ `shell_escape \"${ARGS[@]}\" \"$@\"`"
+ $EXEC_CMD "$CMD"
}
# start interactive server with Elixir
iexlive()
{
livewarning
- $EXEC_CMD "$IEX \
- $IEXNAME $ERLANG_NODE \
- -pa $EJABBERD_EBIN_PATH \
- --erl \"-mnesia dir \\\"$SPOOL_DIR\\\"\" \
- --erl \"$KERNEL_OPTS\" \
- --erl \"$EJABBERD_OPTS\" \
- --app ejabberd \
- --erl \"$ERLANG_OPTS\" --erl $ARGS --erl \"$@\""
+ CMD="`shell_escape \"$IEX\" \"$IEXNAME\" \"${ERLANG_NODE}\"` \
+ --erl \"-mnesia dir \\\"$SPOOL_DIR\\\"\" \
+ --erl \"`shell_escape \"$KERNEL_OPTS\"`\" \
+ --erl \"`shell_escape \"$EJABBERD_OPTS\"`\" \
+ --app ejabberd \
+ --erl \"`shell_escape \"$ERLANG_OPTS\"`\" \
+ --erl \"`shell_escape \"${ARGS[@]}\"`\" \
+ --erl \"`shell_escape \"$@\"`\""
+ $EXEC_CMD "$CMD"
+}
+
+# start server in the foreground
+foreground()
+{
+ check_start
+ CMD="`shell_escape \"$ERL\" \"$NAME\" \"$ERLANG_NODE\"` \
+ -noinput \
+ $MNESIA_OPTS \
+ $KERNEL_OPTS \
+ $EJABBERD_OPTS \
+ -s ejabberd \
+ $ERLANG_OPTS \
+ `shell_escape \"${ARGS[@]}\" \"$@\"`"
+ $EXEC_CMD "$CMD"
}
debugwarning()
@@ -288,7 +317,6 @@ ping()
$EXEC_CMD "$ERL \
$NAME ping-${TTY}-${ERLANG_NODE} \
-hidden \
- -pa $EJABBERD_EBIN_PATH \
$KERNEL_OPTS $ERLANG_OPTS \
-eval 'io:format(\"~p~n\",[net_adm:ping($1)])' \
-s erlang halt -output text -noinput"
@@ -298,11 +326,12 @@ 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 " 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 " 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)"
echo ""
echo "Optional parameters when starting an ejabberd node:"
echo " --config-dir dir Config ejabberd: $ETC_DIR"
@@ -317,8 +346,6 @@ help()
# common control function
ctl()
{
- COMMAND=$@
-
# Control number of connections identifiers
# using flock if available. Expects a linux-style
# flock that can lock a file descriptor.
@@ -330,13 +357,13 @@ ctl()
if [ ! -x "$JOT" ] ; then
# no flock or jot, simply invoke ctlexec()
CTL_CONN="ctl-${ERLANG_NODE}"
- ctlexec $CTL_CONN $COMMAND
+ ctlexec $CTL_CONN "$@"
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
+ ctlexec $CTL_CONN "$@"
result=$?
fi
else
@@ -351,7 +378,7 @@ ctl()
(
exec 8>"$CTL_LOCKFILE"
if flock --nb 8; then
- ctlexec $CTL_CONN $COMMAND
+ ctlexec $CTL_CONN "$@"
ssresult=$?
# segregate from possible flock exit(1)
ssresult=`expr $ssresult \* 10`
@@ -393,14 +420,11 @@ ctl()
ctlexec()
{
CONN_NAME=$1; shift
- COMMAND=$(echo $@ | sed 's/["&$;\|<>()]/\\&/g')
- $EXEC_CMD "$ERL \
- $NAME ${CONN_NAME} \
- -noinput \
- -hidden \
- -pa $EJABBERD_EBIN_PATH \
- $KERNEL_OPTS \
- -s ejabberd_ctl -extra $ERLANG_NODE $COMMAND"
+ CMD="`shell_escape \"$ERL\" \"$NAME\" \"$CONN_NAME\"` \
+ -noinput -hidden $KERNEL_OPTS -s ejabberd_ctl \
+ -extra `shell_escape \"$ERLANG_NODE\"` $EJABBERD_NO_TIMEOUT \
+ `shell_escape \"$@\"`"
+ $EXEC_CMD "$CMD"
}
# stop epmd if there is no other running node
@@ -429,16 +453,6 @@ check_start()
}
}
-# cluster setup
-join_cluster()
-{
- $EXEC_CMD "$EJABBERD_BIN_PATH/joincluster $*"
-}
-leave_cluster()
-{
- $EXEC_CMD "$EJABBERD_BIN_PATH/leavecluster $*"
-}
-
# allow sync calls
wait_for_status()
{
@@ -460,17 +474,16 @@ wait_for_status()
}
# main handler
-case $ARGS in
- ' start') start;;
- ' debug') debug;;
- ' iexdebug') iexdebug;;
- ' live') live;;
- ' iexlive') iexlive;;
- ' ping'*) ping ${ARGS# ping};;
- ' 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
- ' join_cluster'*) join_cluster ${ARGS# join_cluster};;
- ' leave_cluster'*) leave_cluster ${ARGS# leave_cluster};;
- *) ctl $ARGS;;
+case "${ARGS[0]}" in
+ 'start') start;;
+ 'debug') debug;;
+ 'iexdebug') iexdebug;;
+ 'live') live;;
+ 'iexlive') iexlive;;
+ 'foreground') foreground;;
+ 'ping'*) ping ${ARGS# ping};;
+ '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[@]}";;
esac