#!/bin/sh
# Startup script for Jabberd2
# Written for debian packages by Sami Haahtinen
#
#  Because jabber components rely on jabberd to function properly and they
#  need to be restarted in case the main jabber server is restarted, we run
#  scripts in $COMPONENTPATH to start the components.

COMPONENTDPATH=/etc/jabberd2/component.d
PIDPATH=/var/run/jabberd2

test -d ${COMPONENTDPATH} || exit 0

set -e

case "$1" in
   start)
      echo -n "Starting Jabber Services:"
      if [ -z "$2" ]; then
         run-parts --arg=start ${COMPONENTDPATH}
      else
         ${COMPONENTDPATH}/??$2 start
      fi
      echo "."
	;;
   stop)
      echo -n "Stopping Jabber Services:"
      if [ -z "$2" ]; then
         run-parts --reverse --arg=stop ${COMPONENTDPATH}
      else
         ${COMPONENTDPATH}/??$2 stop
      fi
      echo "."
	;;
   restart|force-reload)
      echo "Restarting Jabber Services:"
      $0 stop $2
      sleep 1
      $0 start $2
   ;;
   *)
      # echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
      echo "Usage: $0 {action} [component]" >&2
      echo "   action = start|stop|restart|force-reload" >&2
      echo "   component = router|resolver|sm|s2s|c2s" >&2
      exit 1
   ;;
esac

exit 0
