#!/bin/sh if [ ! -r pid ]; then echo Service does not appear to be running exit 0 fi PID=`cat pid` for TRY in try1 try2; do PROCEXISTS=false ps -p $PID >/dev/null 2>&1 if [ $? -eq 0 ]; then PROCEXISTS=true fi if [ $PROCEXISTS = true ]; then echo It appears the service is running echo Process ID is $PID touch terminate_service echo  quit | telnet `hostname` `cat port` 1>/dev/null 2>&1 echo Stopping service while ps -p $PID > /dev/null 2>&1; do echo `date`: Waiting for process $PID to terminate sleep 5 done else echo It appears the service is stopped rm -f pid break fi sleep 1 done if [ ! -d save ]; then mkdir save fi mv server.log save/server.log_`date +%Y-%m-%d_%T` mv stdout.log save/stdout.log_`date +%Y-%m-%d_%T`