From 11be36998796739f9e653a84639d625991658b7b Mon Sep 17 00:00:00 2001 From: Badlop Date: Mon, 24 Aug 2009 19:43:52 +0000 Subject: [PATCH] Added preliminary template file for ejabberd.init (thanks to Christophe Romain) SVN Revision: 2520 --- src/ejabberd.init.template | 46 ++++++++++++++++++++++++++++++++++++++ src/ejabberdctl.template | 33 +++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 src/ejabberd.init.template diff --git a/src/ejabberd.init.template b/src/ejabberd.init.template new file mode 100644 index 000000000..948e5c4d0 --- /dev/null +++ b/src/ejabberd.init.template @@ -0,0 +1,46 @@ +#! /bin/sh +set -o errexit +set -o nounset + +DIR=@@INSTALLDIR@@ +CTL="$DIR"/bin/ejabberdctl +USER=ejabberd + +test -d "$DIR" || { + echo "ERROR: ejabberd not found: $DIR" + exit 1 +} +grep ^"$USER": /etc/passwd >/dev/null || { + echo "ERROR: System user not found: $USER" + exit 2 +} + +export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" + +case "$1" in + start) + test -x "$CTL" || exit 0 + echo "Starting ejabberd..." + su - $USER -c "$CTL start" + su - $USER -c "$CTL started" + echo "done." + ;; + stop) + test -x "$CTL" || exit 0 + echo "Stopping ejabberd..." + su - $USER -c "$CTL stop" + su - $USER -c "$CTL stopped" + echo "done." + ;; + + force-reload|restart) + "$0" stop + "$0" start + ;; + + *) + echo "Usage: $0 {start|stop|restart|force-reload}" + exit 1 +esac + +exit 0 diff --git a/src/ejabberdctl.template b/src/ejabberdctl.template index eb85ce266..f6a30bb09 100644 --- a/src/ejabberdctl.template +++ b/src/ejabberdctl.template @@ -239,9 +239,42 @@ usage () exit } +# 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 +} + case $ARGS in ' start') start;; ' debug') debug;; ' live') live;; + ' 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