简体   繁体   中英

Cron Job is not running with supervisor in alpine

I have a problem in my docker container, in local that works well but in production it don't work.

The only problem for my app is the cron job that is not running. I'm using Alpine image where I installed Supervisor, I succeed to make php-fpm working but not cron, also I'm using default alpine cron config who is running every 15 minutes. In the log I see that it was executed, but nothing hapened:

    /srv/app # cat /var/log/cron.log
    crond: crond (busybox 1.35.0) started, log level 8
    crond: USER root pid 757 cmd run-parts /etc/periodic/15min
    crond: USER root pid 1319 cmd run-parts /etc/periodic/15min

there is the provisor file ini:

    ; /etc/supervisor.d/supervisor.ini
    [supervisord]
    nodaemon=true
    
    [include]
    files = /etc/supervisor/conf.d/*.conf
    
    [program:cron]
    command=/usr/sbin/crond -f -l 8 -L /var/log/cron.log
    user=root
    autorestart=true
    
    [program:php-fpm]
    command=docker-php-entrypoint php-fpm
    user = root
    autostart = true
    autorestart = true
    stdout_logfile = /dev/stdout
    stdout_logfile_maxbytes=0
    stderr_logfile = /dev/stderr
    stderr_logfile_maxbytes=0

and the cron action:

    # /etc/periodic/15min

    #!/bin/sh
    echo "Fetch Post started : $(date)"
    php /srv/app/bin/console app:fetch
    echo "Fetch Post finished: $(date)"

but when I execute

    php /srv/app/bin/console app:fetch

manually inside the docker container it's work very well

UPDATE 1:

I checked the cron log and there is the output:

/srv/app # cat /var/log/cron.log
crond: crond (busybox 1.35.0) started, log level 8
crond: USER root pid 757 cmd run-parts /etc/periodic/15min
crond: USER root pid 1319 cmd run-parts /etc/periodic/15min
crond: USER root pid 1863 cmd run-parts /etc/periodic/15min
crond: USER root pid 2402 cmd run-parts /etc/periodic/15min
crond: USER root pid 2403 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 2957 cmd run-parts /etc/periodic/15min
crond: USER root pid 3495 cmd run-parts /etc/periodic/15min
crond: USER root pid 4038 cmd run-parts /etc/periodic/15min
crond: USER root pid 4577 cmd run-parts /etc/periodic/15min
crond: USER root pid 4578 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 5130 cmd run-parts /etc/periodic/15min
crond: USER root pid 5669 cmd run-parts /etc/periodic/15min
crond: USER root pid 6207 cmd run-parts /etc/periodic/15min
crond: USER root pid 6743 cmd run-parts /etc/periodic/15min
crond: USER root pid 6744 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 7294 cmd run-parts /etc/periodic/15min
crond: USER root pid 7837 cmd run-parts /etc/periodic/15min
crond: USER root pid 8374 cmd run-parts /etc/periodic/15min
crond: USER root pid 8914 cmd run-parts /etc/periodic/15min
crond: USER root pid 8915 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 9464 cmd run-parts /etc/periodic/15min
crond: USER root pid 10001 cmd run-parts /etc/periodic/15min
crond: USER root pid 10539 cmd run-parts /etc/periodic/15min
crond: USER root pid 11074 cmd run-parts /etc/periodic/15min
crond: USER root pid 11075 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 11076 cmd run-parts /etc/periodic/daily
run-parts: /etc/periodic/daily: No such file or directory
crond: USER root pid 11638 cmd run-parts /etc/periodic/15min
crond: USER root pid 12175 cmd run-parts /etc/periodic/15min
crond: USER root pid 12712 cmd run-parts /etc/periodic/15min
crond: USER root pid 13250 cmd run-parts /etc/periodic/15min
crond: USER root pid 13251 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 13802 cmd run-parts /etc/periodic/15min
crond: USER root pid 14339 cmd run-parts /etc/periodic/15min
crond: USER root pid 14882 cmd run-parts /etc/periodic/15min
crond: USER root pid 15420 cmd run-parts /etc/periodic/15min
crond: USER root pid 15421 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 15973 cmd run-parts /etc/periodic/15min
crond: USER root pid 16514 cmd run-parts /etc/periodic/15min
crond: USER root pid 17052 cmd run-parts /etc/periodic/15min
crond: USER root pid 17587 cmd run-parts /etc/periodic/15min
crond: USER root pid 17588 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 18138 cmd run-parts /etc/periodic/15min
crond: USER root pid 18682 cmd run-parts /etc/periodic/15min
crond: USER root pid 19220 cmd run-parts /etc/periodic/15min
crond: USER root pid 19757 cmd run-parts /etc/periodic/15min
crond: USER root pid 19758 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 20313 cmd run-parts /etc/periodic/15min
crond: USER root pid 20850 cmd run-parts /etc/periodic/15min
crond: USER root pid 21388 cmd run-parts /etc/periodic/15min
crond: USER root pid 21928 cmd run-parts /etc/periodic/15min
crond: USER root pid 21929 cmd run-parts /etc/periodic/hourly
run-parts: /etc/periodic/hourly: No such file or directory
crond: USER root pid 22481 cmd run-parts /etc/periodic/15min

That's mean the cron job is working very well.

But there is a problem with my run15min.sh file?

# /etc/periodic/15min/run15min.sh
#!/bin/sh
echo "Fetch Post started : $(date)"
php /srv/app/bin/console app:fetch
echo "Fetch Post finished: $(date)"

knowing that it works very well locally!

UPDATE 2:

I tried to execute manually the.sh file inside the container in local that's work but not in production. I got this message:

    /etc/periodic/15min # ./run15min.sh 
    /bin/sh: ./run15min.sh: Permission denied

despite I made the autorization in docker file:

    RUN chmod +x /etc/periodic/15min/run15min.sh 

Regards

I resolved the problem by setting authorisation directly inside the container

    RUN chmod 777 /etc/periodic/15min/run15min.sh 

But I don't think this is the right way

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM