- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: Monitor a process, then restart it if its down...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 04:02 AM
тАО05-02-2006 04:02 AM
I have a particlar process that I want to monitor continously and that I want to restart if it stops.
Any ideas?
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 04:08 AM
тАО05-02-2006 04:08 AM
Re: Monitor a process, then restart it if its down....
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 04:12 AM
тАО05-02-2006 04:12 AM
Re: Monitor a process, then restart it if its down....
Lets use sendmail as an example.
Script stubb
procname=sendmail
UNIX95=1
while true
do
sprocs=$(ps -C $procname)
if [ $sprocs -eq 0 ]
then
/sbin/init.d/sendmail start
fi
sleep 1800
done
This script stub(incomplete script) sees if sendmail is running. It does not use grep, which Bill Hassell says is a no-no.
If the number of sendmail processes is 0 it restarts the daemon.
What it needs is code if it can't restart the daemon. Obviously by changing it, you can monitor any daemon.
Note, if you want to monitor oracle, its unfortuneatly quite possible for there to be a process and the database be hoplessly down. You need sql code to accurately monitor oracle.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Tags:
- PS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 04:16 AM
тАО05-02-2006 04:16 AM
Re: Monitor a process, then restart it if its down....
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 04:22 AM
тАО05-02-2006 04:22 AM
Re: Monitor a process, then restart it if its down....
You can put the process into /etc/inittab with respawn option. RTFM for inittab
HTH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО05-02-2006 05:33 AM
тАО05-02-2006 05:33 AM
SolutionThis way, if the program dies, the monitor catches it. If the monitor dies, it is relaunched via cron, and if both die, then the monitor launches, and in turn launches the monitored process.
If I may expand on/change Steve's example; here's the script to have run from cron. Be aware that to make it run from cron, you may have put put in absolute paths for every command in the file (e.g. put in "/usr/bin/ps" instead of "ps").
#!/bin/ksh
export CYCLE_TIME=1800
export PROCNAME=sendmail
# Chk to see if monitor is already running
export MYPROG=`basename $0`
let PROGCOUNT=0
export PROGCOUNT
UNIX95=1
PROGCOUNT=`ps -C ${MYPROG}| wc -l`
UNIX95=0
if [ $PROGCOUNT -gt 2 ]; then
exit 0
fi
# Monitor sendmail
while true
do
UNIX95=1
PROGCOUNT=`ps -C ${PROCNAME}|wc -l`
UNIX95=0
if [ $PROGCOUNT -lt 2 ]; then
/sbin/init.d/sendmail start
fi
sleep $CYCLE_TIME
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-31-2008 08:18 AM
тАО01-31-2008 08:18 AM
Re: Monitor a process, then restart it if its down....
export CYCLE_TIME=1800
export PROCNAME=sendmail
# Chk to see if monitor is already running
export MYPROG=`basename $0`
let PROGCOUNT=0
export PROGCOUNT
UNIX95=1
PROGCOUNT=`ps -C ${MYPROG}| wc -l`
UNIX95=0
if [ $PROGCOUNT -gt 2 ]; then
exit 0
fi
# Monitor sendmail
while true
do
UNIX95=1
PROGCOUNT=`ps -C ${PROCNAME}|wc -l`
UNIX95=0
if [ $PROGCOUNT -lt 2 ]; then
/sbin/init.d/sendmail start
fi
sleep $CYCLE_TIME
done