zoukankan      html  css  js  c++  java
  • supervisor安装配置

    1.安装

    下载:https://codeload.github.com/Supervisor/supervisor/zip/3.1.3

    2.安装

    unzip supervisor-3.1.3.zip
    cd supervisor-3.1.3
    python setup.py

    3. 配置文件,sock配置一定要一致

    [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))
    
    [inet_http_server]         ; inet (TCP) server disabled by default
    port=*:9001        ; (ip_address:port specifier, *:port for all iface)
    username=user              ; (default is no username (open server))
    password=123               ; (default is no password (open server))
    
    [supervisord]
    logfile=/var/log/supervisord/supervisord.log ; (main log file;default $CWD/supervisord.log)
    logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)
    logfile_backups=10           ; (num of main logfile rotation backups;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=chrism                 ; (default is current user, required 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=/var/log/supervisord/            ; ('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 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
    ;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
    ;username=chris              ; should be same as http_username if set
    ;password=123                ; should be same as http_password if set
    ;prompt=mysupervisor         ; cmd line prompt (default "supervisor")
    ;history_file=~/.sc_history  ; use readline history if available
    
    ; The below sample program section shows all possible program subsection values,
    ; create one or more 'real' program: sections to be able to control them under
    ; supervisor.
    
    [include]
    files = /etc/supervisord.d/*.conf

     创建一个测试进程

    mkdir /etc/supervisord.d

    vi  /etc/supervisord.d/tail.conf
    
    [program:tail1] 
    command=tail -f  /etc/supervisord.conf
    autostart=true         
    autorestart=true               
    startretries=3        
    ;stderr_logfile=/tmp/tail1.err.log 
    ;stdout_logfile=/tmp/tail1.out.log

    3.修改执行脚本

    vim /etc/init.d/supervisord
    
    #!/bin/bash
    #
    # supervisord   This scripts turns supervisord on
    # chkconfig:    345 83 04
    # description:  supervisor is a process control utility.  It has a web based
    #               xmlrpc interface as well as a few other nifty features.
    #
    
    # source function library
    . /etc/rc.d/init.d/functions
    
    set -a
    
    PREFIX=/usr/local
    
    SUPERVISORD=$PREFIX/bin/supervisord
    SUPERVISORCTL=$PREFIX/bin/supervisorctl
    
    PIDFILE=/var/supervisor/supervisord.pid
    LOCKFILE=/var/supervisor/supervisord.lock
    
    OPTIONS="-c /etc/supervisord.conf"
    
    # unset this variable if you don't care to wait for child processes to shutdown before removing the $LOCKFILE-lock
    WAIT_FOR_SUBPROCESSES=yes
    
    # remove this if you manage number of open files in some other fashion
    ulimit -n 96000
    
    RETVAL=0
    
    
    running_pid()
    {
        # Check if a given process pid's cmdline matches a given name
        pid=$1
        name=$2
        [ -z "$pid" ] && return 1
        [ ! -d /proc/$pid ] && return 1
        (cat /proc/$pid/cmdline | tr "00" "
    "|grep -q $name) || return 1
        return 0
    }
    
    running()
    {
    # Check if the process is running looking at /proc
    # (works for all users)
    
        # No pidfile, probably no daemon present
        [ ! -f "$PIDFILE" ] && return 1
        # Obtain the pid and check it against the binary name
        pid=`cat $PIDFILE`
        running_pid $pid $SUPERVISORD || return 1
        return 0
    }
    
    start() {
            echo "Starting supervisord: "
    
            if [ -e $PIDFILE ]; then 
            echo "ALREADY STARTED"
            return 1
        fi
    
        # start supervisord with options from sysconfig (stuff like -c)
            $SUPERVISORD $OPTIONS
    
        # show initial startup status
        $SUPERVISORCTL $OPTIONS status
    
        # only create the subsyslock if we created the PIDFILE
            [ -e $PIDFILE ] && touch $LOCKFILE
    }
    
    stop() {
            echo -n "Stopping supervisord: "
            $SUPERVISORCTL $OPTIONS shutdown
        if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then 
                echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"
                for sleep in  2 2 2 2 4 4 4 4 8 8 8 8 last; do
                    if [ ! -e $PIDFILE ] ; then
                        echo "Supervisord exited as expected in under $total_sleep seconds"
                        break
                    else
                        if [[ $sleep -eq "last" ]] ; then
                            echo "Supervisord still working on shutting down. We've waited roughly 60 seconds, we'll let it do its thing from here"
                            return 1
                        else
                            sleep $sleep
                            total_sleep=$(( $total_sleep + $sleep ))
                        fi
    
                    fi
                done
            fi
    
            # always remove the subsys. We might have waited a while, but just remove it at this point.
            rm -f $LOCKFILE
    }
    
    restart() {
            stop
            start
    }
    
    case "$1" in
        start)
            start
            RETVAL=$?
            ;;
        stop)
            stop
            RETVAL=$?
            ;;
        restart|force-reload)
            restart
            RETVAL=$?
            ;;
        reload)
            $SUPERVISORCTL $OPTIONS reload
            RETVAL=$?
            ;;
        condrestart)
            [ -f $LOCKFILE ] && restart
            RETVAL=$?
            ;;
        status)
            $SUPERVISORCTL $OPTIONS status
            if running ; then
                RETVAL=0
            else
                RETVAL=1
            fi
            ;;
        *)
            echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
            exit 1
    esac
    
    exit $RETVAL

    保存完毕之后,可以执行以下命令修改文件权限:

    chmod 777 /etc/init.d/supervisord

    /etc/init.d/supervisord  start

     这样,supervisor就启动了。

    配置开机启动

    chkconfig supervisord  on

     可以以下命令查看是否成功

    chkconfig --list | grep  supervisord 

    用浏览器访问9001端口http://192.168.30.119:9001/

     参考:http://www.tuicool.com/articles/y6v2I3

  • 相关阅读:
    title()、upper()、lower()的用法
    Oracle用户无法访问ASM磁盘组问题
    Oracle-RAC监听服务进程关闭失败问题分析处理
    SHELL-字符串操作和变量替换
    Linux-按文件大小排序
    MySQL-重置root密码问题
    Oracle-表空间添加数据文件扩容出错解决措施
    Logstash-使用
    Logstash-工作原理
    ELK+filebeat+kafka搭建Oracle数据库日志平台
  • 原文地址:https://www.cnblogs.com/sfnz/p/6428855.html
Copyright © 2011-2022 走看看