[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Handle-info] Scripts and source for handle start/stop and backup [SEC=UNCLASSIFIED]



Hi,

I have attached an updated version of the handle start/stop script that
ensures start and stop operations are completed (i.e. not still in
progress) when the script exits -- it cures subtle timing issues for the
backup script on very busy systems.

Cheers,

-- 
Phil

I know why the sun never sets on the British Empire: God wouldn't trust
an Englishman in the dark.
	-- Duncan Spaeth, Princeton professor


------
If you have received this transmission in error please notify us immediately by return e-mail and delete all copies. If this e-mail or any attachments have been sent to you in error, that error does not constitute waiver of any confidentiality, privilege or copyright in respect of information in the e-mail or attachments. 



Please consider the environment before printing this email.

------

#!/bin/bash 
#
# $Id: handle,v 1.5 2010/09/30 00:15:17 A04072 Exp A04072 $
#
# /etc/rc.d/init.d/handle
#
# Red Hat EL start/stop script for the handle server.
#
# Author: Phil Chadwick
#
# chkconfig: 345 99 15 
# description: start/stop script for the handle server
#
# I recommend that you run the handle server under a reserved userid
# defined as HANDLEUSER below.  The default is "swhandle" (which should
# own SVRDIR and contents).
#
# Leave HANDLEUSER undefined or blank string to run handle as root.
#
# Set "BREAKLOCK=yes" to smash the lockfile on restart.  Default is "no",
# because I think it's better to require human investigation if the daemon
# fails to start because a lock is set...
#
# Only tested on RHEL.

#PATH=/bin:/usr/bin:/usr/ucb
PATH=/bin:/usr/bin
export PATH

DESC="handle"
MAIN=net.handle.server.Main
#HDLDIR=/hs
#HDLDIR=/data00/sw/handle/hdl6.2.5_02
HDLDIR=/data00/sw/handle/current
BINDIR=$HDLDIR/bin
SVRDIR=$HDLDIR/svr_1
LOCKFILE=$SVRDIR/txns/lock
BREAKLOCK=no
HANDLEUSER=swhandle

#JAVA_HOME=/usr/lib/jvm/jre
JAVA_HOME=/usr/java/jdk1.6.0_04/jre     
export JAVA_HOME
JAVA=$JAVA_HOME/bin/java
export JAVA
CLASSPATH=$BINDIR/handle.jar
export CLASSPATH
PATH=$JAVA_HOME/bin:$PATH
export PATH

# How to become leader of a new process group, with a new session ID, and no
# controlling tty.  Use setsid(8) for Linux, daemon(8) for FreeBSD, and 
# "daemonise" (source code required) for System V variants, e.g. Solaris.
# This prevents our daemon from getting signals sent to it's inherited
# process group (usually associated, at system boot, with /dev/console).
# When invoked, you should be in "safe" working directory and all three
# file descriptors should be redirected away from a tty.
#DAEMON=daemonise
DAEMON=setsid

# Source function library for RHEL failure() -- not needed otherwise
. /etc/init.d/functions

getpid()
{
    ps -e -o pid,cmd | grep "$1" | \
	sed -e '/ grep /d' -e 's/^ *//' -e 's/ .*//' -e 1q
}

start()
{
    echo -n "Starting $DESC: "
    pid=`getpid "$JAVA $MAIN $SVRDIR"`
    if [ ! -z "$pid" ]
    then
        echo -n $"cannot start $DESC: $DESC is already running (pid $pid)."
        failure $"cannot start $DESC: $DESC is already running (pid $pid)."
	echo
	return 1
    else
	cd $SVRDIR			# daemon's working directory
	[ "$BREAKLOCK" = "yes" ] && rm -f $LOCKFILE 
	ulimit -S -c 0 >/dev/null 2>&1	# no core dumps
	echo "`date \"+%Y-%m-%d %H:%M:%S %Z\"`.  $DESC starting." >>server.log
	runserver="$DAEMON $JAVA $MAIN $SVRDIR 0</dev/null 1>>server.log 2>&1 &"
	[ -n "$HANDLEUSER" -a "`whoami`" = "root" ] &&
	    runserver="su $HANDLEUSER -m -c \"$runserver\""
	eval $runserver			# care: exit status may be for su
	echo
	rhstatus 120 >/dev/null 2>&1    # wait for start so status reports OK
	return $?
    fi
}

stop()
{
    retval=1
    echo -n "Stopping $DESC: "
    pid=`getpid "$JAVA $MAIN $SVRDIR"`
    if [ ! -z "$pid" ]
    then
	kill $pid
	retval=$?
	if [ $retval -eq 0 ]
	then
	    # Wait for it to shut down, so status reports OK
	    for n in 1 1 1 1 2 4 8 16 32 64
	    do
		sleep $n
		kill -s 0 $pid 2>/dev/null || break
	    done
	fi
    else
        echo -n $"cannot stop $DESC: $DESC is not running."
        failure $"cannot stop $DESC: $DESC is not running."
    fi
    echo
    return $retval
}

restart()
{
    stop
    start
}

rhstatus()
{
    # The server is started in the background, and on a
    # very busy system we may want to wait for it to fire up.
    # First argument is max retries with 1 second wait (default 0).
    retries=${1:-0}
    while :
    do
        pid=`getpid "$JAVA $MAIN $SVRDIR"`
        if [ ! -z "$pid" ]
        then
            echo "$DESC (pid $pid) is running..."
            return 0
        fi
        [ $retries -le 0 ] && break
        retries=`expr $retries - 1`
        sleep 1
    done
    echo "$DESC is not running..."
    return 1
}

case "$1" in
    start)
        start
	;;
    stop)
        stop
	;;
    restart|reload)
	restart
	;;
    status)
	rhstatus
	;;
    *)
	echo "Usage: $0 {start|stop|restart|reload|status}"
	exit 1
    ;;
esac
exit $?