Results 1 to 7 of 7
Hi,
The requirement is to monitor an application which should be executing all the time, and if the application is down for any reason, it should be automatically started by ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 11-17-2012 #1Just Joined!
- Join Date
- Nov 2012
- Posts
- 3
Application monitoring
Hi,
The requirement is to monitor an application which should be executing all the time, and if the application is down for any reason, it should be automatically started by the monitoring script.
For this, currently we have written a monitoring script which is added to a crontab and it is scheduled for execution every minute. This(monitoring script) should start the application if it is down. Currently it is not working as expected for some reason. We have a command in the script which uses 'nohup' to bring up the application, this command is working fine when issued thru the command prompt, but not working when it is used in the shell script.
I need help in finding out what the issue could be with the shell script and also if there is an alternate method to achieve the objective stated.
Thanks in advance.
- 11-17-2012 #2Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
hi,
without the scripts, we'll just have to guess.
it may take a very long time, until we hit it right !
as crontab does not have tty, nohup is useless.
check path for every command is in PATH.
if an application can be down, it should be started from inittab.
- 11-17-2012 #3Just Joined!
- Join Date
- Nov 2012
- Posts
- 3
Hi,
Below is the script contents.
If the following code is executed manually the application starts...Code:#!/bin/bash # check daemon ps -ef | grep -v grep | grep comon.App # if not found - equals to 1, start it if [ $? -eq 1 ] then nohup /app/Oracle/Middleware/jdk160_21/bin/java -cp /app/abcd/watch/LogS.jar logs.comon.App & else echo " already running - do nothing" fi
So not sure what the issue is.Code:nohup /app/Oracle/Middleware/jdk160_21/bin/java -cp /app/abcd/watch/LogS.jar logs.comon.App &
- 11-17-2012 #4Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,695
Hello and welcome to LinuxForums!
I would use screen to to do this, instead of nohup.
It will launch a screen session in the background, with your named process running in the foreground of that screen. Here's an example of how to call it:
To list running screens for a given user, do:Code:screen -dm -S Java_App /app/Oracle/Middleware/jdk160_21/bin/java -cp /app/abcd/watch/LogS.jar logs.comon.App
to attach to the pid of a screen (returned by the above command):Code:screen -ls
or in the above case, you can use the screen name like:Code:screen -r <PID>
if you need to clean screens:Code:screen -r Java_App
Also, to trouble-shoot your original issue, i would add logging to the cronjob, e.g.:Code:screen -wipe
then check that log file for errors that you might normally not be seeing, when cron runs the job.Code:10 0 * * * /path/to/java_script.sh > /tmp/script-cronjob.log 2>&1
- 11-17-2012 #5Linux Newbie
- Join Date
- Nov 2012
- Posts
- 134
better is to not use ps, because it shows itself too.
instead use pidof, or pgrep.
- 11-18-2012 #6Just Joined!
- Join Date
- Nov 2012
- Posts
- 3
Can this be implemented in a production environment ?
- 11-18-2012 #7Trusted Penguin
- Join Date
- May 2011
- Posts
- 3,695


Reply With Quote

