[r58]: tags / 1.2.1 / dspace-vireo / bin / start-winstone Maximize Restore History

Download this file

start-winstone    152 lines (129 with data), 5.0 kB

#!/bin/sh

###########################################################################
#
# start-winstone
#
# Version: $Revision: 618 $
#
# Date: $Date: 2003-04-07 09:41:43 -0500 (Mon, 07 Apr 2003) $
#
# Copyright (c) 2002, Hewlett-Packard Company and Massachusetts
# Institute of Technology.  All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# - Neither the name of the Hewlett-Packard Company nor the name of the
# Massachusetts Institute of Technology nor the names of their
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
# TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#
###########################################################################
#
# This is a simple shell script for starting the winstone webserver. The
# webserver will be run in the background, then the shell script will check 
# to make sure the server started successfully before return a status code. If 
# the server faild to start then an error status code will be returned, 
# otherwise a positive status code is returned.

USAGE="start-winstone"

# Check we have at least one command-line argument
if [ "$#" != "0" ]; then
    echo $USAGE
    exit 1
fi

# Assume we're in the bin subdirectory of the DSpace installation directory
BINDIR=`dirname $0`
DSPACEDIR=`cd "$BINDIR/.." ; pwd`
LOGFILE="$DSPACEDIR/log/winstone"


## Check if winstone is allready running
pid_of_winstone () {
    ps auxwww | grep java | grep "winstone.*jar --webappsDir=" | grep -v grep | awk '{print $2}';
}

## If winstone is running, then stop it.
if [ -n "`pid_of_winstone`" ]; then
   echo "Winstone (PID:`pid_of_winstone`) is all ready running, attempting to stop...\c"
   kill -15 `pid_of_winstone`
   
   sleep=0
   while true; do
     sleep 1
     echo ".\c"

     if [ $sleep -gt 20 ]; then
       kill -9 `pid_of_winstone`
       echo " Killed."
       break
     fi
     if [ ! -n "`pid_of_winstone`" ]; then
       echo " Stopped."
       break
     else
       let sleep++
       sleep=`expr $sleep + 1`
     fi
   done
fi 


## Rotate old logs
if [ -f "${LOGFILE}.log" ]; then
    #Find the oldest log
    lastlogindex=1
    while true; do
        if [ -f "${LOGFILE}${lastlogindex}.log" ]
        then
             lastlogindex=`expr $lastlogindex + 1`
        else
            break
        fi
    done
    
    #Move each log up one
    i=$lastlogindex
    while [ $i -gt 1 ]; do
      mv ${LOGFILE}`expr $i - 1`.log ${LOGFILE}${i}.log    
      i=`expr $i - 1`
    done
    mv ${LOGFILE}.log ${LOGFILE}1.log
fi

## Acutaly start winstone
#java -Xmx256m -jar $DSPACEDIR/lib/winstone-*.jar --webappsDir=$DSPACEDIR/webapps/ --httpPort=8081 --ajp13Port=-1 > ${LOGFILE}.log 2>&1 &
#java -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n -Xmx256m -jar $DSPACEDIR/lib/winstone-*.jar --webappsDir=$DSPACEDIR/webapps/ --httpPort=8081 --useJNDI --ajp13Port=-1 --controlPort=8008  > ${LOGFILE}.log 2>&1 &
java -Xmx256m -jar $DSPACEDIR/lib/winstone-*.jar --webappsDir=$DSPACEDIR/webapps/ --httpPort=8081 --useJNDI --ajp13Port=-1 --controlPort=8008 -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y > ${LOGFILE}.log 2>&1 &



## Check that winstone started successfully, otherwise exit with an error code.
echo "Starting Winstone...\c"

sleep=0
while true; do
    sleep 1
    echo ".\c"

    if [ $sleep -gt 200 ]; then
        echo " Failed, check the log for error."
        cat ${LOGFILE}.log
        exit 1
    fi
    
    if grep -q "java.net.BindException: Address already in use" ${LOGFILE}.log; then
    	echo " Failed, address already in use."
    	exit 1
    fi
    
    if grep -q "Winstone Servlet Engine .* running" ${LOGFILE}.log; then
        echo " Started."
        exit 0
    fi
    
    sleep=`expr $sleep + 1`
done