Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check to see if the daemon is up

Status
Not open for further replies.

lintow

Programmer
Nov 29, 2004
82
US
I have a daemon that I have to start when it is shut down.
So I would like to check to see if the daemon is up and running. If its running then stop the script. If its not running then start the daemon. This is what I want to do.

As of right now I have some of it setup. But I need to check if its running or not. Thats where I need help.



Here is the script I have for now. This is when I run it.

server {dars}> ./script.shl
Daemon daemon not running
[1] 23386
server {dars}> Creating deamon daemon
Done creating daemons

server {dars}>
 
Hi

You forgot to mention the system/distribution. Maybe there are tools for this. On SuSE usually [tt]startproc[/tt], [tt]checkproc[/tt] and [tt]killproc[/tt] are used for this kind of handling daemons.

As I see from that output, seems to be some PID logging. So theoretically :
Code:
if ps `cat pidfile` > /dev/null; then
  echo Is running
else
  echo Not running
fi
For a proper solution would be better to see that script.

Feherke.
 
What scripting language are you using.
Pretty straigh forward if you're using bash or ksh

eg.
#!/usr/bin/ksh

RUNNING=`ps -ef | grep endmail | wc -l`
if [ $RUNNING -eq 0 ] ; then
startsrc -s sendmail #AIX Daemon
fi
exit 0


"If you always do what you've always done, you will always be where you've always been."
 
I have one line in the script
startdaemon


This is a log file that is created
once I run startdaemon

2005/09/30 09:10 Starting DARwin Daemon 3.0.4 (for Java 1.2)
2005/09/30 09:10 Attempting to connect to jdbc:eek:racle:thin:mad://123.877.999:1521/TEST
2005/09/30 09:10 Database Connection Successful!!!
2005/09/30 09:10
2005/09/30 09:10 DARwin Daemon 3.0.4 running
 
Hi

Give us details about startdaemon. For example some output from the commands :
Code:
type startdaemon
which startdaemon
ls -l `which startdaemon`
file `which startdaemon`
cat `which startdaemon`

Feherke.
 
server {dars}> startdaemon
server {dars}> Creating deamon daemon
Done creating daemons
server {dars}>

once this is done. It also creates a log file
here is the log file

2005/09/30 09:10 Starting DARwin Daemon 3.0.4 (for Java 1.2)
2005/09/30 09:10 Attempting to connect to jdbc:eek:racle:thin:mad://123.877.999:1521/TEST
2005/09/30 09:10 Database Connection Successful!!!
2005/09/30 09:10
2005/09/30 09:10 DARwin Daemon 3.0.4 running
 
You may avoid grepping for the daemonname and using 'wc' to check if there is a result, and instead format the output of ps with '-opid=' and restrict the ps-query to the command in question '-C DAEMONNAME':
Code:
ps -opid= -C DAEMONNAME && STOPCMD || STARTCMD
Of course you have to adjust DAEMONNAME, STOPCMD and STARTCMD.
STARTCMD might be 'startdaemon'.
If there is no regular command to stop the daemon, you might kill it - preferably with 'kill 15 PIDofDAEMON', not 'kill 9 PIDofDAEMON'.
The pid is get with the ps-command:
Code:
function stopdaemon {
        kill 15 $(ps -opid= -C DAEMONNAME)
}

seeking a job as java-programmer in Berlin:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top