multi_rh9init script

Download, Add a comment, Back to main page
#!/bin/bash 
#
# chkconfig: - 97 97
# description: Starts and stops the Jabber Server
#
# Written by Todd Murray - wonderer@wonderer.net 09/09/2003
# Written for use on Redhat 9.0 
#
# Revised by Todd Murray - Todd.Murray@adidasus.com 05/28/2004
# Tested compatability for use with Redhat Enterprise Linux
#
# Revised by Todd Murray - Todd.Murray@adidasus.com 06/11/2004
# Added command seperators to make sure each start/stop function completes before executing the next
#
# Revised by Todd Murray - Todd.Murray@adidasus.com 04/12/2005
# Fixed the stop functions to ensure proper shutdown of each process
#
# Configuration directory - /usr/jabber/
# PID directory - /var/tmp/
# Log directory - /var/log/jabber/
# Spool directory - /var/spool/jabber/yourhosthere/

# Please note that i am storing my config files in /etc/jabber and
# that the pid is /var/lock/jabber/xxxx.pid  When you change this to meet
# your configuration make sure you adjust the pid values.  You will also
# need to make sure to specify the individual pids in each seperate config xml file.
#
# Note: You must make sure to include the <pidfile></pidfile> directive in each individual xmf config file
# Example of judconf.xml:
# <jabber>
# 
# <jabber>
#
#   <service id="judlinker">
#     <uplink/>
#     <connect>
#      <ip>127.0.0.1</ip>
#      <port>5231</port>
#      <secret>mysecret</secret>
#     </connect>
#   </service>
# 
#   <service id="users.myserver">
#     <host>users.myserver</host>
#     <load><jud>./jud/jud.so</jud></load>
#     <jud xmlns="jabber:config:jud">
#       <vCard>
#         <FN>User Directory on myserver</FN>
#         <DESC>This service provides a simple user directory service.</DESC>
#         <URL>http://myserver/</URL>
#       </vCard>
#     </jud>
#   </service>
# 
#   <pidfile>/var/run/jabber/jud.pid</pidfile>
# 
# </jabber>
#
#
# Make sure to adjust the following variables to match your configuration
# 
# Legend:
# JDIR = Jabber Directory - i.e /usr/local/jabber
# BIN = Jabberd Binary file - You should not need to change this unless you have put the binary 
# in a alternate location
# CONF = Jabber Directory containing the configuration files
#

# Variables
JDIR=/usr/local/jabber
BIN=$JDIR/jabberd/jabberd 
CONF=$JDIR
USER=root

# Source function library for Redhat 9.0 and Redhat Enterprise Linux
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi

# Avoid using root's TMPDIR
unset TMPDIR

# Check that main jabber xml config file exists.
[ -f $CONF/jabber.xml ] || exit 0

RETVAL=0

# The following can be used as a template for adding additional independant options.  Just copy the function
# with a new name and alter the echo, pid, and xml config file.
#

# Starts the main service using function library
startmain() {
	echo -n $"Starting the main jabberd service: "
	daemon sudo -u $USER $BIN -c $CONF/jabber.xml -B
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch /var/tmp/jabber.pid || RETVAL=1
	return $RETVAL
}

# Starts the mu-conferencing service
startconf() {
        echo -n $"Starting the jabberd conferencing services: "
        daemon sudo -u $USER $BIN -c $CONF/muc.xml -B 
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/tmp/mu-conf.pid || RETVAL=1
        return $RETVAL
}

# Starts the AIM Transport
startaimt() {
        echo -n $"Starting the jabberd AIM transport: "
        daemon sudo -u $USER $BIN -c $CONF/aim.xml -B
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/tmp/aimt.pid || RETVAL=1
        return $RETVAL
}

# Starts the MSN Transport
startmsnt() {
        echo -n $"Starting the jabberd MSN transport: "
        daemon sudo -u $USER $BIN -c $CONF/msnt.xml -B
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && touch /var/tmp/msnt.pid || RETVAL=1
        return $RETVAL
}

# Command to start them all
start() {

	startmain;
	startconf;
	startaimt;
	startmsnt
}

# The following can be used as a template for adding additional independant options.  Just copy the function 
# with a new name and alter the echo and pid files.
#
# Stops the main jabberd service
stopmain() {
	echo -n $"Stopping the main jabberd service: "
	read pid < /var/tmp/jabber.pid
	kill -TERM $pid >/dev/null 2>&1
	usleep 50000 
	if checkpid $pid && sleep 1 &&
	   checkpid $pid ; then
	     kill -KILL $pid >/dev/null 2>&1
	     usleep 50000
	fi
	RETVAL=$?
	[ $RETVAL=0 ] && echo_success; rm -f /var/tmp/jabber.pid || echo_failure
	echo
	return $RETVAL
}

# Stops the mu-conferencing service
stopconf() {
        echo -n $"Stopping the jabberd conferencing services: "
        read pid < /var/tmp/mu-conf.pid
	kill -TERM $pid >/dev/null 2>&1
        usleep 50000
        if checkpid $pid && sleep 1 &&
           checkpid $pid ; then
             kill -KILL $pid >/dev/null 2>&1
             usleep 50000
        fi
        RETVAL=$?
	[ $RETVAL=0 ] && echo_success; rm -f /var/tmp/mu-conf.pid || echo_failure
        echo
        return $RETVAL
}

# Stops the AIM Transport
stopaimt() {
        echo -n $"Stopping the jabberd AIM Transport: "
        read pid < /var/tmp/aimt.pid
	kill -TERM $pid >/dev/null 2>&1
        usleep 50000
        if checkpid $pid && sleep 1 &&
           checkpid $pid ; then
             kill -KILL $pid >/dev/null 2>&1
             usleep 50000
        fi
        RETVAL=$?
        [ $RETVAL=0 ] && echo_success; rm -f /var/tmp/aimt.pid || echo_failure
        echo
        return $RETVAL
}

# Stops the MSN Transport
stopmsnt() {
        echo -n $"Stopping the jabberd MSN Transport: "
        read pid < /var/tmp/msnt.pid
	kill -TERM $pid >/dev/null 2>&1
        usleep 50000
        if checkpid $pid && sleep 1 &&
           checkpid $pid ; then
             kill -KILL $pid >/dev/null 2>&1
             usleep 50000
        fi

        RETVAL=$?
        [ $RETVAL=0 ] && echo_success; rm -f /var/tmp/msnt.pid || echo_failure
        echo
        return $RETVAL
}

# Stops all the services
stop() {
	stopmsnt;
	stopaimt;
	stopconf;
	stopmain
}	

# Forces all jabberd processes to stop
forcestop() {
	echo -n $"Forcefully stopping all jabberd services: "
	killproc jabberd
	RETVAL=$?
	[ $RETVAL=0 ] && echo_success; rm -f /var/tmp/jabberd.pid /var/tmp/msnt.pid /var/tmp/aimt.pid /var/tmp/muc.pid || echo_failure
	echo
	return $RETVAL
}

restart() {
	echo "This feature is not yet implemented"
}	

# I am unsure if this does in fact work although it may work and end up reloading all of the config files
reload_old() {
      echo -n $"Reloading jabberd configuration files: "
	killproc jabberd -HUP
	RETVAL=$?
	echo
	return $RETVAL
}	

reload(){
	echo "This feature is not yet implemented"
}

rhstatus() {
	status jabberd
}	

# If you want to add additional independant services make sure you maintain the format and add in the names below
case "$1" in
  start)
  	start
	;;
  startmain)
        startmain
        ;;
  startconf)
        startconf
        ;;
  startaimt)
        startaimt
        ;;
  startmsnt)
	startmsnt
	;;
  stop)
  	stop
	;;
  stopmain)
	stopmain
	;;
  stopconf)
        stopconf
        ;;
  stopaimt)
	stopaimt
	;;
  stopmsnt)
	stopmsnt
	;;
  restart)
	restart
	;;
  reload)
  	reload
	;;
  status)
  	rhstatus
	;;
  condrestart)
  	[ -f /var/tmp/jabber.pid ] && restart || :
	;;
  forcestop)
	forcestop
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|reload|status|condrestart|forcestop}"
	echo ""
	echo "Additional Services: (startmain|startconf|startaimt|startmsnt|stopmain|stopconf|stopaimt|stopmsnt)"
	exit 1
esac

exit $?