Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Crontab not starting the application in every minute

 
Binoy Sankar V.S
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,

I have developed a standalone java application which is deployed in a Linux environment. I have created a script for starting this application if the process is not running or else do nothing.
The application is deployed as a .jar. I have also created a crontab entry like this...
*/1 * * * * /app/prd-data/abc/def/xyzMonitor.sh
.

I will provide the contents of the xyzMonitor.sh script...

#!/bin/bash
# check daemon
ps -ef | grep -v grep | grep common.App
# if not found - notequals to 0, start it
if [ $? -ne 0 ]
then
nohup /app/wl-data/Oracle/Middleware/jdk160_21/bin/java -cp Application.jar *.common.App &
else
echo "XYZ Watcher already running - do nothing"
fi



The issue now is that even after one minute the crontab is not picking the script for running this application.
Can someone help me what is the issue here, whether the script is not correct or any others.

P.S: I am a Linux noob and this development is done for my company. I have done the deployment by getting info from various websites. So I might be wrong in this.
Experts please advice to solve this issue.

Thanks in advance,
Binoy
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have given the full path to the 'java' executable but not to the jar file so the script does not know where to find the jar file. Also, I would expect to see the fully qualified class name and not "*.common.App" .
 
Binoy Sankar V.S
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Tookey wrote:You have given the full path to the 'java' executable but not to the jar file so the script does not know where to find the jar file. Also, I would expect to see the fully qualified class name and not "*.common.App" .


Thanks Richard for the response. I have tried giving the full path to the .jar file. Here's the full script

#!/usr/bin/bash
# check daemon
ps -ef | grep -v grep | grep some.name.logscheduler.common.App
# if not found - not equals to 0, start it
if [ $? -ne 0 ]
then
nohup /app/Oracle/Middleware/jdk160_21/bin/java -cp /app/somename/clswatcher/LogScheduler.jar some.name.logscheduler.common.App &
else
echo "CLS Watcher already running - do nothing"
fi


I have tried this also but its not working. Can you suggest where am doing wrong?

Thanks & Regards,
Binoy
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I that really your package ?

So does the script run from the command line regardless of the working directory?
 
Binoy Sankar V.S
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Tookey wrote:I that really your package ?

Obviously that is not the real name. I am developing this for a client, so can't disclose the real name rite . But its just the replacing of some.name.

So does the script run from the command line regardless of the working directory?

I have tried starting the script manually, like sh xyzMonitor.sh from the working directory. The script is starting the app and its running fine too.
But the issue is with the crontab which is not starting it if the process is not running. I need to make a script to start the app without manual intervention. From my knowledge that is only possible through crontab only.
Else please suggest any other solution.

Hope you got me .


Thanks & Regards,
Binoy
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Binoy Sankar V.S wrote:
Richard Tookey wrote:
So does the script run from the command line regardless of the working directory?

I have tried starting the script manually, like sh xyzMonitor.sh from the working directory. The script is starting the app and its running fine too.
But the issue is with the crontab which is not starting it if the process is not running.


To me the real issue it whether or not the script runs correctly regardless of the working directory and regardless of the PATH.
 
Binoy Sankar V.S
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard Tookey wrote:
To me the real issue it whether or not the script runs correctly regardless of the working directory and regardless of the PATH.


Thanks Richard for the help. Now its working fine. The steps which I did to solve the issue is.

1) I copied the xyzMonitor.sh file to the root(regardless of the working directory) which obviously created the a problem like changing the code for the new path for various properties file.
2) Changed the code for new path and redeployed the .jar file.
3) Updated the crontab entry with the new path.

Now the app is automatically started by the crontab if the app is not started. The crontab check is for every 1 min.
The tip which you gave made me think that way which solved the issue.



Many Thanks & Regards,
Binoy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic