linux supervisord - ghdrako/doc_snipets GitHub Wiki
supervisor ma /etc/supervisord/acp-stunnel.ini i z jej uruchamia procesy. Jesli proces nie moze sie zespawnowac 5 razy to składa Pod-a
supervisord's primary purpose is to create and manage processes based on data in its configuration file. It does this by creating subprocesses. Each subprocess spawned by supervisor is managed for the entirety of its lifetime by supervisord (supervisord is the parent process of each process it creates).
It shares some of the same goals of programs like launchd, daemontools, and runit
To start supervisord, run $BINDIR/supervisord. The resulting process will daemonize itself and detach from the terminal. It keeps an operations log at $CWD/supervisor. log by default.
pip install supervisor
echo_supervisord_conf > /etc/supervisord.conf
dodac:
[program:python_finacial]
command=/opt/run_python_financial
user=root
stdout_logfile=/var/log/stdout_financial.log
stderr_logfile=/var/log/stderr_financial.log
Który mówi żeby uruchamiać plik /opt/run_python_financial z roota. Standardowe wyjście aplikacji przekierowywać do /var/log/stdout_financial.log a wyjście błędów do /var/log/stderr_financial.log. Nasza aplikacja ma zaimplementowane logowanie bezpośrednio do pliku a nie na standardowe wyjście, więc supervisor zbyt dużo nie przekieruje ale takie linijki zawsze warto mieć.
Plik /opt/run_python_financial ma zawartość:
#!/bin/sh
source /opt/virtual_envs/bin/activate
exec gold_digger
No i skoro to już mamy to możemy go uruchomić, wpisując:
supervisord
Aby zarządzać procesami możesz uruchomić program supervisorctl i będzie tam lista aktywnych procesów. Taka konsola jest przydatna i potrzebna ale poza nią możemy mieć jeszcze dostęp przez przeglądarkę. Aby taką możliwość uruchomić należy w pliku konfiguracyjnym- /etc/supervisord.conf – w sekcji inet_http_server odkomentować wszystkie 3 ustawienia oraz ustawić hasło i login.
Dodamy więc do CRON’a zadanie – niech on mi gasi aplikację powiedzmy o 00:01 w sobotę i podnosi o tej samej godzinie w poniedziałek:
1 0 * * 1 /usr/bin/supervisorctl start python_finacial
1 0 * * 6 /usr/bin/supervisorctl stop python_finacial
supervisorctl Actions¶
command | description |
---|---|
help | Print a list of available actions |
help | Print help for |
add […] | Activates any updates in config for process/group |
remove […] | Removes process/group from active config |
update | Reload config and add/remove as necessary, and will restart affected programs |
update all | Reload config and add/remove as necessary, and will restart affected programs |
update […] | Update specific groups, and will restart affected programs |
clear | Clear a process’ log files. |
clear | Clear multiple process’ log files |
clear all | Clear all process’ log files |
fg | Connect to a process in foreground mode Press Ctrl+C to exit foreground |
pid | Get the PID of supervisord. |
pid | Get the PID of a single child process by name. |
pid all | Get the PID of every child process, one per line. |
reload | Restarts the remote supervisord |
reread | Reload the daemon’s configuration files, without add/remove (no restarts) |
restart | Restart a process Note: restart does not reread config files. For that, see reread and update. |
restart :* | Restart all processes in a group Note: restart does not reread config files. For that, see reread and update. |
restart | Restart multiple processes or groups Note: restart does not reread config files. For that, see reread and update. |
restart all | Restart all processes Note: restart does not reread config files. For that, see reread and update. |
signal | No help on signal |
start | Start a process |
start :* | Start all processes in a group |
start | Start multiple processes or groups |
start all | Start all processes |
status | Get all process status info. |
status | Get status on a single process by name. |
status | Get status on multiple named processes. |
stop | Stop a process |
stop :* | Stop all processes in a group |
stop | Stop multiple processes or groups |
stop all | Stop all processes |
tail [-f] [stdout|stderr] (default stdout) | Output the last part of process logs Ex: tail -f Continuous tail of named process stdout Ctrl-C to exit. tail -100 last 100 bytes of process stdout tail stderr last 1600 bytes of process stderr |