Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cron job not running #27

Closed
kasperg opened this issue Apr 27, 2018 · 3 comments
Closed

Cron job not running #27

kasperg opened this issue Apr 27, 2018 · 3 comments

Comments

@kasperg
Copy link

kasperg commented Apr 27, 2018

Thanks for sharing this. I wanted to try this out for a project but I am having problems getting cron jobs working.

Expected Behavior

When I set CRON_COMMAND and CRON_SCHEDULE I expect the command to be executed as define by the schedule.

Current Behavior

When these commands are set the /etc/cron.d/generated_crontab file seems to be generated as expected but as far as I can tell the command is not executed.

I cannot tell why. Some form of logging might be helpful if possible.

Steps to Reproduce (for bugs)

  1. Create a docker-compose.yml file:
version: '3'
services:
  my_app:
    image: thecodingmachine/php:7.2-v1-apache
    environment:
      CRON_SCHEDULE: '* * * * *'
      CRON_COMMAND: 'php -r "echo time();"'
  1. Start the service docker-compose up
  2. Notice the output from Apache startup sequence in the output as expected
22:42 $ docker-compose up
Creating network "tmp_default" with the default driver
Creating tmp_my_app_1 ... done
Attaching to tmp_my_app_1
my_app_1  | [Fri Apr 27 20:42:16.690672 2018] [mpm_prefork:notice] [pid 8] AH00163: Apache/2.4.25 (Debian) PHP/7.2.4 configured -- resuming normal operations
my_app_1  | [Fri Apr 27 20:42:16.690749 2018] [core:notice] [pid 8] AH00094: Command line: 'apache2 -D FOREGROUND'
  1. I had expected there to be timestamps from the cron job in the output
  2. In another terminal run docker-compose exec my_app cat /etc/cron.d/generated_crontab. Output seems sensible enough

* * * * * root (php -r "echo time();") | sed -e 's/^/[Cron] /' > /proc/7/fd/1 2>/proc/7/fd/2

Your Environment

  • Version used: php:7.2-v1-apache and php:7.2-v1-cli
  • Operating System and version: OSX 10.13.4 + Docker for Mac 18.03.0-ce-mac60 (23751)
@kasperg
Copy link
Author

kasperg commented Apr 27, 2018

My original case turned out not to be working for a number of other reasons which caused the cron job to fail so I am closing this.

A lesson from this could perhaps be to make it easier to get error output from cron into the docker logs.

@kasperg kasperg closed this as completed Apr 27, 2018
@moufmouf
Copy link
Member

Hey @kasperg !

I'm reopening your issue. I wrote a quick test and it seems indeed that output from cron is sent to docker logs, but not errors from cron.

I'll look into it.

@moufmouf moufmouf reopened this Apr 30, 2018
moufmouf added a commit to moufmouf/docker-images-php that referenced this issue Apr 30, 2018
@moufmouf
Copy link
Member

Ok, this was not as easy to solve as I had expected (https://github.com/thecodingmachine/docker-images-php/pull/28/files#diff-3799b1f42986a8b0c3012d9bbb330537R28), but that's solved.

Thanks for sharing your issue and taking the time to give some feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants