Supervisor is written in Python process management tool, the process can easily be started, stopped, restarted operations.
Installation command:
$ apt-get install supervisor
After the installation is successful, in the / etc / supervisor directory, generate supervisord.conf profile.
You can also use echo_supervisord_conf> supervisord.conf command to generate a default configuration file (not recommended, more content).
supervisord.conf example configuration:
; supervisor config file
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; sockef file mode (default 0700)
[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor ; ('AUTO' child log dir, default $TEMP)
; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = /etc/supervisor/conf.d/*.conf
* .Conf configuration process reads the configuration file in the directory /etc/supervisor/conf.d, we create a hwapp.conf process configuration files in this directory:
[program:flask_demo]
directory=/home/zhangsan/flask_demo
command=command=uwsgi --ini /etc/supervisor/conf.d/uwsgi.ini
autostart=true
autorestart=true
startretries=10
redirect_stderr=true
stdout_logfile=/var/log/flask_demo/stdout.log
stderr_logfile=/var/log/flask_demo/stderr.log
environment=ASPNETCORE_ENVIRONMENT="Development"
Note that, if not the root account, you need to set permissions for these directories, or else will report some errors (be sure to configure the root account).
$ sudo chmod 777 /var/run
$ sudo chmod 777 /etc/supervisor
Then you can start the Supervisord:
$ supervisord
supervisorctl commonly used commands:
Command Description
supervisorctl stop program_name 停止某个进程
supervisorctl start program_name 启动某个进程
supervisorctl restart program_name 重启某个进程
supervisorctl stop all 停止全部进程
supervisorctl reload 载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程
supervisorctl update 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启
Note:
For the foregoing reasons, need to use sudo permission to start a supervisor, and therefore belongs to a user-initiated process is the root of Python