Server Administration: automatically restarting services

Darin Perusich Darin.Perusich at cognigencorp.com
Fri Apr 9 09:52:09 EDT 2004


you need to take into account the possibility that someone might be 
ssh'd into the machine. so you need to narrow it down to the parent ssh 
process. this script will take care of it for you, it's specific to ssh. 
modify to fit your needs.

--BEGIN--
#!/bin/sh
PID=`cat /var/run/sshd.pid`
CHECKPID=`ps wax |grep sshd |grep $PID |awk '{print $1}'`

if [ "X${CHECKPID}" = "X" ]; then
         /etc/init.d/ssh start
         # email the admin
         echo "started ssh on server `hostname` on date `date`, 
please \ 		investigate" | mailx -s "We Have A Problem" admin at somedomain.net

fi
exit
--END--

Matt Cristantello wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Thanks for the ideas -- I'll look into BigBrother/Sister over the
> weekend if I get a chance.
> 
> I have some scripts right now that look like this--
> 
> #!/bin/sh
> 
> ps -A | grep -v sshdassert | grep sshd > /dev/null || /etc/init.d/ssh start
> 
> I was hoping to find something that would pick up on dead processes,
> etc. I'll see if BigBrother can do that.
> 
> Thanks!
> ~Matt
> 
> Mark Musone wrote:
> | Another trick (if it's not a daemonizing process) is to simply put it in
> | the /etc/inittab as a respawn entry. Doing that will make init always
> | keep the process running, and will restart it automagically when it
> | stops running..
> |
> |
> |
> | -----Original Message-----
> | From: owner-nflug at nflug.org [mailto:owner-nflug at nflug.org] On Behalf Of
> | Dennis Ruzeski
> | Sent: Thursday, April 08, 2004 8:26 AM
> | To: nflug at nflug.org
> | Subject: RE: Server Administration: automatically restarting services
> |
> | This is a pretty simple shell script from UGU.com. The basic idea is
> | that it greps for the process. If it doesn't see it, it restarts it..
> | This one is ok, I've got a ksh version that's a little neater and a
> | friend of mine wrote a perl script that's great, but I can't get a hold
> | of him to get a copy.
> |
> |
> | From UGU.com
> | Here is a script that will keep daemons running
> | if the decide to die for some unforseen reason.
> |
> | This tip generously supported by: ken at theglobeandmail.com
> |
> | -------------------- cut here -----------------
> |
> |
> |
> | #!/bin/csh
> | #
> | # NAME
> | # keepitup.csh - Keep demons up and running
> | #
> | # SYNOPSIS
> | # keepitup.csh
> | #
> | # DESCRIPTION
> | # If any of the following processes are down, then start them up
> | # again. This script can be run every few minutes from a crontab.
> | #
> | # AUTHOR
> | # Ken Stevens
> |
> | foreach daemon ( \
> | /opt/GIS/apps/EventDispatcher/scripts/EventDispatcher.pl \
> | /opt/GIS/apps/CatchFTP/scripts/ProcessFTP.pl \
> | /opt/GIS/apps/NewsHound/scripts/NewsHound.pl \
> | )
> |
> | ps -e | fgrep `echo $daemon:t | cut -c1-8` > /dev/null
> |
> | if ( $status > 0 ) then
> | echo Restarting $daemon
> | date
> | $daemon &
> | endif
> |
> | end
> |
> |
> |
> | -----Original Message-----
> | From: Matt Cristantello [mailto:matt at crazy42.org]
> | Sent: Thursday, April 08, 2004 12:39 AM
> | To: nflug at nflug.org
> | Subject: Server Administration: automatically restarting services
> |
> | Hey,
> |
> | I was just wondering if any of you have come across any projects to
> | automatically restart crashed or broken services (such as sshd, apache,
> | etc.) in linux. I have rcN.d and init.d scripts set up, but I'd like
> | something to check, say every five minutes, and see if a process is
> | still running/is in a good state, then restart it if it's not. I can do
> | something similar using ps -A, grep, and then running the init.d script
> | if necessary, but I'd like somethign a little more automatic. If nothing
> | like this has been done, I'll look into writing something and releasing
> | it under the GPL or something like that.
> |
> | Thanks,
> | ~Matt
> |
> | --
> | ************************************************************************
> | ****
> | "When trouble arises and things look bad, there is always one
> | individual who perceives a solution and is willing to take command.
> | Very often, that individual is crazy."
> | -Dave Barry
> | ************************************************************************
> | ****
> | ~                Matthew D. Cristantello
> | ~                matt at crazy42.org
> | ~                716-472-3833 (cell)
> | ~                AIM: Matt977
> | ************************************************************************
> | ****
> 
> - ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.651 / Virus Database: 417 - Release Date: 4/5/2004
> 
> 
> - ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.651 / Virus Database: 417 - Release Date: 4/5/2004
> 
> 
> 
> - --
> **************************************************************************** 
> 
> "There are many ways of going forward, but only one way of standing
> still."
> - -Franklin D. Roosevelt
> **************************************************************************** 
> 
> ~                Matthew D. Cristantello
> ~                matt at crazy42.org
> ~                716-472-3833 (cell)
> ~                AIM: Matt977
> **************************************************************************** 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.4 (GNU/Linux)
> 
> iD8DBQFAdhWLi3I4xV1yeBQRAoheAKCfrrPCpiBrvPr/xrtBscZOMr7RQgCfag0Y
> lsk1Jydb9fVle7YfZe91/mE=
> =60fa
> -----END PGP SIGNATURE-----
> 
> 

-- 
Darin Perusich
Unix Systems Administrator
Cognigen Corp.
darinper at cognigencorp.com





More information about the nflug mailing list