Supervisor installation and configuration--managing the benefits of the daemon

Source: Internet
Author: User

CentOS7 above directly using the Yum installation to configure the Supervisor program with a small configuration file
And can start their own daemon process in a multi-process manner.
However, CentOS6 systems using Yum installed supervisor do not support the use of small configuration files and multi-process
So you want to use supervisor to manage your daemon on the CentOS6 system.
You will need to install it using the Python installer, as follows:


1. Install the Python installer
Yum Install-y Python-setuptools

2. Install supervisor using the Python installer
Easy_install Supervisor

3, view Supervisor version
Supervisord--version

4, Generate Supervisor default profile
echo_supervisord_conf >/etc/supervisord.conf

5, the valid configuration content reference is as follows

[Unix_http_server]
File=/tmp/supervisor.sock//If modified to a different directory, you need to confirm that the owner of the process has write access to its directory
[Supervisord]
Logfile=/data/log/supervisor/supervisord.log//Modify to a custom log directory, you need to confirm that the owner of the process has write access to its directory
logfile_maxbytes=50mb
logfile_backups=10
Loglevel=info
Pidfile=/tmp/supervisord.pid//If modified to a different directory, you need to confirm that the owner of the process has write access to its directory
Nodaemon=false
minfds=1024
minprocs=200
[Rpcinterface:supervisor]
Supervisor.rpcinterface_factory = Supervisor.rpcinterface:make_main_rpcinterface
[Supervisorctl]
Serverurl=unix:///tmp/supervisor.sock//If the file option has been modified, the corresponding
[include]//default status small file not open, need to automatically uncomment
Files = supervisord.d/*.conf//The official recommendation here is to use relative paths (relative to/etc directories)

6, generate a service startup script to manage using service commands
Vim/etc/rc.d/init.d/supervisord

#!/bin/bash

Chkconfig:-45description:supervisor serviceprocessname:supervisordconfig:/etc/supervisord.confpidfile:/var/ Run/supervisord.pid


. /etc/init.d/functions

Daemon=/usr/bin/supervisord
Pidfile=/var/run/supervisord.pid

[-X "$DAEMON"] | | Exit 0

Start () {
Echo-n "Starting Supervisord:"
If [-f $PIDFILE]; Then
Pid=cat $PIDFILE
Echo Supervisord already running: $PID
Exit 2;
Else
Daemon $DAEMON--pidfile= $PIDFILE-C/etc/supervisord.conf
Retval=$?
Echo
[$RETVAL-eq 0] && Touch/var/lock/subsys/supervisord
Return $RETVAL
Fi

}

Stop () {
Echo-n "shutting down Supervisord:"
Echo
Killproc-p $PIDFILE Supervisord
Echo
Rm-f/var/lock/subsys/supervisord
return 0
}

Case "$" in
Start
Start
;;
Stop
Stop
;;
Status
Status Supervisord
;;
Restart
Stop
Start
;;
*)
echo "Usage: {Start|stop|status|restart}"

  • Exit 1
    ;;
    Esac
    Exit $?

    7. Add Execute permission to script
    chmod +x/etc/rc.d/init.d/supervisord

    8. Add the startup script generated above into the CentOS service Manager
    Chkconfig--add Supervisord

    9. Set the Supervisor service as self-starting
    Chkconfig Supervisord on

    10. Add a small file of the process you need to protect
    Vim/etc/supervisord.d/self.conf

    The specific format refers to the official given default version, which is the following section
    ; [Program:theprogramname]
    ; command=/bin/cat; The program (relative uses PATH, can take args)
    ;p rocessname=% (programname) s; ProcessName Expr (default% (ProgramName) s)
    ; Numprocs=1; Number of processes copies to start (Def 1)
    ;d irectory=/tmp; Directory to CWD to before exec (Def no CWD)
    ; umask=022; Umask for process (default None)
    ;p riority=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,2; ' Expected ' exit codes used with AutoRestart (default 0,2)
    ; 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
    ; redirectstderr=true; REDIRECT Proc stderr to stdout (default false)
    ; Stdoutlogfile=/a/path; StdOut log path, none for none; Default AUTO
    ; STDOUTLOGFILEMAXBYTES=1MB; Max # logfile bytes b4 rotation (default 50MB)
    ; stdoutlogfilebackups=10; # of StdOut logfile backups (0 means none, default 10)
    ; STDOUTCAPTUREMAXBYTES=1MB; Number of bytes in ' capturemode ' (default 0)
    ; stdouteventsenabled=false; Emit events on StdOut writes (default false)
    ; Stderrlogfile=/a/path; stderr log path, none for none; Default AUTO
    ; STDERRLOGFILEMAXBYTES=1MB; Max # logfile bytes b4 rotation (default 50MB)
    ; stderrlogfilebackups=10; # of stderr logfile backups (0 means none, default 10)
    ; STDERRCAPTUREMAXBYTES=1MB; Number of bytes in ' capturemode ' (default 0)
    ; stderreventsenabled=false; Emit events on StdErr writes (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)
    ;p rocessname=% (programname) s; ProcessName Expr (default% (ProgramName) s)
    ; Numprocs=1; Number of processes copies to start (Def 1)
    ; events=event; Event Notif. Types to subscribe to (req ' d)
    ; buffersize=10; Event buffer Queue Size (default 10)
    ;d irectory=/tmp; Directory to CWD to before exec (Def no CWD)
    ; umask=022; Umask for process (default None)
    ;p Riority=-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,2; ' Expected ' exit codes used with AutoRestart (default 0,2)
    ; 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
    ; redirectstderr=false; Redirectstderr=true isn't allowed for eventlisteners
    ; Stdoutlogfile=/a/path; StdOut log path, none for none; Default AUTO
    ; STDOUTLOGFILEMAXBYTES=1MB; Max # logfile bytes b4 rotation (default 50MB)
    ; stdoutlogfilebackups=10; # of StdOut logfile backups (0 means none, default 10)
    ; stdouteventsenabled=false; Emit events on StdOut writes (default false)
    ; Stderrlogfile=/a/path; stderr log path, none for none; Default AUTO
    ; STDERRLOGFILEMAXBYTES=1MB; Max # logfile bytes b4 rotation (default 50MB)
    ; stderrlogfilebackups=10; # of stderr logfile backups (0 means none, default 10)
    ; stderreventsenabled=false; Emit events on StdErr writes (default false)
    ; environment=a= "1", b= "2"; Process Environment Additions
    ; Serverurl=auto; Override ServerURL computation (childutils)

    Here is a simplified example of your own use
    [Program:jumpserver]
    Command =source/opt/py3/bin/activate &&/data/jumpserver/jms start all-d
    ProcessName =% (programname) s% (processnum) s
    Numprocs = 1
    autostart= true
    autorestart= true
    Stdoutlogfile=/data/log/jumpserver/jumpserver.log

    11. After everything is ready, you can start the Supervisord service.
    As configured above, the Supervisord process starts, and the child processes it manages are automatically started.

    To this end, a simple supervisor installation plus configuration is basically done.
    Colleagues who want to use supervisor's own daemon can start working boldly! *

Supervisor installation and configuration--managing the benefits of the daemon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.