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

Implement persistent/reliable cron service using supervisor. #1041

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compose/bin/cli
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
bin/docker-compose exec phpfpm "$@"
bin/docker-compose exec -u app phpfpm "$@"
2 changes: 1 addition & 1 deletion compose/bin/clinotty
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash
[ -z "$1" ] && echo "Please specify a CLI command (ex. ls)" && exit
# -T: Disable pseudo-tty allocation
bin/docker-compose exec -T phpfpm "$@"
bin/docker-compose exec -u app -T phpfpm "$@"
4 changes: 2 additions & 2 deletions compose/bin/cron
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env bash
[ -z "$1" ] && echo "Please specify a service operation (start|stop|status|restart|reload|force-reload)" && exit
bin/root service cron "$@"
[ -z "$1" ] && echo "Please specify a service operation (start|stop|status|restart)" && exit
bin/root supervisorctl "$@" cron
bin/root touch /var/www/html/var/.setup_cronjob_status /var/www/html/var/.update_cronjob_status
bin/root chown app:app /var/www/html/var/.setup_cronjob_status /var/www/html/var/.update_cronjob_status
1 change: 1 addition & 0 deletions compose/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
phpfpm:
image: markoshust/magento-php:8.2-fpm-0
volumes: *appvolumes
tty: true
env_file: env/phpfpm.env
#extra_hosts: *appextrahosts

Expand Down
1 change: 1 addition & 0 deletions compose/env/phpfpm.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ BLACKFIRE_CLIENT_TOKEN=
COMPOSER_DISABLE_XDEBUG_WARN=1
PHP_CS_FIXER_IGNORE_ENV=1
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
START_CRON=true
10 changes: 8 additions & 2 deletions images/php/8.2/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ MAINTAINER Mark Shust <mark@shust.com>

ARG APP_ID=1000
RUN groupadd -g "$APP_ID" app \
&& useradd -g "$APP_ID" -u "$APP_ID" -d /var/www -s /bin/bash app
&& useradd -g "$APP_ID" -G tty -u "$APP_ID" -d /var/www -s /bin/bash app

RUN mkdir -p /etc/nginx/html /var/www/html /sock \
&& chown -R app:app /etc/nginx /var/www /usr/local/etc/php/conf.d /sock
Expand Down Expand Up @@ -34,8 +34,10 @@ RUN apt-get update && apt-get install -y \
msmtp \
nodejs \
procps \
tini \
vim \
zip \
supervisor \
&& rm -rf /var/lib/apt/lists/*

RUN pecl channel-update pecl.php.net && pecl install \
Expand Down Expand Up @@ -91,7 +93,11 @@ COPY conf/msmtprc /etc/msmtprc
COPY conf/php.ini $PHP_INI_DIR
COPY conf/php-fpm.conf /usr/local/etc/
COPY conf/www.conf /usr/local/etc/php-fpm.d/
COPY conf/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# using tini as PID 1 instead of supervisor eliminates the scary but harmless "reaped unknown pid XX" message each time cron runs
ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]


USER app:app
VOLUME /var/www
WORKDIR /var/www/html
5 changes: 2 additions & 3 deletions images/php/8.2/conf/php-fpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@

[global]

error_log = /proc/self/fd/2
error_log = /dev/console
daemonize = no

[www]

; if we send this to /proc/self/fd/1, it never appears
access.log = /proc/self/fd/2
access.log = /dev/console

;user = app
;group = app
Expand Down
28 changes: 28 additions & 0 deletions images/php/8.2/conf/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[supervisord]
nodaemon=true
user=root
pidfile=%(here)s/supervisord.pid
logfile=/var/www/html/var/log/supervisord.log

[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[program:php]
command=docker-php-entrypoint /usr/local/sbin/php-fpm
user=app

[program:cron]
command=bash -c 'su - app bash -c "/usr/local/bin/php /var/www/html/bin/magento cron:install"; exec /usr/sbin/cron -f'
autostart=%(ENV_START_CRON)s
stdout_logfile=/dev/console
stdout_logfile_maxbytes=0
stderr_logfile=/dev/console
stderr_logfile_maxbytes=0