Crontab

General PhidgetSBC Discussion.
NDLBoard
Phidgetsian
Posts: 6
Joined: Sat May 04, 2013 12:32 pm
Contact:

Crontab

Postby NDLBoard » Sat May 04, 2013 1:09 pm

Good evening,

I am using my phidget SBC to manage the heating and the double-flow ventilation system of my house (in France - sorry for my not very accurate English).
I am very happy with my SBC, all my programs are written in Java, they are .jar launched at the booting of the SBC.
There are 3 projects:
- one managing the heating (towards the 8 8 8 phidget of the SBC)
- one managing the ventilation (towards one more 8 8 8 phidgets connected to the SBC via USB)
- one that allow me to drive the system from anywhere and that send me an email in case of any misfunction (towards the wire internet connection of the SBC)
The two first programs are very stable, they have been running for months without any problem (at the end I noticed the SBC was very slow when connecting with the web interface, so I rebooted it and it was OK for another couple of months)
The last program is crashing after a non determinated amount of time (between 5 minuts and a week), pheraps because this program is too heavy, peraphs due to a memory leak, I did not managed to fix it.

That is why I am trying to launch it via crontab each hour, and to make it die after one hour of work (if it has not already crashed before by itself....)

I have tried a lot of crontab commands, none is working.

My program is located from sbc root:
/usr/userapps/DataLink/DataLink.jar

The crontab file I edited is the one located:
/etc/crontab

In which I added the line:
00 * * * * root java -jar /usr/userapps/DataLink/DataLink.jar

Will really appreciate any help!
Best regards

User avatar
Patrick
Lead Developer
Posts: 3157
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Crontab

Postby Patrick » Mon May 06, 2013 9:35 am

I usually create a shell script for cron to run, and then start my program from there. I'm not sure how happy cron is with command line arguments like you have. Also, the PATH may not be set. 1st try specifying the full path to java, otherwise, create a shell script.

Also, you will probably want to verify that the program isn't running before starting another instance - something else you can do in a shell script.

-Patrick

User avatar
Patrick
Lead Developer
Posts: 3157
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Crontab

Postby Patrick » Mon May 06, 2013 10:35 am

Also, look into supervise from daemontools.

-Patrick

NDLBoard
Phidgetsian
Posts: 6
Joined: Sat May 04, 2013 12:32 pm
Contact:

Re: Crontab

Postby NDLBoard » Tue May 07, 2013 3:59 pm

Thanks Patrick for your answer,

I have tried to do what you suggested to me,
but I am not familiar with shell scripts and I did not managed to launch my .jar

I added to /etc/crontab the line:
00 * * * * root /usr/userapps/DataLink/DataLinkScript.sh

I added the file DataLinkScript.sh in my project directory, this file contains:
#!/bin/sh
/usr/lib/jvm/default-java/jre/bin/java -jar DataLink.jar

(NB: I modified my program to make it die after 1 hour work to avoid 2 instances to execute at the same time, I will study your suggestion of supervise later on)

The System Log show a crontab exit code 126: Command cannot execute
I think it may be due to a syntax problem but I do not manage to fix it

Thank you for your help!

User avatar
Patrick
Lead Developer
Posts: 3157
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Crontab

Postby Patrick » Tue May 07, 2013 4:49 pm

ok, other then this, you will need to make your script executable with 'chmod 755'

You also should deamonize the java program with &, unless it daemonizes itself:

Code: Select all

#!/bin/sh
/usr/lib/jvm/default-java/jre/bin/java -jar DataLink.jar &

-Patrick

NDLBoard
Phidgetsian
Posts: 6
Joined: Sat May 04, 2013 12:32 pm
Contact:

Re: Crontab

Postby NDLBoard » Tue May 21, 2013 10:28 pm

Thank you Patrick for your help,

I did the chmod as you suggested so as to compil the shell script,
it worked: there is no more system log error code after the crontab execution,

unfortunately, my programm is not launched...
my shell script is located in my project directory and contains:

#!/bin/sh
/usr/lib/jvm/default-java/jre/bin/java -jar DataLink.jar &

I guess that crontab is properly launching the script (as the error code disappeared),
I probably have a wrong classpath in my shell script,
I have tried a lot of possibilities, but with no result,

I you have any idea...

Thanks


Return to “General”

Who is online

Users browsing this forum: No registered users and 3 guests