Supervisor應用配置實例

Supervisor是一個進程管理系統,允許用戶在Unix-like操作系統上監視與管理一系列進程。管理的進程被當做supervisor的子進程,supervisor可以準確知道進程的狀態,當進程中斷時可以自動重啓。當需要管理一個用戶或一個項目的進程時,supervisor是一個很好的工具。

安裝配置

安裝:

sudo apt-get install supervisor

安裝完成後,配置文件在/etc/supervisor目錄下,其中supervisord.conf是supervisord的配置文件,conf.d文件夾放需要管理的進程配置文件。
在這裏插入圖片描述
下面以配置一個Python web運行環境爲例,開機後自動啓動 Nginx 和 uWSGI,並且支持進程中止時候自動重啓。配置非常簡單,僅需以下三個步驟。

  1. supervisor的配置文件(分號; 表示註釋):

一般不需要改動這個配置。

; 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的主要全局配置
[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)

[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

; 引入進程管理配置文件
[include]
files = /etc/supervisor/conf.d/*.conf
  1. 管理的子進程配置文件

在此配置需要管理的進程

[supervisord]
nodaemon=true

[program:uwsgi]
command=/usr/local/bin/uwsgi --ini /etc/uwsgi/uwsgi.ini --die-on-term --need-app
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:nginx]
command=/usr/sbin/nginx
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
# Graceful stop, see http://nginx.org/en/docs/control.html
stopsignal=QUIT

program 是程序名稱,不能爲空;
command是程序運行命令
autorestart=true當程序中止時自動重啓

  1. 啓動supervisor
/usr/bin/supervisord

開啓http 監控server

在supervisord.conf配置文件裏面添加如下配置。

[inet_http_server]
port=*:9001

效果如下
在這裏插入圖片描述

常用命令介紹

root@my-host:/src# supervisorctl stop all
nginx: stopped
uwsgi: stopped
root@my-host:/src# supervisorctl start all
nginx: started
uwsgi: started
root@my-host:/src# supervisorctl stop nginx
nginx: stopped
root@my-host:/src# supervisorctl start nginx
nginx: started
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章