[cod] Restart Script

Nathan P. natedog550 at hotmail.com
Thu Jan 27 14:40:06 EST 2005


> or possibly with something checking for 100% cpu

Here's some code I came up with a while back and actually use it.  I run it
as a daemon.  The problem is that you would want it to not restart the
server the second it sees the CPU being over 98%.  But rather have it send
like let's say the number one to a file and then sleep for 60 seconds and
then run this command again and grep the file to see if it has been hung
recently.  By doing that you've pretty much proven that the server is
definitely hung and not just a weird spike.  Another problem is the below
code uses the "top" command.  This seems to use a little more CPU then I
would want.  So I'm going to change it to the "ps" command instead.  I think
it may have to do with top being a interactive display and if you run a ps
-aux it just outputs then stops.  Anyways later on what I'm going to do is
that if it sees that it's been hung it'll restart.  Then wait and check
again.  If it's hung again instead of restarting it'll shutdown then send an
email to me and the user.  Shutting down should counter-act config problems
or whatever because that way it won't be in an infinite loop of restarting.
In case you didn't know print $9 = column 9 of the output - adjust to your
system accordingly.

HUNG=`top -b -n 1 | grep BinaryFileHere | grep -v grep | awk '{print $9}'`
      if [ "$HUNG" \> 98 ] ; then
        Do something here
      else
       Do something here
      fi


Peace

--
NateDog


> -----Original Message-----
> From: Ian mu [mailto:mu.llamas at gmail.com]
> Sent: Wednesday, January 26, 2005 11:20 AM
> To: cod at icculus.org
> Subject: Re: [cod] Restart Script
> 
> Yeah the hard crashes are easier to deal with, the hanging ones I
> guess realistically you're going to have to code something to check
> its status every so often with a udp query status and restart it if
> its not (could possibly use something like qstat), or possibly with
> something checking for 100% cpu, but I think that ways probably a bit
> unreliable. Be interesting if someones done one already as thinking of
> writing one myself otherwise.



More information about the Cod mailing list