LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices



Reply
 
Search this Thread
Old 08-12-2002, 02:20 AM   #1
IceNineJon
Member
 
Registered: Jun 2002
Location: Los Angeles, Ca, USA
Distribution: Mandrake 9.1
Posts: 82

Rep: Reputation: 15
program to check to make sure a process is running?


I have a fairly new server up and running which has a RealServer installed on it. It works fine but every couple of weeks, RealServer crashes and I have to manually start it again. Is there a program that will automatically check the process list and let me know if "rmserver" is still running and if it isn't, email me?

Of course this does not solve my RealServer problems but at least I'll know when it crashes right away.

Any suggestions are appreciated,
Jon
 
Old 08-13-2002, 12:27 PM   #2
abrakadabra
Member
 
Registered: Apr 2002
Location: Denver
Distribution: SuSe,RedHat,Mandrake,
Posts: 109

Rep: Reputation: 16
Hi IceNineJon,

No sure how proficient you are in creating scripts but in your place I'd create one and put it as a cron to execute every so often.

Here is the pseudo code for it.

# check if rmserver is running.

if running=yes # to check this you can use ps
do nothing
else
e-mail system admin.
fi

You can also configure the /var/sys.log file for this task.

Good luck!


 
Old 08-13-2002, 02:27 PM   #3
IceNineJon
Member
 
Registered: Jun 2002
Location: Los Angeles, Ca, USA
Distribution: Mandrake 9.1
Posts: 82

Original Poster
Rep: Reputation: 15
abrakadabra: thanks for the idea but unfortunately I'm not very proficient with linux scripting at the time but maybe it's a good time to learn then

Thanks for your input,
Jon
 
Old 08-13-2002, 03:04 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,744
Blog Entries: 54

Rep: Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973
# in /etc/crontab:
# this checks every 10mins
*/10 * * * * root /etc/cron.daily/checkrealserver.cron

#!/bin/sh
# this is /etc/cron.daily/checkrealserver.cron, chmod 0750
email=<insert address here>
progname=rmserver

if [ "$(/sbin/pidof $progname)" = "" ]; then echo "rmserver found down on $(date +%m-%d-%Y)" | mail -s "$progname on $(hostname) down at $(date)" $email; fi

Last edited by unSpawn; 08-13-2002 at 03:05 PM.
 
Old 08-13-2002, 03:30 PM   #5
IceNineJon
Member
 
Registered: Jun 2002
Location: Los Angeles, Ca, USA
Distribution: Mandrake 9.1
Posts: 82

Original Poster
Rep: Reputation: 15
Dang unSpawn...you make it look so easy . Thanks, it's working like a charm .

Now, is there any way to make it so it won't email me every ten minutes while it's down (for example, let's say it goes down at 8 PM and I don't check my email until midnight...I'll have 24 warning messages)? If it's too much trouble, don't worry about it, I doubt the little text messages will fill my 75 MB mail queue .

Thanks again!,
Jon

Last edited by IceNineJon; 08-13-2002 at 03:31 PM.
 
Old 08-14-2002, 09:43 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,744
Blog Entries: 54

Rep: Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973Reputation: 2973
Well, there's two ways. First you could tweak the crontab entry to a higher check interval, or we could add an interval to the checkscript. Then again that doesn't fix what you *should* fix, and that's rmserver b4rfing up. Ever considered running strace on it?

Below you'll find a stupid example of how you could tweak a limit per day/hour. It'll check the file for the last time it was run, and if the interval has passed it'll fire off a mail.

We need to add another file, /var/run/checkrealserver make it 0640 to the user.

#!/bin/sh
# this is /etc/cron.daily/checkrealserver.cron, chmod 0750
email=<insert address here>
progname=rmserver
limitf=/var/run/checkrealserver
limitc="+%<d|H>" # d=once daily, H=once hourly, mind you, hourly is caps
if [ ! -f /var/run/checkrealserver ]; then echo "We can't do limiting because we miss $limitf" | mail -s "$progname check error" | mail $email; else limit=$(grep $limitf -e "$(date $limitc)")
if [ "$(/sbin/pidof $progname)" = "" ]&&[ ! "$(date $limitc)" = "$limit" ]; then echo "rmserver found down on $(date +%m-%d-%Y)" | mail -s "$progname on $(hostname) down at $(date)" $email; echo $(date $limitc) > $limitf; fi

# Hell, you could even bashexercise and add a multiplier, like once every 4 dys/hrs...
 
Old 08-15-2002, 12:05 AM   #7
IceNineJon
Member
 
Registered: Jun 2002
Location: Los Angeles, Ca, USA
Distribution: Mandrake 9.1
Posts: 82

Original Poster
Rep: Reputation: 15
Again, thank you for your help...a few questions about your last post:

1) I'd never heard of strace before so I did a google search for it and found the homepage. The page has kernel patches but they're for 2.2.x and I have 2.4.x...does this mean it's not necessary to patch my kernel or do I still need to but the patches are behind?

2) I'm a little confused what this script does. Does it check to see if rmserver is down...if so, it checks to see how much time has passed since an email was last sent? If so, perfect . If not, can you elaborate on what it does?

3) You said above that we need to add another file...I assume that means to leave the other cronjob in the crontab? If so, how do these scripts relate to one another?

Thanks again for your help!,
Jon

Last edited by IceNineJon; 08-15-2002 at 12:08 AM.
 
Old 08-06-2003, 03:07 PM   #8
MacMan824
LQ Newbie
 
Registered: Aug 2003
Location: Pittsford, NY
Distribution: Mac OS X 10.2.6
Posts: 1

Rep: Reputation: 0
Hey,

I found this thread doing a Google search. For whatever reason, my mail server decides to shut itself down whenever somebody logs out of the system. I don't know why. So I wanted to make a cron entry to restart it if it does that, and I tried following these directions.

I had to make my own pidof program, because apparently OS X doesn't have one, but I did and it works just fine. The problem is, the cronjob doesn't appear to work.

My root crontab looks like so:

*/1 * * * * root /etc/cron.daily/checkmailserver.cron
(I want it to check every 1 minute)

And checkmailserver.cron looks like so:

#!bin/sh
progname=WSMailboxServer

if [ "$(/sbin/pidof $progname)" = "" ]; then /Applications/4DWebSTAR/StartupItem/4DWebSTAR/4DWebSTAR; fi

It doesn't seem to work; the mail server shuts down and nothing happens -- it is never restarted. Just for the hell of it, I made the checkmailserver.cron file +x and then tried to execute it, and I got a command not found.

Anyone have any ideas?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Obtain ip address and check for running process via Bash Script? xconspirisist Programming 10 09-12-2008 02:18 PM
Check if program is running Conjurer Programming 8 11-17-2005 02:37 PM
Scripts to check if a process is running kt8993 Programming 3 07-09-2005 06:32 PM
script to check if process is dead or running rspurlock *BSD 6 04-13-2004 12:32 AM
[script] check for a running process mikshaw Linux - Software 2 01-13-2004 09:33 PM


All times are GMT -5. The time now is 03:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration