Verify Cron is Running
-
Hello All!
I am using Invision Community, have the cron jobs enabled, and restarted the app. But for some reason it doesn't seem to be running. Is there a way to verify that they're running (or not) and the best way to do that?Thank you!
@jlx89 After you restart the app, in the app logs you should see
==> Imported crontab
. It will also print an error if it could not parse the crontab correctly.For testing, you can put something like this in your crontab:
* * * * * echo "Cron ran at $(date)" >> /app/data/test.txt
Then, after a couple of minutes, I can see in
/app/data/test.txt
:Cron ran at Thu 29 Jul 2021 10:19:01 PM UTC Cron ran at Thu 29 Jul 2021 10:20:01 PM UTC
If the output above does not appear for some reason, maybe you can
systemctl restart box
and wait for sometime to see if that helps. -
@jlx89 After you restart the app, in the app logs you should see
==> Imported crontab
. It will also print an error if it could not parse the crontab correctly.For testing, you can put something like this in your crontab:
* * * * * echo "Cron ran at $(date)" >> /app/data/test.txt
Then, after a couple of minutes, I can see in
/app/data/test.txt
:Cron ran at Thu 29 Jul 2021 10:19:01 PM UTC Cron ran at Thu 29 Jul 2021 10:20:01 PM UTC
If the output above does not appear for some reason, maybe you can
systemctl restart box
and wait for sometime to see if that helps.@girish said in Verify Cron is Running:
-
-
-
-
- echo "Cron ran at $(date)" >> /app/data/test.txt
-
-
-
Thanks! So Cron is running, the output worked going to test.txt. But for some reason it doesn't seem to be running what I have setup. I'm also not seeing any errors in the logs. Is there another way to dig into it to find any issues?
-
-
@girish said in Verify Cron is Running:
-
-
-
-
- echo "Cron ran at $(date)" >> /app/data/test.txt
-
-
-
Thanks! So Cron is running, the output worked going to test.txt. But for some reason it doesn't seem to be running what I have setup. I'm also not seeing any errors in the logs. Is there another way to dig into it to find any issues?
-
-
@jlx89 maybe your specified command simply silently fails right away? How does your crontab line look like?
-
@nebulon I've pasted it below:
1 * * * * /usr/bin/php -d memory_limit=-1 -d max_execution_time=0 /app/data/public/path/to/task/trigger.php {key to run trigger.php}
Thank you!
-
@jlx89 just to double check, I think this pattern would run the command "1 minute after every hour every day" is that what you had in mind?
-
@nebulon Yeah, that is what I was shooting for at the moment. I'll try changing it back to every minute and see if it kicks off again.
So hypothetically, you should see the cron run in the logs, correct?
Thank you!
@jlx89 The cron output has to be redirected to a file, it won't appear in the main application logs. I think it will be useful for the cron command to be able to redirect to main application logs. So, I have pushed an update to the LAMP app to make that possible. I put some notes here on how to do this after the update - https://docs.cloudron.io/apps/lamp/#cron-support.
So, after you update, you can try something like this:
1 * * * * (echo "Trigger is running now"; /usr/bin/php -d memory_limit=-1 -d max_execution_time=0 /app/data/public/path/to/task/trigger.php) > /proc/$(cat /var/run/crond.pid)/fd/1 2>&1
You will see both the echo and any php command output in the main application logs.
-
@jlx89 The cron output has to be redirected to a file, it won't appear in the main application logs. I think it will be useful for the cron command to be able to redirect to main application logs. So, I have pushed an update to the LAMP app to make that possible. I put some notes here on how to do this after the update - https://docs.cloudron.io/apps/lamp/#cron-support.
So, after you update, you can try something like this:
1 * * * * (echo "Trigger is running now"; /usr/bin/php -d memory_limit=-1 -d max_execution_time=0 /app/data/public/path/to/task/trigger.php) > /proc/$(cat /var/run/crond.pid)/fd/1 2>&1
You will see both the echo and any php command output in the main application logs.
@girish said in Verify Cron is Running:
1 * * * * (echo "Trigger is running now"; /usr/bin/php -d memory_limit=-1 -d max_execution_time=0 /app/data/public/path/to/task/trigger.php) > /proc/$(cat /var/run/crond.pid)/fd/1 2>&1
Perfect, thank you so much! That worked out very well!