jigsaw.server unix startup/shutdown script V1.15...

Hi !

----

Long long ago there was an unix-startup/shutdown script...

... and here comes an update for it :-)

The script is configured for Solaris 7 but should work on Solaris >=
2.5.1 and Linux, too.
The script requires some modifications (admin user+password for
"jigkill", CLASSPATH and path to server config) to run on your site.

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) Roland.Mainz@informatik.med.uni-giessen.de
  \__\/\/__/  gisburn@informatik.med.uni-giessen.de
  /O /==\ O\  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
 (;O/ \/ \O;) TEL +49 641 99-13193 FAX +49 641 99-41359
#!/bin/sh
#
# Copyright (c) 1999/2000 by Roland Mainz (Roland.Mainz@informatik.med.uni-giessen.de)
# All rights reserved.
# /etc/init.d/jigsaw.server
# /etc/rc3.d/S10jigsaw.server (hard link to /etc/init.d/jigsaw.server)
# /etc/rc0.d/K39jigsaw.server (hard link to /etc/init.d/jigsaw.server)
#
#pragma ident	"@(#)jigsaw.server	1.15	2000/03/03 IMI"
#
#######################################################
# version history
# V1.15 (05.09.2000): - Fixed various flaws in function handling for Solaris /sbin/sh
#                     - Added extra "sleep" after sending SIGTERM to give signal handler in jigsaw more time
#                     - Increased limit of max. open files per process to 1000
# V1.14 (03.03.2000): - Now uses test -d /proc/<pid> to test if process exists or not
#                     - Moved check into a seperate function "pexists"
# V1.13 (24.01.2000): - Replaced JSDK 2.1 with "tomcat" (JSP 1.1 and JSDK 2.2)
# V1.12 (27.09.1999): - Removed check for single user dirs at jigsaw startup, 
#                       instead a single test is made if the automounter is running.
# V1.11 (05.09.1999): - Improved checking if automountd can reach user directries or not.
# V1.10 (12.08.1999): - Added JIGROOT config variable which allows that jigsaw's root can be anywhere.
#                       Suggested by John E. Conlon (jconlon@verticon.com). Thanks !
# V1.9  (11.08.1999): - removed -host option at startup. It seems that jigsaw 2.0.3 no longer requires this option...
# V1.8  (26.07.1999): - fixed the longstandig (silly!) bug that "ps -ef | grep bla-bla" returns the "grep" line
#                     - "grep" replaced by "fgrep" - smaller, faster...
#                     - reduced the "start" sleep value back to 5 sec...
# V1.7  (29.05.1999): - Changed CLASSPATH for JAVA Project-X Release 2
# V1.6  (12.05.1999): - stop now only starts jigkill if there's a jigsaw-server process running
# V1.5  (07.05.1999): - start: increased the delay from 10 to 20 sec after jigsaw has been invoked because 
#                       some msgs are "eaten" by dtlogin/xdm
# V1.4  (03.05.1999): - added "save" option to save servers
#                     - "stop" option now waits until the "jigkill" background process returns
#                     - fixed delay in stop option (was "sleep 8" instead of "sleep 5"; 
#                       bug introduced in V1.2)
#                     - fixed startup delay (should be 10 sec to see jigsaw's startup messages on console)
# V1.3  (28.04.1999): - changed CLASSPATH for new servlet archive /usr/local/java/jsdk2.1/servlet.jar
#                     - added SIGKILL shutdown method to force a "shutdown" of jigsaw service if SIGTERM 
#                       did not work
#                     - added "restart_server" switch to make "stop" + "start" in one step.
#                       (I did not use the name "restart" because this may be reserved by another /etc/init.d/ 
#                       script functionality...)
# V1.2              : - added "sleep 5" at startup to see servers startup messages before xdm/dtlogin hides 
#                       this info...
# V1.1              : - initial release
#######################################################
# Install instructions:
# copy this script to /etc/init.d/jigsaw.server and make hard links 
# /etc/rc3.d/S10jigsaw.server and /etc/rc0.d/K39jigsaw.server to this script
# Set permissions to 700 (chmod 700 /etc/init.d/jigsaw.server), otherwise
# the admin server's password is visible to anyone !!
#######################################################
# User "modifyable" variables:
JIGHOME=/usr/local/Jigsaw
JIGHOST=gyros.informatik.med.uni-giessen.de
JIGROOT=${JIGHOME}/Jigsaw/Jigsaw # this is normally the default location
# JIGROOT=/shared/www/gyros.informatik.med.uni-giessen.de
JIGUID=jigsaw
JIGGID=www

JIGADMINUSER=admin
JIGADMINPASSWD=jig4theworld

# be carefull that this is in sync with the user classpath variables
CLASSPATH=/usr/local/java/javasoft-project-x/xml-tr2/xml.jar:/usr/local/java/ibmxml4j/xml4j_2_0_0/xml4j.jar:/usr/local/java/javamail/mail.jar:/usr/local/java/jaf/activation.jar
# add CLASSPATH elements required by jigsaw
CLASSPATH=${CLASSPATH}:/usr/local/java/tomcat/lib/servlet.jar:/usr/local/java/tomcat/lib/jasper.jar:/usr/java/lib/tools.jar
# add jigsaw's classes itself
CLASSPATH=${CLASSPATH}:${JIGHOME}/Jigsaw_2.1/classes/sax.jar:${JIGHOME}/Jigsaw_2.1/classes/xp.jar
export CLASSPATH


## do not edit below this line !!
PATH=/usr/java/bin:/usr/xpg4/bin:/usr/bin:/usr/sbin; export PATH
LD_LIBRARY_PATH=${JIGHOME}/Jigsaw/lib/solaris:${LD_LIBRARY_PATH}; export LD_LIBRARY_PATH
JIGSAW_PID=/etc/jigsaw.pid ; export JIGSAW_PID # must be changed if you run multiple instances of jigsaw

# check if given PID exists
pexists()
{ 
    if [ -d "/proc/$1" ] ; then
        return 0
    fi

    return 1
}


jigkill()
{ 
    java -client org.w3c.jigsaw.admin.JigKill $*
    return
}


# jigsaw installed on this system ?
[ ! -d "${JIGHOME}" ] && exit


# Start/stop processes required for jigsaw WWW server
case "$1" in
'start')
    echo "jigsaw webserver\c"

    # echo " disabled."
    # exit 0
    
    if [ -f $JIGSAW_PID ] ; then
        echo " already running."
        exit 0
    else
        # check if the automounter is running...
        if [ `pgrep automountd` = "" ] ; then 
            echo " cannot be started, automountd not running."
            exit 0
        fi

        # increase max. number of open files per process
        ulimit -n 1000    

        # launch jigsaw web server
        (java -server -Xms16m -Xmx192m org.w3c.jigsaw.Main -root ${JIGROOT} -user ${JIGUID} -group ${JIGGID} </dev/null 2>&1 & echo $! >$JIGSAW_PID) | tee -a ${JIGROOT}/logs/console >/dev/console &
    
        echo " started." 

        exit 0
    fi    
    ;;

'stop')   
    if [ -f $JIGSAW_PID ] ; then
        echo "Attempt to kill jigsaw web server\c"
        
        JIGPID=`cat $JIGSAW_PID`
        
        echo ".\c"
        
        # only and only start jigkill if there is a process that can killed !
        if pexists ${JIGPID} ; then
            jigkill -u ${JIGADMINUSER} -p ${JIGADMINPASSWD} --stop http://${JIGHOST}:8009/ >/dev/null &
        
            # time to wait for jigsaw to exit, after this fire a SIGTERM to the JVM
            TIMETOKILLJIG=48 # 4 min
        
            while pexists ${JIGPID} ; do 
                echo ".\c"
                sleep 5
                TIMETOKILLJIG=`expr ${TIMETOKILLJIG} - 1`
            
                # sometimes the JVM hangs; in this case (after TIMETOKILLJIG * 5 sec) send a SIGTERM...
                if [ ${TIMETOKILLJIG} -lt 1 ] ; then
                  echo "(sending SIGTERM)\c"
                  kill ${JIGPID}
                  sleep 5 # sleep some extra time
                fi
            
                # same as above, but the unfriendly KILL method to FORCE a shutdown...
                if [ ${TIMETOKILLJIG} -lt -5 ] ; then
                    echo "(sending SIGKILL)\c"
                    kill -KILL ${JIGPID}
                    echo "######## jigsaw server was KILLED !!!"
                fi        
            done 
        fi
        
        # remove pid key
        rm -f $JIGSAW_PID
        
        echo " done\c"
        
        # wait for "jigkill" background process
        wait      
        
        echo "." 
    else
        echo "jigsaw web server not running."
    fi
    ;;
    
'restart_server')
    echo "jigsaw restart:"
    
        echo "stopping jigsaw..."
        ${0} stop
      
        sleep 2
      
        echo "starting jigsaw..."
        ${0} start
      
    echo "restart done."
    ;; 
     
'save')
    if [ -f $JIGSAW_PID ] ; then
        # any details are printed from jigkill...
        jigkill -u ${JIGADMINUSER} -p ${JIGADMINPASSWD} --save http://${JIGHOST}:8009/ 
        
        echo "save done."
    else
        echo "jigsaw web server not running."
    fi
    ;;
    
*)
    echo "Usage: ${0} { start | stop | restart_server | save }"
    exit 1
    ;;
esac
exit 0

# EOF.

Received on Tuesday, 5 September 2000 14:22:05 UTC