#!/bin/sh #################################################################################################### # Script to control the java SimpleSocketServer process. # # SS_PORT must be the same port as in the log4j.xml socket appender that the client (cipres-portal) uses. # ss_log4j.xml should be the same log directory that the client (cipres-portal) is using for the other log files. # # Usage: ss_control [start|stop|restart|status] # Exit status # start, restart, status - 0 if socketserver is started or already running, 1 otherwise # stop - 0 if socketserver is killed or not running, 1 otherwise # Notes: # * You must make this script executable. Running as "sh ss_control" won't work! # * If socket server is restarted or started after the web app, the socket appender in # the web app will try to reconnect. It may take up to 30 sec. That's the default time, but # can be overridden for the socket appender in the web app's log4j.xml. #################################################################################################### # Figure out which directory this script is in. whereami() { program="$0" while [ -h "$program" ]; do link=`ls -ld "$program"` link=`expr "$link" : '.*-> \(.*\)'` if [ "`expr "$link" : '/.*'`" = 0 ]; then dir=`dirname "$program"` program="$dir/$link" else program="$link" fi done SS_ROOT=`dirname $program` SS_ROOT=`cd $SS_ROOT && /bin/pwd` } whereami SS_PORT=${ngbw.logs.sdk.port} SS_USER=`whoami` HOST=`hostname` LOG4J_JAR=${SS_ROOT}/log4j*.jar LOG4J_XML=${SS_ROOT}/ss_log4j.xml MYLOG=${ngbw.logs}/ss.log if [ "`uname | grep Darwin`" = "Darwin" ]; then PS="ps -U$SS_USER -j -ww" else PS="ps -U$SS_USER -f" fi # Get processes IDs of interest getpids() { MY_SS=`$PS | grep SimpleSocketServer | grep $SS_PORT | grep -v grep | awk '{print $2}'` OTHER_SS=`$PS | grep SimpleSocketServer | grep -v $SS_PORT | grep -v grep | awk '{print $2}'` len $MY_SS ; MY_SS_COUNT=$? len $OTHER_SS; OTHER_SS_COUNT=$? } len() { retval=0 for i in $* do retval=`expr $retval + 1` done return $retval } killall() { for pid in $* do echo killing $pid on $HOST kill $pid done } SS_RETVAL=1 case "$1" in 'start') getpids if [ $MY_SS_COUNT -eq 0 ]; then echo "Starting SimpleSocketServer on $HOST port $SS_PORT" echo "Starting SimpleSocketServer on $HOST port $SS_PORT" >> $MYLOG nohup java -classpath $LOG4J_JAR org.apache.log4j.net.SimpleSocketServer $SS_PORT $LOG4J_XML >> $MYLOG 2>&1 < /dev/null & sleep 5 fi $0 status SS_RETVAL=$? ;; 'stop') getpids killall $MY_SS sleep 5 $0 status if [ $? = 0 ]; then SS_RETVAL=1 else SS_RETVAL=0 fi ;; 'restart') echo "Restarting SimpleSocketServer" on $HOST with port $SS_PORT $0 stop sleep 5 $0 start SS_RETVAL=$? ;; 'status') getpids if [ $MY_SS_COUNT -gt 0 ] ; then echo "SimpleSocketServer is running on $HOST with port $SS_PORT. pid(s): $MY_SS" SS_RETVAL=0 else echo "SimpleSocketServer is NOT Running on $HOST with port $SS_PORT" fi if [ $OTHER_SS_COUNT -gt 0 ] ; then echo "There are SimpleSocketServers running on ports other than $SS_PORT on $HOST. pid(s): $OTHER_SS" fi ;; *) echo "Usage: $0 {start|stop|restart|status}" SS_RETVAL=1 ;; esac exit $SS_RETVAL