Start/stop script script

Download, Add a comment, Back to main page
# !/bin/sh
# chkconfig: 235 99 10
# description: Start or stop the Jabber server
#
### BEGIN INIT INFO
# Provides: Jabber
# Required-Start: $network $syslog
# Required-Stop: $network
# Default-Start: 2 3 5
# Default-Stop: 0 1 6
# Description: Start or stop the Jabber server
### END INIT INFO


# +------------------------------------
# | By JOP on 22 May 2003
# | Permit to Manage Jabber services
# +------------------------------------


# +------------------------------------
# | Variables
# +------------------------------------

jabber_home=/usr/jabber
janchor_home=$jabber_home/janchor-0.3.9
pidFile=$jabber_home/jabber.pid
path_errors_log=$jabber_home/error.log
path_records_log=$jabber_home/record.log
path_debug_log=$jabber_home/debug.log
path_jabber_xml=$jabber_home/jabber.xml

# +------------------------------------
# | Script
# +------------------------------------
# Must be jabberd

if [ "`/usr/bin/whoami`" != "jabberd" ]; then
       echo ""
       echo " Must be Jabberd user to use this script."
       echo ""
       exit 1
fi

# +------------------------------------
case "$1" in
   stop)
        echo ""
        echo " Stopping JABBER ..."
        echo ""
        killall -w jabberd
	if [ -f $pidFile ]
    	then
      		echo "jabberd.pid file exists, removing"
      		rm -f $pidFile
    	fi
   ;;
   start)
        echo ""
        echo " Starting JABBER ..."
        echo ""
	ps -axc | grep jabberd > /dev/null 2>&1
    	if [ "$?" -eq 0 ]
    	then
      		echo "jabberd is already running!"
      		exit 1
    	fi
       	if [ -f $pidFile ]
    	then
    		echo "jabberd.pid file exists, removing"
		rm -f $pidFile
    	fi
        $jabber_home/jabberd/jabberd -B >> /dev/null
   ;;
   debug)
        echo ""
        echo " Starting JABBER ..."
        echo ""
	ps -axc | grep jabberd > /dev/null 2>&1
    	if [ "$?" -eq 0 ]
    	then
      		echo "jabberd is already running!"
      		exit 1
    	fi
       	if [ -f $pidFile ]
    	then
    		echo "jabberd.pid file exists, removing"
		rm -f $pidFile
    	fi
        $jabber_home/jabberd/jabberd -B -D >> $path_debug_log
   ;;
   reload)
        echo "Reloading jabber.xml config"
        kill -HUP `/bin/cat $pidFile`
   ;;
   logs)
        clear
        echo "--------------------------------"
        echo "All records in $path_records_log"
        echo "--------------------------------"
        echo " "
        sleep 2
        more $path_records_log
   ;;
   errors)
        clear
        echo "--------------------------------"
        echo "Last 150 errors in $path_errors_log."
        echo "--------------------------------"
        echo " "
        sleep 2
        tail -n 150 $path_errors_log | more
   ;;
   status)
        echo ""
        echo " Status for Jabberd ..."
        echo ""
        ps -ef | grep '/jabberd'
        echo ""
   ;;
   xml)
        vi $path_jabber_xml
   ;;
   --help)
      echo "-------------------------------------"
      echo " Usage: $0 {start|stop|status|restart|reload|logs|errors|xml}"
      echo " "
      echo "  --help    Give you this page."
      echo "  start     Start application."
      echo "  stop      Stop application."
      echo "  status    Give status for application."
      echo "  reload    Reload settings in XML File."
      echo "  restart   Restart application."
      echo "  debug     Start application with debug "
      echo "  logs      Shows all records messages."
      echo "  errors    Shows last 150 error messages."
      echo "  xml       Edit your Jabber config file."
      echo "-------------------------------------"
      echo " "
      exit 1
      ;;
   restart)
        echo ""
        echo " Restarting Jabberd ..."
        $0 stop && $0 start
        echo ""
   ;;
   *)
# # +------------------------------------
   $0 --help
   exit 1
esac
exit 0