I\'m trying to run the following command after the container is up and running.
php artisan queue:work -n -q &
The \"&\" is there b
If you need graceful shutdown for queue, you can follow this.
This is taken from @Paul Redmond's article at Laravel News and extending his docker-entrypoint file so suite my need. After a lot of testing for graceful shutdown I finally was able to do.
First thing in docker-compose.yml file set stop_signal: SIGTERM
for your queue service.
queue:
image: laravel-www
container_name: laravel-queue
stop_signal: SIGTERM
depends_on:
- app
volumes:
- .:/var/www/html
...
Next in the entrypoint.sh file, the main thing is to run the queue:work using the exec
command.
#!/usr/bin/env bash
set -e
# Run our defined exec if args empty
if [ -z "$1" ]; then
role=${CONTAINER_ROLE:-app}
env=${APP_ENV:-production}
if [ "$env" != "local" ]; then
echo "Caching configuration..."
(cd /var/www/html && php artisan cache:clear && php artisan config:clear && php artisan route:clear && php artisan view:clear)
(cd /var/www/html && php artisan config:cache && php artisan event:cache && php artisan route:cache && php artisan view:cache)
fi
if [ "$role" = "app" ]; then
echo "Running PHP-FPM..."
exec php-fpm
elif [ "$role" = "queue" ]; then
echo "Running the queue..."
exec php /var/www/html/artisan queue:work -vv --no-interaction --tries=3 --sleep=5 --timeout=300 --delay=10
elif [ "$role" = "cron" ]; then
echo "Running the cron..."
while [ true ]
do
exec php /var/www/html/artisan schedule:run -vv --no-interaction
sleep 60
done
else
echo "Could not match the container role \"$role\""
exit 1
fi
else
exec "$@"
fi
Your are done. Next time you stop queue service, it will stop gracefully and won't wait 10 seconds for SIGKILL
. I think it has to do with the PID 1
thing.