Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

deansatch's avatar

Restart supervisor during deploy?

Can anyone explain to me the best way to keep my queue worker up to date and running as stable as possible?

So for example I have a worker that runs order confirmations which are queued via the database. I have noticed if I make a change to my job scripts whilst the worker is running I have to restart it before it will see those changes.

My worker conf file is pretty simple:


[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/current/artisan queue:work --sleep=10 --tries=6 --daemon
autostart=true
autorestart=true
user=root
numprocs=3
redirect_stderr=true
stderr_logfile=/var/www/storage/supervisor/worker.err.log
stdout_logfile=/var/www/storage/supervisor/worker.log

Should I be adding a deployment hook in envoyer to restart supervisor everytime I deploy new code? Or is that bad? My main worry with that would be what would happen if I had jobs in the jobs table at the time of restart...would they be lost? Any clarification on the whole process would be much appreciated

Thanks

0 likes
10 replies
bobbybouwmann's avatar

Yes, you have to restart your queue, or in your case supervisor, to make sure that your queue works as expected. Supervisor should finish all processes before killing itself. After that, it should start up the queue again with the new code. So you might have a delay of a few seconds that jobs are not being processed, but you won't lose any jobs!

The reason that you don't lose jobs, is because they are stored in the database. The worker just picks one from there and that's it. So restarting supervisor won't affect your queue.

secondman's avatar

Yeah not the question I asked.

I want to restart supervisor itself.

LetherMade's avatar

Like Niush explains a queue:restart would be good enough in the deploy script.

But if you really want to restart supervisor self in the forge quick deploy script you would have to give the forge user rights to restart supervisor.

This can be done in the sudoers file. You would need some linux knowledge tough.

  • log in as forge user
  • sudo -i and type forge sudo password
  • visudo wil enter the sudoers file in a special modus to not f*ck up the sudoers file ^^
  • add following code below "User privilege specification" below the root user:

forge ALL=(ALL) NOPASSWD: ALL

With this you give the forge user the rights to execute all programs in sudo mode without password.. and you could do sudo services supervisor restart

This is a serious security leak if your servers ssh ports are exposed.

The best way is to limit the exuctuions it can do like so:

forge ALL=NOPASSWD: /usr/bin/supervisorctl

this way forge can only use the sudo supervisorctl command with no password :)

bernardwiesner's avatar

I find it problematic to have a few seconds lag on queued jobs when a restart is required. There could be time sensitive jobs that need to be executed in that exact second.

I think a better alternative is using pm2 with the queue worker. It has a rolling restart option where you can have 0 downtime deploys.

panadol007's avatar

I have a same concern, from my experience, following command will clear all the queued jobs sudo systemctl restart supervisord

But I'm double checking if following command will clear all queued jobs: php artisan queue:restart

Please or to participate in this conversation.