Skip to content

Instantly share code, notes, and snippets.

@WRonX
Created January 11, 2023 13:09
Show Gist options
  • Save WRonX/b1d39bf097b5139c49d21cf000e0f845 to your computer and use it in GitHub Desktop.
Save WRonX/b1d39bf097b5139c49d21cf000e0f845 to your computer and use it in GitHub Desktop.
Running Laravel scheduler on Azure environment

Introduction

This is just an add-on to running queue worker on Azure. If you want to run scheduler, first you need to get familiar with that document and fullfill the environment file update requirement for Supervisor (in the document above it's done by adding EnvGenerate command and running it on startup). After that, you need to create Supervisor configuration and run it on startup.

⚠️ This is a very poorly tested solution and the stability of it is currently unknown. Use at your own risk.
⚠️ ALSO: this instruction was created for a very specific case, yours is probably different.
⚠️ ALSO ALSO: Laravel's documentation does not encourage running schedule worker on production environments, it rather suggests it was created for local development environments. From my experience it seems to work the same as schedule:run ran from cron, but if you want an expert opinion, ask someone from IT, I am just a humble carpenter.

Supervisor configuration

Add a laravel-scheduler.conf to your project in the main directory. Example working content:

[program:laravel-scheduler]
directory=/home/site/wwwroot
process_name=%(program_name)s_%(process_num)02d
command=php artisan schedule:work
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/home/site/wwwroot/storage/logs/scheduler.log

Changes made, compared to running queue worker:

  • number of processes (numprocs) changed to 1
  • Supervisor won't kill process if it still runs (stopwaitsecs removed)
  • working directory added (Laravel's schedule worker seems to call Artisan every time and without it, it wouldn't find it)

Supervisor installation and App Service config

This is what you need to add at the end of your deployment slot's Startup Command (Configuration->General) if you did not follow all steps from mentioned queue-related document (because you didn't need queue worker, just scheduler). If you need both queue worker and scheduler, you will need to merge the commands (copying config file and running Supervisor program).

&& apt install supervisor -y && cp /home/site/wwwroot/laravel-scheduler.conf /etc/supervisor/conf.d && service supervisor start && supervisorctl reread && supervisorctl update && supervisorctl start laravel-scheduler:*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment