From 004807aa32ba67842d40745f53a31d6f45989ebb Mon Sep 17 00:00:00 2001 From: James Cole Date: Sat, 18 Aug 2018 14:08:28 +0200 Subject: [PATCH] Update cron file, use supervisor. --- .deploy/docker/cronjob.conf | 11 +++++++++++ .deploy/docker/crontab | 1 - .deploy/docker/entrypoint.sh | 4 +--- .deploy/docker/firefly-iii.conf | 6 ++++++ .deploy/docker/supervisord.conf | 30 ++++++++++++++++++++++++++++++ Dockerfile | 19 ++++++++++++++----- app/Console/Kernel.php | 32 +++++++++++++++++--------------- 7 files changed, 79 insertions(+), 24 deletions(-) create mode 100644 .deploy/docker/cronjob.conf delete mode 100644 .deploy/docker/crontab create mode 100644 .deploy/docker/firefly-iii.conf create mode 100644 .deploy/docker/supervisord.conf diff --git a/.deploy/docker/cronjob.conf b/.deploy/docker/cronjob.conf new file mode 100644 index 0000000000..71aacd84eb --- /dev/null +++ b/.deploy/docker/cronjob.conf @@ -0,0 +1,11 @@ +[program:cron] +command=/usr/sbin/cron -f -L 15 +user=root +autostart=true +autorestart=true +stdout_events_enabled=true +stderr_events_enabled=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 +startsecs=10 +startretries=3 diff --git a/.deploy/docker/crontab b/.deploy/docker/crontab deleted file mode 100644 index a039a6bc84..0000000000 --- a/.deploy/docker/crontab +++ /dev/null @@ -1 +0,0 @@ -* * * * * root /artisan schedule:run >> /var/log/cron.log diff --git a/.deploy/docker/entrypoint.sh b/.deploy/docker/entrypoint.sh index 3e419fd2eb..ff808c1990 100755 --- a/.deploy/docker/entrypoint.sh +++ b/.deploy/docker/entrypoint.sh @@ -26,6 +26,4 @@ cat .env.docker | envsubst > .env composer dump-autoload php artisan package:discover php artisan firefly:instructions install -service rsyslog start -service cron start -exec apache2-foreground +exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf --nodaemon \ No newline at end of file diff --git a/.deploy/docker/firefly-iii.conf b/.deploy/docker/firefly-iii.conf new file mode 100644 index 0000000000..5ee1c2eb28 --- /dev/null +++ b/.deploy/docker/firefly-iii.conf @@ -0,0 +1,6 @@ +[program:apache2] +command=/bin/bash -c "source /etc/apache2/envvars && exec /usr/sbin/apache2 -DFOREGROUND" +stdout_events_enabled=true +stderr_events_enabled=true +stdout_logfile=/dev/stdout +stdout_logfile_maxbytes=0 \ No newline at end of file diff --git a/.deploy/docker/supervisord.conf b/.deploy/docker/supervisord.conf new file mode 100644 index 0000000000..479120ed38 --- /dev/null +++ b/.deploy/docker/supervisord.conf @@ -0,0 +1,30 @@ +# supervisor config file +# Adapted from the config file distributed with the supervisor package on Debian +# Jessie + +# Enable supervisord in non-daemon mode. Disable the logfile as we receive +# log messages via stdout/err. Set up the child process log directory in case +# the user doesn't set logging to stdout/err. +[supervisord] +nodaemon = true +logfile = NONE +pidfile = /var/run/supervisord.pid +childlogdir = /var/log/supervisor +loglevel=debug + +# Enable supervisorctl via RPC interface over Unix socket +[unix_http_server] +file = /var/run/supervisor.sock +chmod = 0700 + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +[supervisorctl] +serverurl = unix:///var/run/supervisor.sock + + +# Include conf files for child processes +# Debian/Ubuntu packages use /etc/supervisor/conf.d +[include] +files = /etc/supervisor/conf.d/*.conf \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index f9cf575904..06c3345ca7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,12 +20,15 @@ RUN apt-get update -y && \ libedit-dev \ libtidy-dev \ libxml2-dev \ + unzip \ libsqlite3-dev \ + nano \ libpq-dev \ libbz2-dev \ gettext-base \ cron \ rsyslog \ + supervisor \ locales && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* @@ -50,12 +53,18 @@ RUN cd /tmp && \ # Make sure that libcurl is using the newer curl libaries RUN echo "/usr/local/lib" >> /etc/ld.so.conf.d/00-curl.conf && ldconfig -# Create the log file to be able to run tail -RUN touch /var/log/cron.log +# Mimic the Debian/Ubuntu config file structure for supervisor +COPY .deploy/docker/supervisord.conf /etc/supervisor/supervisord.conf +RUN mkdir -p /etc/supervisor/conf.d /var/log/supervisor -# Setup cron job -COPY .deploy/docker/crontab /etc/cron.d/crontab -RUN chmod 0644 /etc/cron.d/crontab +# copy Firefly III supervisor conf file. +COPY ./.deploy/docker/firefly-iii.conf /etc/supervisor/conf.d/firefly-iii.conf + +# copy cron job supervisor conf file. +COPY ./.deploy/docker/cronjob.conf /etc/supervisor/conf.d/cronjob.conf + +# test crons added via crontab +RUN echo "0 3 * * * cd /var/www/firefly-iii && php artisan firefly:cron >> /dev/stdout 2>&1" | crontab - # Install PHP exentions. RUN docker-php-ext-install -j$(nproc) gd intl tidy zip bcmath pdo_mysql bz2 pdo_pgsql diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 1e4f9eb172..250b83f5bc 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -24,10 +24,9 @@ declare(strict_types=1); namespace FireflyIII\Console; -use Carbon\Carbon; -use FireflyIII\Jobs\CreateRecurringTransactions; use Illuminate\Console\Scheduling\Schedule; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; +use Log; /** * File to make sure commands work. @@ -52,18 +51,21 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule): void { - $schedule->call(function() { - echo "\n"; - echo '------------'; - echo "\n"; - echo wordwrap('Firefly III no longer users the Laravel scheduler to do cron jobs! Please read the instructions here:'); - echo "\n"; - echo 'https://firefly-iii.readthedocs.io/en/latest/'; - echo "\n\n"; - echo 'Disable this cron job!'; - echo "\n"; - echo '------------'; - echo "\n"; - })->everyMinute(); + $schedule->call( + function () { + Log::error('Firefly III no longer users the Laravel scheduler to do cron jobs! Please read the instructions at https://firefly-iii.readthedocs.io/en/latest/'); + echo "\n"; + echo '------------'; + echo "\n"; + echo wordwrap('Firefly III no longer users the Laravel scheduler to do cron jobs! Please read the instructions here:'); + echo "\n"; + echo 'https://firefly-iii.readthedocs.io/en/latest/'; + echo "\n\n"; + echo 'Disable this cron job!'; + echo "\n"; + echo '------------'; + echo "\n"; + } + )->everyMinute(); } }