Here’s the new one….
 
#!/bin/sh
RETVAL=0
 
if [ "$1" = "" ]
 then
  BASE=/opt/ASSP;
 else
  BASE=$1;
fi
export BASE
echo Stopping ASSP Anti-SPAM Proxy server in $BASE
pidfile=$BASE/pid
 
if [ ! -e $pidfile ]; then
  echo "ASSP already stopped"
else
  PID=`cat $pidfile`
  if [ "x" == "x$PID" ]; then
    exit
  fi
 
  kill $PID
 
  # wait for ASSP to quit gracefully
  tries=""
  while ps -p $PID | grep $PID 1> /dev/null 2> /dev/null ; do
    if [ "x$tries" == "x......." ]; then
      break
    fi
    sleep 2
    tries=".$tries"
  done
 
  if ps -p $PID | grep $PID 1> /dev/null 2> /dev/null ; then
    echo "ASSP is still running, I will remove it from memory"
    kill -9 $PID
 
    # wait for ASSP to be removed from memory
    tries=""
    while ps -p $PID | grep $PID 1> /dev/null 2> /dev/null ; do
      if [ "x$tries" == "x......." ]; then
        break
      fi
      sleep 2
      tries=".$tries"
    done
 
    if ps -p $PID | grep $PID 1> /dev/null 2> /dev/null ; then
      # Process is still running...  return error
      echo "Error... ASSP could not be terminated"
      RETVAL=1
    else
      # in case ASSP changed PID during this script I will NOT kill the pidfile
      if [ $PID == `cat $pidfile` ] ; then
        rm -f $pidfile
      else
        echo "ASSP changed PID, run command again"
        RETVAL=1
      fi
    fi
  fi
fi
exit $RETVAL
 
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Jean-Pierre van Melis
Verzonden: zaterdag 5 april 2008 14:06
Aan: 'ASSP development mailing list'
Onderwerp: Re: [Assp-test] watchdog
 
I just noticed myself that the script is incorrect…
Please wait with comments… (shame on me)
 
Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Jean-Pierre van Melis
Verzonden: zaterdag 5 april 2008 13:11
Aan: 'ASSP development mailing list'
Onderwerp: [Assp-test] watchdog
 
A year ago I wrote a little bash-script to use as a watchdog for my ASSP’s.
Whenever I have a buggy or ill-responding ASSP-script, it is easily identified 
by its occasional restarting (of which I get an email).
It is working quite good, but I want to improve it.
 
The watchdog uses “service <assp-service> start” and “service <assp-service> 
stop” to control the process.
Sometimes, on a high-load server, the command “service <assp-service> stop” is 
not able to stop the process.
That’s why I want to use “kill -9” to remove the process from memory.
Is this good practice or bad practice?
 
Furthermore I want to know which script to modify.
I can modify my watchdog, the “init.d script” or the “stop” script.
The easiest place to modify was the “stop” script, which I did.
Anyone having tips or comments?
 
# cd /opt/ASSP/
# cat stop
#!/bin/sh
if [ "$1" = "" ]
 then
  BASE=/opt/ASSP;
 else
  BASE=$1;
fi
export BASE
echo Stopping ASSP Anti-SPAM Proxy server in $BASE
pidfile=$BASE/pid
kill `cat $pidfile`
 
# wait for ASSP to quit gracefully
tries=""
while [ -e $pidfile ]; do
  if [ "x$tries" == "x......." ]; then
    break
  fi
  sleep 2
  tries=".$tries"
done
if [ -e $pidfile ]; then
  echo "ASSP is still running, I will remove it from memory"
  kill -9 `cat $pidfile`
fi
-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Register now and save $200. Hurry, offer ends at 11:59 p.m., 
Monday, April 7! Use priority code J8TLD2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Assp-test mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/assp-test

Reply via email to