0

I am running a web-application (MyCronTest) on a Glassfish-Server in a Jelastic-Environment. This web-application contains the servlet (/test), that I would like to call regularly with a cron-job.

So I followed this tutorial from the Jelastic docs, but they use Tomcat instead of Glassfish and I am not so sure about the paths and where to put which file...and now I am lost ;)

the servlet
When calling the servlet directly in my browser it prints out the following line to System.out:

test executed at 05/03/2014 15:00

the bash file to execute
I created a bash script called myCronJob.sh and put it in the directory glassfish3/temp:

#!/bin/bash
curl http://myGlassfish.jelastic.dogado.eu/MyCronTest/test;

I tested it of course, it is executable and it works (at least when I execute it on my computer).

the cron event scheduler
according to the tutorial there is a file /cron/tomcat I need to edit. Well, I found a /cron/glassfish which (I am guessing) should do the same.

# IMPORTANT NOTE!
# Please make sure there is a blank line after the last cronjob entry.
*/1 * * * * /opt/glassfish3/temp/myCronJob.sh

I added an empty line at the end, as they told me to. I even tried it with

*/1 * * * * /bin/bash /opt/glassfish3/temp/myCronJob.sh

as they suggested in the tutorial. But still no output. No error.. just empty log files.

Does anyone have an idea what I am missing here? Am I doing something wrong?

Solution / Edit

Thanks to Damien's Answer I was finally able to narrow down my problem. It was actually the line in my bash-script that caused the problem:

curl http://myGlassfish.jelastic.dogado.eu/MyCronTest/test;

should have been

curl http://localhost/MyCronTest/test;

since I was blocked by a firewall. Lucky for me, my Glassfish is running on the same machine / environment, so localhost works.
Everything else is correct.

Community
  • 1
  • 1
GameDroids
  • 5,584
  • 6
  • 40
  • 59
  • Does `/bin/bash /opt/glassfish3/temp/myCronJob.sh` alone work to you or, in fact, to the user to whom you added the crontab? – fedorqui Mar 05 '14 at 14:53
  • to be honest I am not sure. I set the permissions of `myCronJob.sh` so that everyone can read it. It says it is owned by user 700 and group 700, as do all the files in the `temp` directory. And I cannot see any possibility to add or change any users on Jelastic for that matter. – GameDroids Mar 05 '14 at 15:08
  • Do you mean owned by the user "700", or are the permissions 700? ie `rwx------` If the latter, then try changing the permissions to 755 using `chmod 755 /opt/glassfish3/temp/myCronJob.sh` to allow other uses to read and execute the file. – Josh Jolly Mar 05 '14 at 15:21
  • I meant user "700" (who ever that is). But I did what you said with `chmod 755`.. although it didn't change anything. I only have ftp-access and can't fiddle around with ssh. But as far as I know the permissions are not changed when I copy the file via ftp – GameDroids Mar 05 '14 at 15:25

1 Answers1

1

Well, I found a /cron/glassfish which (I am guessing) should do the same.

Correct.

But still no output. No error.. just empty log files.

Assuming that you have correctly uploaded your file to /opt/glassfish3/temp/myCronJob.sh, I recommend that you try to direct the cron output to your own log file or email it to you:

MAILTO="your@email.com"
*/1 * * * * /opt/glassfish3/temp/myCronJob.sh 2&1 > /opt/glassfish3/glassfish/nodes/localhost-domain1/instance-168458181/logs/cronoutput.log

Note that the email may be filtered by your spam filters due to things like missing PTR (reverse DNS) and so on - but it's ok to use like this for testing/debugging purposes (just don't rely on these mails getting through for anything critical!)

If these tips don't help you, then I recommend contacting your hosting provider's support team to verify the .sh file's permissions, output when executed manually, and the cron log file contents (all of which only they can help you with).

Damien - Layershift
  • 1,508
  • 8
  • 15
  • thanks for your help! it's still not working as I expect it to, but at least an empty `cronoutput.log` was created.. so the crons work. I just have to figure out why the bash-script isn't working. But I already feel closer to a solution, thanks :) – GameDroids Mar 05 '14 at 20:47
  • even the bash-script works!!! just `curl` isn't working ... now I'm feeling really stupid ;) – GameDroids Mar 05 '14 at 20:54
  • @GameDroids did you manage to solve the problem with `curl` or is that bit still outstanding? (if curl is still unsolved, post a new question with details...) – Damien - Layershift Mar 06 '14 at 18:16
  • 1
    Yes, I did! `Curl` can't communicate with other addresses but `localhost` (firewall, I guess). So I changed it and now it works perfectly. So thanks again, for your answer. It brought me on the right path - now, I know how to write logs from crontab and I don't even have to use the bash-script anymore :) – GameDroids Mar 06 '14 at 21:54