From a1bda23cd91538db5c0386b597c6f07c92c179d0 Mon Sep 17 00:00:00 2001 From: Lan Phan Date: Tue, 8 Jan 2019 14:30:53 +0700 Subject: [PATCH] add new conf example file to run laravel scheduler in php-worker (#1930) --- DOCUMENTATION/content/documentation/index.md | 53 +++++++++++-------- .../laravel-scheduler.conf.example | 8 +++ 2 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 php-worker/supervisord.d/laravel-scheduler.conf.example diff --git a/DOCUMENTATION/content/documentation/index.md b/DOCUMENTATION/content/documentation/index.md index 38337d8b..725d4ae8 100644 --- a/DOCUMENTATION/content/documentation/index.md +++ b/DOCUMENTATION/content/documentation/index.md @@ -532,29 +532,8 @@ phpunit ## Run Laravel Queue Worker -1 - First add `php-worker` container. It will be similar as like PHP-FPM Container. -
-a) open the `docker-compose.yml` file -
-b) add a new service container by simply copy-paste this section below PHP-FPM container +1 - Create supervisor configuration file (for ex., named `laravel-worker.conf`) for Laravel Queue Worker in `php-worker/supervisord.d/` by simply copy from `laravel-worker.conf.example` -```yaml - php-worker: - build: - context: ./php-worker - args: - - INSTALL_PGSQL=${PHP_WORKER_INSTALL_PGSQL} #Optionally install PGSQL PHP drivers - - INSTALL_BCMATH=${PHP_WORKER_INSTALL_BCMATH} #Optionally install BCMath php package - - INSTALL_SOAP=${PHP_WORKER_INSTALL_SOAP} #Optionally install Soap php package - volumes_from: - - applications - depends_on: - - workspace - extra_hosts: - - "dockerhost:${DOCKER_HOST_IP}" - networks: - - backend -``` 2 - Start everything up ```bash @@ -566,6 +545,34 @@ docker-compose up -d php-worker +
+ +## Run Laravel Scheduler + +Laradock provides 2 ways to run Laravel Scheduler +1 - Using cron in workspace container. Most of the time, when you start Laradock, it'll automatically start workspace container with cron inside, along with setting to run `schedule:run` command every minute. + +2 - Using Supervisord in php-worker to run `schedule:run`. This way is suggested when you don't want to start workspace in production environment. +
+a) Comment out cron setting in workspace container, file `workspace/crontab/laradock` + +```bash +# * * * * * laradock /usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1 +``` +
+b) Create supervisor configuration file (for ex., named `laravel-scheduler.conf`) for Laravel Scheduler in `php-worker/supervisord.d/` by simply copy from `laravel-scheduler.conf.example` +
+c) Start php-worker container + +```bash +docker-compose up -d php-worker +``` + + + + + +
## Use Mailu @@ -1198,7 +1205,7 @@ We also recommend [setting the timezone in Laravel](http://www.camroncade.com/ma You can add your cron jobs to `workspace/crontab/root` after the `php artisan` line. ``` -* * * * * php /var/www/artisan schedule:run >> /dev/null 2>&1 +* * * * * laradock /usr/bin/php /var/www/artisan schedule:run >> /dev/null 2>&1 # Custom cron * * * * * root echo "Every Minute" > /var/log/cron.log 2>&1 diff --git a/php-worker/supervisord.d/laravel-scheduler.conf.example b/php-worker/supervisord.d/laravel-scheduler.conf.example new file mode 100644 index 00000000..0e83f878 --- /dev/null +++ b/php-worker/supervisord.d/laravel-scheduler.conf.example @@ -0,0 +1,8 @@ +[program:laravel-scheduler] +process_name=%(program_name)s_%(process_num)02d +command=/bin/sh -c "while [ true ]; do (php /var/www/artisan schedule:run --verbose --no-interaction &); sleep 60; done" +autostart=true +autorestart=true +numprocs=1 +user=laradock +redirect_stderr=true