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.

4

1 回答 1

1

好吧,我找到了一个 /cron/glassfish (我猜)应该做同样的事情。

正确的。

但仍然没有输出。没有错误..只是清空日志文件。

假设您已将文件正确上传到/opt/glassfish3/temp/myCronJob.sh,我建议您尝试将 cron 输出定向到您自己的日志文件或通过电子邮件将其发送给您:

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

请注意,由于缺少 PTR(反向 DNS)等原因,您的垃圾邮件过滤器可能会过滤电子邮件 - 但可以像这样用于测试/调试目的(只是不要依赖这些邮件通过任何事情批判的!)

如果这些提示对您没有帮助,那么我建议联系您的托管服务提供商的支持团队以验证 .sh 文件的权限、手动执行时的输出以及 cron 日志文件的内容(所有这些只有他们可以帮助您)。

于 2014-03-05T17:47:21.820 回答