Reputation: 13558
For synchronous processing, we use supervisord with a beanstalkd queue. The application and worker code is all written in php (using SlmQueue). I notice that when we deploy new code, the new code isn't working for the worker processes. I am not quite sure what's the reason, but what I did found out:
service supervisor restart
does not restart the process (the PID keeps the same)supervisorctl reload
does reload all the processes, the new code is used for nowsupervisorctl
has no way (as I understand it) to reload only one program and keep the others still runningI am looking for a way to deploy new code (working via ansible and a git checkout) and no need to restart the complete supervisor process with all its children. We run Ubuntu 12.04 machines with PHP 5.5. I guess the opcode cache may play a role, but I am unsure how to trigger a flush for these specific files.
Is there any way to gracefully reload the processes and not completely reload all supervisord child processes? Or if the reason might be the opcode cache, is it possible to flush the cache with a certain trigger?
Upvotes: 6
Views: 9174
Reputation: 3659
The supervisorctl that comes with Supervisord 3.0 does allow restarting individual programs (or groups of programs) as a single non-interactive command.
# supervisorctl help restart
restart <name> Restart a process
restart <gname>:* Restart all processes in a group
restart <name> <name> Restart multiple processes or groups
restart all Restart all processes
Note: restart does not reread config files. For that, see reread and update.
E.g. supervisorctl restart my_program
works fine now.
Regarding your related question on how to flush PHP's opcache, the following should help:
A universal way is to create a .php file with the contents:
<?php
opcache_reset();
Then call that via your webserver, e.g. via curl https://example.com/flush_cache.php
. It's important to do the opcache_reset()
call via your webserver in order to flush the right cache. Calling it via the php cli command won't work.
There are some other ways to flush it, depending on the way you run PHP. For Apache with mod_php you can reload Apache via apachectl graceful
(or similar). For PHP-FPM you can reload the FPM process via service php-fpm reload
(or similar). Another option is to use cachetool, which allows flushing from the cli without restarting processes and also provides commands to get statistics.
Upvotes: 0
Reputation: 6306
You can use supervisorctl to restart only one process.
supervisorctl -c /etc/supervisord/supervisord.conf
Once you are in the supervisor subshell you can use status
and restart
to reload your job.
Consider the following example where I reload flower
supervisor> status
beat_worker:beat_worker_00 RUNNING pid 32274, uptime 0:27:45
flower RUNNING pid 32275, uptime 0:27:45
workers:worker_wkrone_00 RUNNING pid 32278, uptime 0:27:45
workers:worker_wkrtwo_00 RUNNING pid 32276, uptime 0:27:45
workers:worker_wkrthree_00 RUNNING pid 32277, uptime 0:27:45
supervisor> restart flower
flower: stopped
flower: started
and now if you do a status again you will see that the pid of flower
has changed.
supervisor> status
beat_worker:beat_worker_00 RUNNING pid 32274, uptime 0:28:13
flower RUNNING pid 32713, uptime 0:00:08
workers:worker_wkrone_00 RUNNING pid 32278, uptime 0:28:13
workers:worker_wkrtwo_00 RUNNING pid 32276, uptime 0:28:13
workers:worker_wkrthree_00 RUNNING pid 32277, uptime 0:28:13
Then just do a ctrl -d
to exit the supervisord shell.
If you inspect the output of status you will see that the pid of the job changed and the uptime count restarted.
Upvotes: 2