#!/bin/bash # Use chkconfig --add psm to set up the script to start and stop automatically. # P4Search Init Script. # chkconfig: 345 91 29 # description: Start P4Search Monitor for instance REPL_SDP_INSTANCE. ID=id declare OpMode=${1:-status} export ID=id [[ "${OS:-$(uname -s)}" = "SunOS" ]] && export ID=/usr/xpg4/bin/id if [[ `$ID -u` = 0 ]]; then source /p4/common/bin/p4_vars REPL_SDP_INSTANCE || exit 1 exec su - $OSUSER -c "$0 $OpMode" elif [[ "`$ID -u -n`" != $OSUSER ]]; then echo "$0 can only be run by root or $OSUSER" exit 1 fi # Load SDP shell environment for Instance REPL_SDP_INSTANCE. source /p4/common/bin/p4_vars REPL_SDP_INSTANCE || exit 1 export PSM_ROOT=${P4HOME}}/psm/ export RACK_ENV=production export THISSCRIPT=${0##*/} pid=0 GetPID() { pid=`ps ax | grep ruby | grep psm | grep -v grep | awk '{print $1;}'` } Status() { GetPID if [ "q$pid" = q ] ; then echo "psm is stopped" else echo "psm ($pid) is running" fi exit 0 } Start() { psm & exit $? } Stop() { GetPID kill $pid exit $? } Usage() { echo -e "\nUsage: $THISSCRIPT {start|stop}\n" exit 100 } if [ $# != 1 ] ; then Usage fi case $OpMode in reload) GetPID kill -HUP $pid opid=$pid GetPID if [ "q$pid" != q -a $pid = $opid ] ; then echo "psm reloaded" else echo "psm not running" fi ;; restart) Stop Start ;; start) Start ;; status) Status ;; stop) Stop ;; *) Usage ;; esac