进程守护supervisor系列一:安装与配置(代码片段)

author author     2023-05-07     671

关键词:

进程守护Supervisor

准备工作:
环境:

Centos 7 (Centos6.5不适合以下教程)

Python >= 2.7 (升级见:Python升级教程)

pip包管理工具安装(已安装可跳过)

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py 

安装:

  • 安装superviosr
pip install supervisor
  • 配置配置文件
    // 创建配置目录
    mkdir -p /etc/supervisor/conf
    // 输出默认配置文件
    echo_supervisord_conf  >/etc/supervisor/supervisord.conf

    配置文件

# vim /etc/supervisor/supervisord.conf
; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
;  - Shell expansion ("~" or "$HOME") is not supported.  Environment
;    variables can be expanded using this syntax: "%(ENV_HOME)s".
;  - Quotes around values are not supported, except in the case of
;    the environment= options as shown below.
;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".
;  - Command will be truncated if it looks like a config file comment, e.g.
;    "command=bash -c ‘foo ; bar‘" will truncate to "command=bash -c ‘foo ".
;
; Warning:
;  Paths throughout this example file use /tmp because it is available on most
;  systems.  You will likely need to change these to locations more appropriate
;  for your system.  Some systems periodically delete older files in /tmp.
;  Notably, if the socket file defined in the [unix_http_server] section below
;  is deleted, supervisorctl will be unable to connect to supervisord.

[unix_http_server]
file=/var/run/supervisor.sock   ; the path to the socket file
;chmod=0700                 ; socket file mode (default 0700)
;chown=nobody:nogroup       ; socket file uid:gid owner
;username=user              ; default is no username (open server)
;password=123               ; default is no password (open server)

; Security Warning:
;  The inet HTTP server is not enabled by default.  The inet HTTP server is
;  enabled by uncommenting the [inet_http_server] section below.  The inet
;  HTTP server is intended for use within a trusted environment only.  It
;  should only be bound to localhost or only accessible from within an
;  isolated, trusted network.  The inet HTTP server does not support any
;  form of encryption.  The inet HTTP server does not use authentication
;  by default (see the username= and password= options to add authentication).
;  Never expose the inet HTTP server to the public internet.

[inet_http_server]                  ; inet (TCP) server disabled by default
port=0.0.0.0:9001          ; ip_address:port specifier, *:port for all iface
; username=hadoop                     ; default is no username (open server)
; password=******                ; default is no password (open server)

[supervisord]
logfile=/var/log/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
pidfile=/var/run/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false               ; start in foreground if true; default false
minfds=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200
;umask=022                   ; process file creation umask; default 022
;user=supervisord            ; setuid to this UNIX account at startup; recommended if root
;identifier=supervisor       ; supervisord identifier, default is ‘supervisor‘
;directory=/tmp              ; default is not to cd during start
;nocleanup=true              ; don‘t clean up tempfiles at start; default false
;childlogdir=/tmp            ; ‘AUTO‘ child log dir, default $TEMP
;environment=KEY="value"     ; key value pairs to add to environment
;strip_ansi=false            ; strip ansi escape codes in logs; def. false

; The rpcinterface:supervisor 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:x] sections.

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

; The supervisorctl section configures how supervisorctl will connect to
; supervisord.  configure it match the settings in either the unix_http_server
; or inet_http_server section.

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris              ; should be same as in [*_http_server] if set
;password=123                ; should be same as in [*_http_server] if set
;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history  ; use readline history if available

; The sample program section below shows all possible program subsection values.
; Create one or more ‘real‘ program: sections to be able to control them under
; supervisor.

;[program:theprogramname]
;command=/bin/cat              ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=999                  ; the relative start priority (default 999)
;autostart=true                ; start at supervisord start (default: true)
;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
;startretries=3                ; max # of serial start failures when starting (default 3)
;autorestart=unexpected        ; when to restart if exited after running (def: unexpected)
;exitcodes=0                   ; ‘expected‘ exit codes used with autorestart (default 0)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false             ; send stop signal to the UNIX process group (default false)
;killasgroup=false             ; SIGKILL the UNIX process group (def false)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
;stdout_capture_maxbytes=1MB   ; number of bytes in ‘capturemode‘ (default 0)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stdout_syslog=false           ; send stdout to syslog with process name (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
;stderr_capture_maxbytes=1MB   ; number of bytes in ‘capturemode‘ (default 0)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;stderr_syslog=false           ; send stderr to syslog with process name (default false)
;environment=A="1",B="2"       ; process environment additions (def no adds)
;serverurl=AUTO                ; override serverurl computation (childutils)

; The sample eventlistener section below shows all possible eventlistener
; subsection values.  Create one or more ‘real‘ eventlistener: sections to be
; able to handle event notifications sent by supervisord.

;[eventlistener:theeventlistenername]
;command=/bin/eventlistener    ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
;numprocs=1                    ; number of processes copies to start (def 1)
;events=EVENT                  ; event notif. types to subscribe to (req‘d)
;buffer_size=10                ; event buffer queue size (default 10)
;directory=/tmp                ; directory to cwd to before exec (def no cwd)
;umask=022                     ; umask for process (default None)
;priority=-1                   ; the relative start priority (default -1)
;autostart=true                ; start at supervisord start (default: true)
;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)
;startretries=3                ; max # of serial start failures when starting (default 3)
;autorestart=unexpected        ; autorestart if exited after running (def: unexpected)
;exitcodes=0                   ; ‘expected‘ exit codes used with autorestart (default 0)
;stopsignal=QUIT               ; signal used to kill process (default TERM)
;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false             ; send stop signal to the UNIX process group (default false)
;killasgroup=false             ; SIGKILL the UNIX process group (def false)
;user=chrism                   ; setuid to this UNIX account to run the program
;redirect_stderr=false         ; redirect_stderr=true is not allowed for eventlisteners
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stdout_syslog=false           ; send stdout to syslog with process name (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;stderr_syslog=false           ; send stderr to syslog with process name (default false)
;environment=A="1",B="2"       ; process environment additions
;serverurl=AUTO                ; override serverurl computation (childutils)

; The sample group section below shows all possible group values.  Create one
; or more ‘real‘ group: sections to create "heterogeneous" process groups.

;[group:thegroupname]
;programs=progname1,progname2  ; each refers to ‘x‘ in [program:x] definitions
;priority=999                  ; the relative start priority (default 999)

; 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/*.ini
  • 配置开机启动
# vim /lib/systemd/system/supervisord.service

[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
SysVStartPriority=99

[Install]
WantedBy=multi-user.target
  • 添加启动服务
    systemctl enable supervisord.service
    systemctl start/restart/stop supervisord.service
  • 增加自定义守护文件
    eg.新增服务配置文件
    # vim /etc/supervisor/conf/xdb.ini
    [program:xdb-service]
    command=/home/hadoop/anaconda3/envs/xdb/bin/python /data/service/xdb-service/app.py
    directory=/data/service/xdb-service/
    stdout_logfile=/data/service/xdb-service/log/supervisor.log
    stdout_logfile_maxbytes = 200MB
    autostart=true
    startretries=10
    user=hadoop
    systemctl reload supervisord.service

启动:

root用户启动

###启动服务

supervisorctl start all
supervisorctl start service_name

###关闭服务

supervisorctl stop all
supervisorctl stop service_name

###查看状态

supervisorctl status [service_name]

###更新配置文件

supervisorctl update

###重新启动所有服务或者是某个服务

supervisorctl restart all
supervisorctl restart service_name

centos下supervisor守护进程基本配置

supervisor:C/S架构的进程控制系统,可使用户在类UNIX系统中监控、管理进程。常用于管理与某个用户或项目相关的进程。组成部分supervisord:服务守护进程supervisorctl:命令行客户端WebServer:提供与supervisorctl功能相当的WEB操作界面XM... 查看详情

supervisor安装及配置——管理守护进程的福利(代码片段)

CentOS7以上直接使用yum安装即可正常使用小配文件配置supervisor程序并可以多进程方式启动自己的进守护进程但CentOS6系统使用yum安装的supervisor不支持使用小配置文件和多进程所以要想在CentOS6系统上的正常使用supervisor管理自己的守... 查看详情

supervisor安装和配置指南(代码片段)

supervisor:是用python写的一个进程管理工具,用来启动,重启,关闭进程。注意:Supervisor只能管理非daemon的进程,也就是说Supervisor不能管理守护进程。否则提示Exitedtooquickly(processlogmayhavedetails)异常。好比Tomcat默认是以守护进程启... 查看详情

centos7.4配置supervisor守护进程(代码片段)

1、安装yuminstallpython-setuptoolseasy_installsupervisor2、创建守护进程跟路径mkdir-m700-p/etc/supervisor3、在目录“/etc/supervisor”下创建配置文件echo_supervisord_conf>/etc/supervisor/supervisord.conf4、修改配置vim/etc/superviso 查看详情

supervisor的配置与使用

环境:ubuntu14.04lts http://supervisord.org/liunx下有很多守护进程的工具,如nohup,screen,supervisor等,supervisor是用Python开发的进程管理程序,能将一个普通的命令行进程变为后台daemon,异常退出时能自动重启。#安装sudoapt-getinstallsupe... 查看详情

palo通过supervisor进行进程管理(代码片段)

...用守护进程启动,以保证进程退出后,会被自动拉起,如Supervisor。如需使用守护进程启动,需要修改各个start_xx.sh脚本,去掉最后的&符号首先安装supervisor,具体请参照本人的另一篇博客CentOS7安装supervisor守护进程管理器 1... 查看详情

使用supervisor管理进程二

supervisor安装完成后会生成三个执行程序:supervisortd、supervisorctl、echo_supervisord_conf,分别是supervisor的守护进程服务(用于接收进程管理命令)、客户端(用于和守护进程通信,发送管理进程的指令)、生成初始配置文件程序。3... 查看详情

centos7中使用supervisor守护进程(代码片段)

 转:https://www.cnblogs.com/qmhuang/p/8196132.html配置supervisor实现进程守护1.安装supervisoryuminstallSupervisor 2.启动服务supervisord-c/etc/supervisord.conf 进入cd/etc目录找到supervisord.conf配置文件和superviso 查看详情

supervisor进程管理工具(代码片段)

1、什么是supervisorSupervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。、作用:它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意... 查看详情

supervisor安装与配置(代码片段)

Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被... 查看详情

linux使用supervisor守护进程(代码片段)

Supervisor是什么是Linux/Unix系统下的一个进程管理工具,它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起ÿ... 查看详情

10:supervisor进程管理工具(代码片段)

1.1supervisor介绍  1、什么是supervisor      1. Supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。、      2.作用:它可以很方便的监听、启动、停止、重启一... 查看详情

【转】daemon、supervisor与php

参考技术ASupervisor简单来说就是在你需要常驻运行的程序挂掉的时候及时拉起。这对于现在的场景是非常合适啊。编辑/etc/supervisord.d/php-fpm.ini,配置如下:进入Supervisor控制台:请记住这里最后的结果是ERROR,然而查看进程php-fpm确... 查看详情

mac下supervisor进程监控管理工具的安装与配置

Supervisor 是一个类unix操作系统下的进程监控管理工具。Supervisor 是由Python写成,可用Python的包安装管理工具 pip(PythonPackageIndex) 直接安装 代码如下:sudopipinstallsupervisor 配置SupervisorSupervisor的配置文件命名为supe... 查看详情

宝塔面板使用supervisor管理器开启守护进程(代码片段)

1、宝塔面板的安装宝塔官网链接windows采用下一步安装方式liunx安装命令centosyuminstall-ywget&&wget-Oinstall.shhttp://download.bt.cn/install/install_6.0.sh&&shinstall.sh其他安装可以在官网中查看在这里可以随便写一个守护进程的php代码wh... 查看详情

supervisor安装及其配置

一、supervisor概述       supervisor是一个c/s系统,被用来在类Unix系统中监控进程状态。supervisor使用python开发。服务端进程为supervisord,主要负责启动自身及其监控的子进程,响应客户端命令,重启异常退出... 查看详情

ubuntu服务器下安装supervisor守护程序并配置

参考技术A4.修改配置文件customer.conf(celery的消费程序)方法1-关闭supervisord服务再打开方法2-重新加载conf6.查看配置运行情况解决方法为修改supervisor.conf将默认的file和serverurl路径修改为(保持一致) 查看详情

lxd2.0系列:安装与配置

 导读简单来说,LXD是一个守护进程,为LXC容器的管理提供一组RESTAPI。主要目标是提供一种类虚拟机的用户体验,是一种第三方的容器管理工具。下面呢,我们来介绍LXD2.0的安装与配置安装篇有很多种办法可以获得LXD。我们... 查看详情