Is there a way to automatically restart Supervisor processes?

I have a dev server that I often post code changes to in Git. After each click, I need to manually enter the server and restart the dispatcher processes.

Is there a way to get Supervisor to track the file system directory for changes and restart the change process?

+6
source share
3 answers

You should use an Event Listener that controls the file system (possibly watchdog ) and issues a restart using the XML-RPC API . Listen to memmon from superlance for inspiration. It should not be so difficult. And since the watchdog calls your restart procedure, you do not need to read events using childutils.listener.wait .

Alternatively, git hooks can do the trick if the permissions are correct for accessing the supervisor API (socket permissions, HTTP passwords). A simpler but less secure approach.

A simpler and even less secure approach will let you release supervisorctl restart . The managed user must match your push user (either git or www, depending on how you configured it). Many ways to do this wrong, safe. But for development, this can do well.

on this topic:

+5
source

I also did not find a solution, so I tried to make my own. Here it is .

You can install the package with this command:

 pip install git+https://github.com/stavinsky/supervisord-touch-reload.git 

(I will add it to PyPI after adding some tests.)

An example of setting up the manager located in the examples folder on github. I think the documentation will be very soon. Basically all you need to start using this module is to add an event listener using command , for example:

python -m touch_reload --socket unix:///tmp/supervisor.sock --file <path/to file file> --program <program name>

where file is the file to be tracked using the absolute or relative path of the directory , socket is the socket from the supervisorctl section, and program is the name of the program from the definition of the [program:<name>] section. --username and --password are also available, which you can use if you have a custom dispatcher configuration.

+5
source

While not the solution that the supervisor uses, I usually solve this problem in a controlled application. For example, add the -reload flag to gunicorn and it will reload when your application changes.

+1
source

Source: https://habr.com/ru/post/958885/


All Articles