From a48860660cfee196075deaf9e218303e6c2e5e7e Mon Sep 17 00:00:00 2001 From: Martin Date: Fri, 16 Dec 2022 15:38:25 +0100 Subject: [PATCH 1/7] Fixed CRON container outputs logs into docker properly --- crontab/crontab | 18 ++++++++++++++---- docker-compose.simple-install.yml | 7 ++----- docker-cron-entrypoint.sh | 10 ++++++++-- docker-entrypoint.sh | 2 +- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/crontab/crontab b/crontab/crontab index 906a7b7..7b8a8c9 100644 --- a/crontab/crontab +++ b/crontab/crontab @@ -1,5 +1,15 @@ -@hourly export $(cat /var/www/docker.env) && /bin/sh /var/www/eramba/app/upgrade/bin/cake cron job hourly >> /var/log/cron.log 2>&1 -@daily export $(cat /var/www/docker.env) && /bin/sh /var/www/eramba/app/upgrade/bin/cake cron job daily >> /var/log/cron.log 2>&1 -@yearly export $(cat /var/www/docker.env) && /bin/sh /var/www/eramba/app/upgrade/bin/cake cron job yearly >> /var/log/cron.log 2>&1 -* * * * * export $(cat /var/www/docker.env) && /bin/sh /var/www/eramba/app/upgrade/bin/cake queue run -v >> /var/log/cron.log 2>&1 +# Example of job definition: +# .---------------- minute (0 - 59) +# | .------------- hour (0 - 23) +# | | .---------- day of month (1 - 31) +# | | | .------- month (1 - 12) OR jan,feb,mar,apr ... +# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat +# | | | | | +# * * * * * user-name command to be executed + +@hourly su -s /bin/bash -c "/var/www/eramba/app/upgrade/bin/cake cron job hourly" www-data >/proc/1/fd/1 2>/proc/1/fd/2 +@daily su -s /bin/bash -c "/var/www/eramba/app/upgrade/bin/cake cron job daily" www-data >/proc/1/fd/1 2>/proc/1/fd/2 +@yearly su -s /bin/bash -c "/var/www/eramba/app/upgrade/bin/cake cron job yearly" www-data >/proc/1/fd/1 2>/proc/1/fd/2 +* * * * * su -s /bin/bash -c "/var/www/eramba/app/upgrade/bin/cake queue run -v" www-data >/proc/1/fd/1 2>/proc/1/fd/2 + # remember to end this file with an empty new line diff --git a/docker-compose.simple-install.yml b/docker-compose.simple-install.yml index b6efda5..11b6bb7 100644 --- a/docker-compose.simple-install.yml +++ b/docker-compose.simple-install.yml @@ -31,7 +31,6 @@ services: - ./apache/ssl/mycert.crt:/etc/ssl/certs/mycert.crt - ./apache/ssl/mycert.key:/etc/ssl/private/mycert.key - ./apache/vhost-ssl.conf:/etc/apache2/sites-available/000-default.conf - - ./crontab/crontab:/etc/cron.d/eramba-crontab environment: DB_HOST: ${DB_HOST} DB_DATABASE: ${DB_DATABASE} @@ -52,16 +51,14 @@ services: cron: container_name: cron image: ghcr.io/eramba/eramba:latest - command: ["cron", "-f"] - entrypoint: ["/docker-cron-entrypoint.sh"] + command: ["cron", "-f", "-L", "2"] restart: always volumes: - data:/var/www/eramba/app/upgrade/data - app:/var/www/eramba - logs:/var/www/eramba/app/upgrade/logs - - ./docker-cron-entrypoint.sh:/docker-cron-entrypoint.sh + - ./docker-cron-entrypoint.sh:/docker-entrypoint.sh - ./crontab/crontab:/etc/cron.d/eramba-crontab - - .env:/var/www/docker.env environment: DB_HOST: ${DB_HOST} DB_DATABASE: ${DB_DATABASE} diff --git a/docker-cron-entrypoint.sh b/docker-cron-entrypoint.sh index 43f9fb4..90b66db 100755 --- a/docker-cron-entrypoint.sh +++ b/docker-cron-entrypoint.sh @@ -1,5 +1,11 @@ #!/bin/sh -su -s /bin/bash -c "crontab -u www-data /etc/cron.d/eramba-crontab" www-data +env >> /etc/environment -exec docker-php-entrypoint "$@" +crontab -u root /etc/cron.d/eramba-crontab + +su -s /bin/bash -c "php /var/www/eramba/app/upgrade/bin/cake.php queue worker end all" www-data + +# execute CMD +echo "$@" +exec "$@" diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 54823a4..fac8e0b 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -10,7 +10,7 @@ su -s /bin/bash -c "rsync -rv app/upgrade/data_template/ app/upgrade/data/" www- # when deploying a code or DB migration change and you want the "old workers" based on the old code # to not process any new incoming jobs after deployment. -su -s /bin/bash -c "php app/upgrade/bin/cake.php queue worker end all -q" www-data +#su -s /bin/bash -c "php app/upgrade/bin/cake.php queue worker end all -q" www-data # Lets activate maintenance mode #su -s /bin/bash -c "php app/upgrade/bin/cake.php setup.maintenance_mode activate" www-data From 190f32a57ef9cc16d350ecaba03997af124863cb Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 31 Dec 2022 14:57:42 +0100 Subject: [PATCH 2/7] Rsync logs_template folder to logs --- docker-entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index fac8e0b..cabc3de 100644 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -8,6 +8,9 @@ su -s /bin/bash -c "php composer.phar run-script post-install-cmd --no-interacti # syncing dir structure into /data folder from /data_template su -s /bin/bash -c "rsync -rv app/upgrade/data_template/ app/upgrade/data/" www-data +# syncing dir structure into /logs folder from /logs_template +su -s /bin/bash -c "rsync -rv app/upgrade/logs_template/ app/upgrade/logs/" www-data + # when deploying a code or DB migration change and you want the "old workers" based on the old code # to not process any new incoming jobs after deployment. #su -s /bin/bash -c "php app/upgrade/bin/cake.php queue worker end all -q" www-data From 3c2337de071fb5740bcee1ccf6dba0736e21d796 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 31 Dec 2022 14:57:52 +0100 Subject: [PATCH 3/7] cron entrypoint runs post-install-cmd --- docker-cron-entrypoint.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docker-cron-entrypoint.sh b/docker-cron-entrypoint.sh index 90b66db..cc7f1ab 100755 --- a/docker-cron-entrypoint.sh +++ b/docker-cron-entrypoint.sh @@ -4,6 +4,9 @@ env >> /etc/environment crontab -u root /etc/cron.d/eramba-crontab +# Run Post Install CMD to generate app_local.php file with unique SALT and other defaults. +su -s /bin/bash -c "php /var/www/eramba/composer.phar run-script post-install-cmd --working-dir=/var/www/eramba --no-interaction" www-data + su -s /bin/bash -c "php /var/www/eramba/app/upgrade/bin/cake.php queue worker end all" www-data # execute CMD From 1fe99d70b8cbc6ce477dcba7725b6dacee758211 Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 31 Dec 2022 14:58:00 +0100 Subject: [PATCH 4/7] mount latest entrypoint --- docker-compose.simple-install.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.simple-install.yml b/docker-compose.simple-install.yml index 11b6bb7..95568e1 100644 --- a/docker-compose.simple-install.yml +++ b/docker-compose.simple-install.yml @@ -31,6 +31,7 @@ services: - ./apache/ssl/mycert.crt:/etc/ssl/certs/mycert.crt - ./apache/ssl/mycert.key:/etc/ssl/private/mycert.key - ./apache/vhost-ssl.conf:/etc/apache2/sites-available/000-default.conf + - ./docker-entrypoint.sh:/docker-entrypoint.sh environment: DB_HOST: ${DB_HOST} DB_DATABASE: ${DB_DATABASE} From 87527496fa7979e9c8f067ba9262d5867f162532 Mon Sep 17 00:00:00 2001 From: Martin Date: Sun, 1 Jan 2023 13:35:24 +0100 Subject: [PATCH 5/7] Removed `www-data` crontab In case someone is updating from previous docker versions --- docker-cron-entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-cron-entrypoint.sh b/docker-cron-entrypoint.sh index cc7f1ab..14cdc29 100755 --- a/docker-cron-entrypoint.sh +++ b/docker-cron-entrypoint.sh @@ -2,6 +2,7 @@ env >> /etc/environment +crontab -u www-data -r crontab -u root /etc/cron.d/eramba-crontab # Run Post Install CMD to generate app_local.php file with unique SALT and other defaults. From 2325d1e9aa0af26965fc23adfcb3b222a06ae8fa Mon Sep 17 00:00:00 2001 From: Martin Date: Thu, 5 Jan 2023 10:29:34 +0100 Subject: [PATCH 6/7] File permissions --- docker-entrypoint.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 docker-entrypoint.sh diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh old mode 100644 new mode 100755 From 3430999435ee02aceb08c4f4775ab582a1d13c71 Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 7 Feb 2023 13:33:00 +0100 Subject: [PATCH 7/7] Configured CRON entrypoint individually Configured CRON entrypoint individually and not as a mounted replacement of `docker-entrypoint.sh` file --- docker-compose.simple-install.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker-compose.simple-install.yml b/docker-compose.simple-install.yml index 95568e1..2a9fced 100644 --- a/docker-compose.simple-install.yml +++ b/docker-compose.simple-install.yml @@ -53,12 +53,13 @@ services: container_name: cron image: ghcr.io/eramba/eramba:latest command: ["cron", "-f", "-L", "2"] + entrypoint: ["/docker-cron-entrypoint.sh"] restart: always volumes: - data:/var/www/eramba/app/upgrade/data - app:/var/www/eramba - logs:/var/www/eramba/app/upgrade/logs - - ./docker-cron-entrypoint.sh:/docker-entrypoint.sh + - ./docker-cron-entrypoint.sh:/docker-cron-entrypoint.sh - ./crontab/crontab:/etc/cron.d/eramba-crontab environment: DB_HOST: ${DB_HOST}