jabber2 script

Download, Add a comment, Back to main page
#!/bin/bash
# This is a script to start/stop/and monitor jabber and added on components. It does stop the components and jabber server correctly. Dan Chesmore dchesmore@mcleodusa.com

cd /home/jabber
JABBERD_HOME=/usr/local/bin
JUD_HOME=/home/jabber/files/jud/users-agent-1.1
MUC_HOME=/usr/local/bin
AIM_HOME=/usr/local/var/jabber1.4.3/jabberd-1.4.3
LOG_HOME=/home/jabber/files/bandersnatch/bandersnatch
JABBER_LOG=/usr/local/var/jabberd/log/jabber.log
LOCK_HOME=/usr/local/var/jabberd/lock
PID_HOME=/usr/local/var/jabberd/pid

logmessage()
{
   echo `date "+%Y-%m-%d %H:%M:%S"` "- $1" >> $JABBER_LOG
}

checkIfRunning()
{
   if [ -f $LOCK_HOME/jabberd.lock -o -f $LOCK_HOME/jud.lock -o -f $LOCK_HOME/muc.lock -o -f $LOCK_HOME/aim.lock -o -f $LOCK_HOME/log.lock ]
   then
      echo "You must stop Jabber before starting"
      exit
   fi
}

jabberdStatus()
{
   count=`ps -ef | grep jabberd | grep -v grep | wc -l | awk '{print $1}'` 
   echo -n "Total Jabberd processes:" $count
   if [ ! $count -eq "0" ]
   then
      echo ", memory usage:" `ps -o vsz= Ovs -C jabberd | tail -n1`"K"
   else
      echo
   fi
}

judStatus()
{
   count=`ps -ef | grep users-agent | grep -v grep | wc -l | awk '{print $1}'`
   echo -n "Total JUD  processes:" $count
   if [ ! $count -eq "0" ]
   then
      echo ", memory usage:" `ps -o vsz= Ovs -C users-agent | tail -n1`"K"
   else
      echo
   fi
}

mucStatus()
{
   count=`ps -ef | grep mu-conference | grep -v grep | wc -l | awk '{print $1}'`
   echo -n "Total MUC processes:" $count
   if [ ! $count -eq "0" ]
   then
      echo ", memory usage:" `ps -o vsz= Ovs -C mu-conference | tail -n1`"K"
   else
      echo
   fi      
}

aimStatus()
{
   count=`ps -ef | grep aim | grep -v grep | wc -l | awk '{print $1}'`
   echo -n "Total AIM Processes:" $count
   if [ ! $count -eq "0" ]
   then
      echo ", memory usage:" `ps -o vsz= Ovs -C aim-transport | tail -n1`"K"
   else
      echo
   fi
}

logStatus()
{
   count=`ps -ef | grep bandersnatch | grep -v grep | wc -l | awk '{print $1}'`
   echo -n "Total Bandersnatch processes:" $count
   if [ ! $count -eq "0" ]
   then 
      echo ", memory usage:" `ps -o vsz= Ovs -C bandersnatch | tail -n1`"K"
   else
      echo
   fi
}

startJabberd()
{
   logmessage "Starting Jabberd"

   cd $JABBERD_HOME
   nohup jabberd >/dev/null 2>&1 &
   cat /dev/null>$LOCK_HOME/jabberd.lock
   sleep 5

   jabberdStatus
}

startJud()
{
   logmessage "Starting JUD"

   cd $JUD_HOME
   nohup users-agent config.xml >/dev/null 2>&1 &
   cat /dev/null>$LOCK_HOME/jud.lock
   sleep 4

   judStatus
}

startMuc()
{
   logmessage "Starting MUC"

   cd $MUC_HOME
   nohup mu-conference -c /etc/jabberd/muc-jcr.xml >/dev/null 2>&1 &
   cat /dev/null>$LOCK_HOME/muc.lock
   sleep 3

   mucStatus
}

startAim()
{
   logmessage "Starting AIM"

   cd $AIM_HOME
   nohup jabberd/jabberd -c aim-transport-stable-20040131/aim.xml >/dev/null 2>&1 &
   cat /dev/null>$LOCK_HOME/aim.lock
   sleep 2

   aimStatus
}

startLog()
{
   logmessage "Starting Bandersnatch"

   cd $LOG_HOME
   nohup perl bandersnatch2.pl config.xml >/dev/null 2>&1 &
   cat /dev/null>$LOCK_HOME/log.lock
   sleep 1

   logStatus
}

stopJabber()
{
   rm -f /usr/local/var/jabberd/lock/jabberd.lock
   rm -f /usr/local/var/jabberd/lock/jud.lock
   rm -f /usr/local/var/jabberd/lock/muc.lock
   rm -f /usr/local/var/jabberd/lock/aim.lock
   rm -f /usr/local/var/jabberd/lock/log.lock
  
   logmessage "Stopping Bandersnatch"
   kill `pgrep -f "perl bandersnatch2.pl config.xml"`

   logmessage "Stopping JUD"
   kill `pgrep -f "users-agent"`
   
   logmessage "Stopping MUC"
   kill `pgrep -f "mu-conference"`

   logmessage "Stopping AIM"
   kill `pgrep -f "aim"`
   
   logmessage "Stopping Jabberd"
   kill `pgrep -f "perl -w -x /usr/local/bin/jabberd"`

   logStatus
   judStatus
   mucStatus
   aimStatus
   jabberdStatus
}

monitorJabber()
{
   stop=0
   while [ $stop = 0 ]
   do
      sleep 5
      
      if [ 'ps -ef | grep router.xml | grep -v grep | wc -l' -eq "0" -a -f $LOCK_HOME/jabberd.lock ]
      then
         log message "Auto-restarting Jabberd system"
	 stopJabber
	 startJabberd
	 startJud
	 startMuc
	 startAim
	 startLog
      elif [ 'ps -ef | grep resolver.xml | grep -v grep | wc -l' -eq "0" -a -f $LOCK_HOME/jabberd.lock ]
      then
         log message "Auto-restarting Jabberd system"
	 stopJabber
	 startJabberd
	 startJud
	 startMuc
	 startAim
	 startLog
      elif [ 'ps -ef | grep sm.xml | grep -v grep | wc -l' -eq "0" -a -f $LOCK_HOME/jabberd.lock ]
      then
         log message "Auto-restarting Jabberd system"
	 stopJabber
	 startJabberd
	 startJud
	 startMuc
	 startAim
	 startLog
      elif [ 'ps -ef | grep c2s.xml | grep -v grep | wc -l' -eq "0" -a -f $LOCK_HOME/jabberd.lock ]
      then
         log message "Auto-restarting Jabberd system"
	 stopJabber
	 startJabberd
	 startJud
	 startMuc
	 startAim
	 startLog
      elif [ 'ps -ef | grep s2s.xml | grep -v grep | wc -l' -eq "0" -a -f $LOCK_HOME/jabberd.lock ]
      then
         log message "Auto-restarting Jabberd system"
	 stopJabber
	 startJabberd
	 startJud
	 startMuc
	 startAim
	 startLog
      elif [ 'ps -ef | grep users-agent | grep -v grep | wc -l' -eq "0" -a -f $LOCK_HOME/jud.lock ]
      then
         log message "Auto-restarting JUD"
	 rm -f $LOCK_HOME/jud.lock
	 startJud
      elif [ 'ps -ef | grep mu-conference | grep -v grep | wc -l' -eq "0" -a -f $LOCK_HOME/muc.lock ]
      then
         log message "Auto-restarting MUC"
	 rm -f $LOCK_HOME/muc.lock
	 startMuc
      elif [ 'ps -ef | grep aim | grep -v grep | wc -l' -eq "0" -a -f $LOCK_HOME/aim.lock ]
      then
         log message "Auto-restarting AIM"
	 rm -f $LOCK_HOME/aim.lock
	 startAim
      elif [ 'ps -ef | grep bandersnatch | grep -v grep | wc -l' -eq "0" -a -f $LOCK_HOME/log.lock
      then
         log message "Auto-restarting Bandersnatch"
	 rm -f $LOCK_HOME/log.lok
	 startLog
      elif [ ! -f $LOCK_HOME/jabberd.lock -a ! -f $LOCK_HOME/jud.lock -a ! -f $LOCK_HOME/muc.lock -a ! -f $LOCK_HOME/aim.lock -a ! -f $LOCK_HOME/log.lock ]
      then
         stop=1
      fi
      
   done
   exit
}

case "$1" in
   start)
      checkIfRunning
      startJabberd
      startJud
      startMuc
      startAim
      startLog
      ;;
   stop)
      stopJabber
      ;;
   status)
      judStatus
      jabberdStatus
      mucStatus
      aimStatus
      logStatus
      ;;
   restart)
      stopJabber
      sleep 5
      startJabberd
      startJud
      startMuc
      startAim
      startLog
      ;;
   *)
       echo "Usage: jabber {start|stop|restart|status}"
       exit 1
esac

exit 0