supervisor安裝和命令介紹

一陈惰、安裝

下載最新的supervisor安裝包:https://pypi.python.org/pypi/supervisor

cd /usr/local/src

wget https://pypi.python.org/packages/7b/17/88adf8cb25f80e2bc0d18e094fcd7ab300632ea00b601cbbbb84c2419eae/supervisor-3.3.2.tar.gz

tar -zxvf supervisor-3.3.2.tar.gz

cd supervisor-3.3.2

python setup.py install

Tips:錯(cuò)誤1:ImportError: No module named setuptools

## 下載pip
wget https://files.pythonhosted.org/packages/c2/f7/c7b501b783e5a74cf1768bc174ee4fb0a8a6ee5af6afa92274ff964703e0/setuptools-40.8.0.zip
unzip setuptools-40.8.0.zip 
cd setuptools-40.8.0
python setup.py install

Tips:錯(cuò)誤2:error: Could not find suitable distribution for Requirement.parse(‘meld3>=0.6.5‘)畦徘,安裝meld擴(kuò)展

wget https://pypi.python.org/packages/45/a0/317c6422b26c12fe0161e936fc35f36552069ba8e6f7ecbd99bbffe32a5f/meld3-1.0.2.tar.gz#md5=3ccc78cd79cffd63a751ad7684c02c91
tar zxvf meld3-1.0.2.tar.gz
cd meld3-1.0.2
python setup.py install

Tips:本地python版本為python3以下

二、配置

1.生成配置文件

echo_supervisord_conf > /etc/supervisord.conf

2.啟動(dòng)

supervisord -c /etc/supervisord.conf

##查看 supervisord 是否在運(yùn)行:

ps aux | grep supervisord

3.基礎(chǔ)配置

(1)打開配置文件

vim /etc/supervisord.conf

(2)在配置文件底部抬闯,配置include

[include]
files=/etc/supervisor/*.conf  #若你本地?zé)o/etc/supervisor目錄井辆,請(qǐng)自建

(3)用supervisor管理進(jìn)程,配置如下:

cd /etc/supervisor
vim ossfs.conf # 這里的文件名稱自定義

(4)加入以下內(nèi)容:

; 設(shè)置進(jìn)程的名稱溶握,使用 supervisorctl 來管理進(jìn)程時(shí)需要使用該進(jìn)程名
[program:your_program_name] 
command=python server.py --port=9000
;numprocs=1                 ; 默認(rèn)為1
;process_name=%(program_name)s   ; 默認(rèn)為 %(program_name)s杯缺,即 [program:x] 中的 x
directory=/home/python/tornado_server ; 執(zhí)行 command 之前,先切換到工作目錄
user=oxygen                 ; 使用 oxygen 用戶來啟動(dòng)該進(jìn)程
; 程序崩潰時(shí)自動(dòng)重啟睡榆,重啟次數(shù)是有限制的萍肆,默認(rèn)為3次
autorestart=true            
redirect_stderr=true        ; 重定向輸出的日志
stdout_logfile = /var/log/supervisord/tornado_server.log
loglevel=info

(5)這里是啟動(dòng)要配置的參數(shù),請(qǐng)根據(jù)自己的項(xiàng)目自定義添加
更改了supervisor配置文件胀屿,需要重啟,運(yùn)行以下指令:

supervisorctl reload

(6)服務(wù)啟動(dòng)

supervisord -c /etc/supervisord.conf 

(7)用瀏覽器來管理進(jìn)程配置
打開配置文件

vim /etc/supervisord.conf

配置 inet_http_server

[inet_http_server]       
port=127.0.0.1:9001; 服務(wù)器ip
username=username ;自定義
password=password ;自定義

三塘揣、supervisorctl的用法

supervisord : 啟動(dòng)supervisor

supervisorctl reload :修改完配置文件后重新啟動(dòng)supervisor

supervisorctl status :查看supervisor監(jiān)管的進(jìn)程狀態(tài)

supervisorctl start all | 進(jìn)程名 :?jiǎn)?dòng)全部或某進(jìn)程

supervisorctl stop all | 進(jìn)程名 :停止全部或某進(jìn)程

supervisorctl stop all:停止進(jìn)程,注:start宿崭、restart亲铡、stop都不會(huì)載入最新的配置文件。

supervisorctl update:根據(jù)最新的配置文件葡兑,啟動(dòng)新配置或有改動(dòng)的進(jìn)程奖蔓,配置沒有改動(dòng)的進(jìn)程不會(huì)受影響而重啟

四、設(shè)置開機(jī)啟動(dòng)

(1)添加開機(jī)腳本

vim /etc/init.d/supervisord

腳本如下:

#! /bin/sh
### BEGIN INIT INFO
# Provides:          supervisord
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

# Author: Dan MacKinlay <danielm@phm.gov.au>
# Based on instructions by Bertrand Mathieu
# http://zebert.blogspot.com/2009/05/installing-django-solr-varnish-and.html

# Do NOT "set -e"

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
DESC="Description of the service"
NAME=supervisord
DAEMON=/usr/local/bin/supervisord
DAEMON_ARGS=" -c /etc/supervisord.conf"
#PIDFILE=/var/run/$NAME.pid
PIDFILE=/tmp/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

#
# Function that starts the daemon/service
#
do_start()
{
    # Return
    #   0 if daemon has been started
    #   1 if daemon was already running
    #   2 if daemon could not be started
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
        || return 1
    start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
        $DAEMON_ARGS \
        || return 2
    # Add code here, if necessary, that waits for the process to be ready
    # to handle requests from services started subsequently which depend
    # on this one.  As a last resort, sleep for some time.
}

#
# Function that stops the daemon/service
#
do_stop()
{
    # Return
    #   0 if daemon has been stopped
    #   1 if daemon was already stopped
    #   2 if daemon could not be stopped
    #   other if a failure occurred
    start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
    RETVAL="$?"
    [ "$RETVAL" = 2 ] && return 2
    # Wait for children to finish too if this is a daemon that forks
    # and if the daemon is only ever run from this initscript.
    # If the above conditions are not satisfied then add some other code
    # that waits for the process to drop all resources that could be
    # needed by services started subsequently.  A last resort is to
    # sleep for some time.
    start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
    [ "$?" = 2 ] && return 2
    # Many daemons don't delete their pidfiles when they exit.
    rm -f $PIDFILE
    return "$RETVAL"
}

#
# Function that sends a SIGHUP to the daemon/service
#
do_reload() {
    #
    # If the daemon can reload its configuration without
    # restarting (for example, when it is sent a SIGHUP),
    # then implement that here.
    #
    start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
    return 0
}

case "$1" in
  start)
    [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
    do_start
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  stop)
    [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
    do_stop
    case "$?" in
        0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
        2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
    esac
    ;;
  #reload|force-reload)
    #
    # If do_reload() is not implemented then leave this commented out
    # and leave 'force-reload' as an alias for 'restart'.
    #
    #log_daemon_msg "Reloading $DESC" "$NAME"
    #do_reload
    #log_end_msg $?
    #;;
  restart|force-reload)
    #
    # If the "reload" option is implemented then remove the
    # 'force-reload' alias
    #
    log_daemon_msg "Restarting $DESC" "$NAME"
    do_stop
    case "$?" in
      0|1)
        do_start
        case "$?" in
            0) log_end_msg 0 ;;
            1) log_end_msg 1 ;; # Old process is still running
            *) log_end_msg 1 ;; # Failed to start
        esac
        ;;
      *)
        # Failed to stop
        log_end_msg 1
        ;;
    esac
    ;;
  *)
    #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
    echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
    exit 3
    ;;
esac
:

(2)設(shè)置該腳本為可以執(zhí)行

sudo chmod +x /etc/init.d/supervisord

(3)設(shè)置為開機(jī)自動(dòng)運(yùn)行

sudo update-rc.d supervisord defaults

(4)試一下讹堤,是否工作正常

service supervisord stop

service supervisord start

若報(bào)錯(cuò):insserv: warning: script 'service' missing LSB tags and overrides吆鹤,請(qǐng)執(zhí)行:

sudo apt-get remove insserv

五、錯(cuò)誤排查

1洲守、unix:///var/run/supervisor/supervisor.sock no such file

問題描述:安裝好supervisor沒有開啟服務(wù)直接使用supervisorctl報(bào)的錯(cuò)
解決辦法:?jiǎn)?dòng)服務(wù)

supervisord -c /etc/supervisord.conf 

2疑务、啟動(dòng)了多個(gè)supervisord服務(wù),導(dǎo)致無法正常關(guān)閉服務(wù)

問題描述:多次運(yùn)行supervisord -c /etc/supervisord.conf 或supervisord岖沛,導(dǎo)致有些進(jìn)程被多個(gè)superviord管理暑始,無法正常關(guān)閉進(jìn)程。
解決辦法:kill相關(guān)的進(jìn)程婴削。

ps -fe | grep supervisord    #查看所有啟動(dòng)過的supervisord服務(wù)

kill -9 PID                           #kill相關(guān)進(jìn)程

3、supervisord 啟動(dòng)失敗 Error: Another program is already listening on a port that one of our HTTP serve...

unlink /var/run/supervisor.sock
unlink /tmp/supervisor.sock 

這個(gè)錯(cuò)誤的原因就是supervisor.sock 這個(gè)文件會(huì)被系統(tǒng)自動(dòng)刪除或者其它原因不存在了牙肝,刪除軟連接就可以了唉俗。 supervisor.sock 生成的位置可以去 supervisor 的配置文件中找到嗤朴。

轉(zhuǎn)載:http://www.reibang.com/p/3658c963d28b

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市虫溜,隨后出現(xiàn)的幾起案子雹姊,更是在濱河造成了極大的恐慌,老刑警劉巖衡楞,帶你破解...
    沈念sama閱讀 221,548評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件吱雏,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡瘾境,警方通過查閱死者的電腦和手機(jī)歧杏,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,497評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來迷守,“玉大人犬绒,你說我怎么就攤上這事《以洌” “怎么了凯力?”我有些...
    開封第一講書人閱讀 167,990評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)礼华。 經(jīng)常有香客問我咐鹤,道長(zhǎng),這世上最難降的妖魔是什么圣絮? 我笑而不...
    開封第一講書人閱讀 59,618評(píng)論 1 296
  • 正文 為了忘掉前任祈惶,我火速辦了婚禮,結(jié)果婚禮上晨雳,老公的妹妹穿的比我還像新娘行瑞。我一直安慰自己,他們只是感情好餐禁,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,618評(píng)論 6 397
  • 文/花漫 我一把揭開白布血久。 她就那樣靜靜地躺著,像睡著了一般帮非。 火紅的嫁衣襯著肌膚如雪氧吐。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,246評(píng)論 1 308
  • 那天末盔,我揣著相機(jī)與錄音筑舅,去河邊找鬼。 笑死陨舱,一個(gè)胖子當(dāng)著我的面吹牛翠拣,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播游盲,決...
    沈念sama閱讀 40,819評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼误墓,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼蛮粮!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起谜慌,我...
    開封第一講書人閱讀 39,725評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤然想,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后欣范,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體变泄,經(jīng)...
    沈念sama閱讀 46,268評(píng)論 1 320
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡幢码,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,356評(píng)論 3 340
  • 正文 我和宋清朗相戀三年汁掠,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片剧包。...
    茶點(diǎn)故事閱讀 40,488評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡驳癌,死狀恐怖滑燃,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情颓鲜,我是刑警寧澤表窘,帶...
    沈念sama閱讀 36,181評(píng)論 5 350
  • 正文 年R本政府宣布,位于F島的核電站甜滨,受9級(jí)特大地震影響乐严,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜衣摩,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,862評(píng)論 3 333
  • 文/蒙蒙 一昂验、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧艾扮,春花似錦既琴、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,331評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至酌予,卻和暖如春磺箕,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背抛虫。 一陣腳步聲響...
    開封第一講書人閱讀 33,445評(píng)論 1 272
  • 我被黑心中介騙來泰國(guó)打工松靡, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人建椰。 一個(gè)月前我還...
    沈念sama閱讀 48,897評(píng)論 3 376
  • 正文 我出身青樓雕欺,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子阅茶,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,500評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容