diff options
Diffstat (limited to 'ejabberdctl.template')
-rwxr-xr-x | ejabberdctl.template | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/ejabberdctl.template b/ejabberdctl.template index 9099bd3dd..edf9bea0d 100755 --- a/ejabberdctl.template +++ b/ejabberdctl.template @@ -13,23 +13,30 @@ ERLANG_NODE=ejabberd@localhost ERL="{{erl}}" IEX="{{bindir}}/iex" EPMD="{{epmd}}" -INSTALLUSER={{installuser}} +INSTALLUSER="{{installuser}}" -# check the proper system user is used if defined -EXEC_CMD="false" -if [ -n "$INSTALLUSER" ] ; then - if [ $(id -g) -eq $(id -g $INSTALLUSER || echo -1) ] ; then +# check the proper system user is used +case `id -un` in + "$INSTALLUSER") EXEC_CMD="as_current_user" - else - id -Gn | grep -q wheel && EXEC_CMD="as_install_user" - fi -else - EXEC_CMD="as_current_user" -fi -if [ "$EXEC_CMD" = "false" ] ; then - echo "ERROR: This command can only be run by root or the user $INSTALLUSER" >&2 - exit 7 -fi + ;; + root) + if [ -n "$INSTALLUSER" ] ; then + EXEC_CMD="as_install_user" + else + EXEC_CMD="as_current_user" + echo "WARNING: This is not recommended to run ejabberd as root" >&2 + fi + ;; + *) + if [ -n "$INSTALLUSER" ] ; then + echo "ERROR: This command can only be run by root or the user $INSTALLUSER" >&2 + exit 7 + else + EXEC_CMD="as_current_user" + fi + ;; +esac # parse command line parameters for arg; do @@ -62,14 +69,14 @@ done # define erl parameters ERLANG_OPTS="+K $POLL -smp $SMP +P $ERL_PROCESSES $ERL_OPTIONS" if [ "$FIREWALL_WINDOW" != "" ] ; then - ERLANG_OPTS="$ERLANG_OPTS -kernel " \ - "inet_dist_listen_min ${FIREWALL_WINDOW%-*} " \ - "inet_dist_listen_max ${FIREWALL_WINDOW#*-}" + ERLANG_OPTS="$ERLANG_OPTS -kernel \ + inet_dist_listen_min ${FIREWALL_WINDOW%-*} \ + inet_dist_listen_max ${FIREWALL_WINDOW#*-}" fi if [ "$INET_DIST_INTERFACE" != "" ] ; then INET_DIST_INTERFACE2=$("$ERL" -noshell -eval 'case inet:parse_address("'$INET_DIST_INTERFACE'") of {ok,IP} -> io:format("~p",[IP]); _ -> ok end.' -s erlang halt) if [ "$INET_DIST_INTERFACE2" != "" ] ; then - ERLANG_OPTS="$ERLANG_OPTS -kernel inet_dist_use_interface \"$INET_DIST_INTERFACE2\"" + ERLANG_OPTS="$ERLANG_OPTS -kernel inet_dist_use_interface $INET_DIST_INTERFACE2" fi fi ERL_LIBS={{libdir}} @@ -103,7 +110,7 @@ export ERL_LIBS exec_cmd() { case $EXEC_CMD in - as_install_user) su -c '"$0" $@"' "$INSTALLUSER" -- "$@" ;; + as_install_user) su -c '"$0" "$@"' "$INSTALLUSER" -- "$@" ;; as_current_user) "$@" ;; esac } @@ -223,12 +230,6 @@ check_start() "$EPMD" -kill >/dev/null } } - } || { - [ -d "$SPOOL_DIR" ] || exec_cmd mkdir -p "$SPOOL_DIR" - cd "$SPOOL_DIR" || { - echo "ERROR: ejabberd can not access directory $SPOOL_DIR" - exit 6 - } } } @@ -253,6 +254,13 @@ wait_status() [ $timeout -gt 0 ] } +# ensure we can change current directory to SPOOL_DIR +[ -d "$SPOOL_DIR" ] || exec_cmd mkdir -p "$SPOOL_DIR" +cd "$SPOOL_DIR" || { + echo "ERROR: can not access directory $SPOOL_DIR" + exit 6 +} + # main case $1 in start) |