(转)https://www.jianshu.com/p/3658c963d28b

一、安装

  • 源码安装

先下载最新的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 #本地python版本为python2.7
# python2.7 setup.py install #本地python版本为python3以上

二、配置

1.生成配置文件

echo_supervisord_conf > /etc/supervisord.conf

2.启动

supervisord -c /etc/supervisord.conf

查看 supervisord 是否在运行:

ps aux | grep supervisord

3.配置

打开配置文件

vim /etc/supervisord.conf

在配置文件底部,配置include

[include]
files=/etc/supervisor/*.conf #若你本地无/etc/supervisor目录,请自建

用supervisor管理进程,配置如下:

cd /etc/supervisor
vim ossfs.conf # 这里的文件名称自定义

加入以下内容:

; 设置进程的名称,使用 supervisorctl 来管理进程时需要使用该进程名
[program:your_program_name]
command=python server.py --port=9000
;numprocs=1 ; 默认为1
;process_name=%(program_name)s ; 默认为 %(program_name)s,即 [program:x] 中的 x
directory=/home/python/tornado_server ; 执行 command 之前,先切换到工作目录
user=oxygen ; 使用 oxygen 用户来启动该进程
; 程序崩溃时自动重启,重启次数是有限制的,默认为3次
autorestart=true
redirect_stderr=true ; 重定向输出的日志
stdout_logfile = /var/log/supervisord/tornado_server.log
loglevel=info

这里是启动要配置的参数,请根据自己的项目自定义添加

更改了supervisor配置文件,需要重启,运行以下指令:

supervisorctl reload

4.supervisorctl的用法

supervisord : 启动supervisor
supervisorctl reload :修改完配置文件后重新启动supervisor
supervisorctl status :查看supervisor监管的进程状态
supervisorctl start 进程名 :启动XXX进程
supervisorctl stop 进程名 :停止XXX进程
supervisorctl stop all:停止全部进程,注:start、restart、stop都不会载入最新的配置文件。
supervisorctl reread:重新读取配置文件
supervisorctl update:根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启

5.若不使用控制台来管理进程,用浏览器来管理,该如何配置?

打开配置文件

vim /etc/supervisord.conf

配置 inet_http_server

[inet_http_server]
port=127.0.0.1:9001 ; 服务器ip
username=xxx ;自定义
password=xxx ;自定义

三、设置开机启动

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 :
# 设置该脚本为可以执行
sudo chmod +x /etc/init.d/supervisord
# 设置为开机自动运行
sudo update-rc.d supervisord defaults
# 试一下,是否工作正常
service supervisord stop
service supervisord start

若报错:insserv: warning: script 'service' missing LSB tags and overrides,请执行:

sudo apt-get remove insserv

作者:童蒙_
链接:https://www.jianshu.com/p/3658c963d28b
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

supervisor 从安装到使用的更多相关文章

  1. supervisor centos安装

    一.安装配置supervisor 1.安装python自动化工具    #yum install python-setuptools 2.#easy_install supervisor安装super ...

  2. Supervisor的安装以及使用

    1.supervisor的介绍 Supervisor 是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统,通过配置可以实 ...

  3. Linux Supervisor的安装与使用入门

    在linux或者unix操作系统中,守护进程(Daemon)是一种运行在后台的特殊进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事件.由于在linux中,每个系统与用户进行交流的界 ...

  4. supervisor的安装部署及集群管理

    supervisor的安装部署及集群管理 supervisor官网:http://www.supervisord.org/ 参考链接: http://blog.csdn.net/xyang81/art ...

  5. Linux Supervisor的安装与使用入门---SuSE

    Linux Supervisor的安装与使用入门 在linux或者unix操作系统中,守护进程(Daemon)是一种运行在后台的特殊进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事 ...

  6. Linux Supervisor的安装与使用入门---Ubuntun

    Linux Supervisor的安装与使用入门 在linux或者unix操作系统中,守护进程(Daemon)是一种运行在后台的特殊进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事 ...

  7. Supervisor 的安装与配置教程

    简介 Supervisor是一个进程控制系统. 它是一个C/S系统(注意: 其提供WEB接口给用户查询和控制), 它允许用户去监控和控制在类UNIX系统的进程. 它的目标与launchd, daemo ...

  8. Linux进程管理工具Supervisor的安装配置

    目录 Linux进程管理工具Supervisor的安装配置 简介 安装Python包管理工具 安装Supervisor 配置 配置文件参数说明 配置进程管理 启动supervisor 控制进程 交互终 ...

  9. supervisor的安装与简单介绍

    1,介绍 Supervisor是一个进程管理工具,官方的说法 用途就是有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断.当进程中断的时候我希望能自动重新启动它,此时,我就需要 ...

  10. Ubuntu14中supervisor的安装及配置

    supervisor是一款很好用的进程管理工具,其命令也很简单,其安装过程如下: Ubuntu14: 首先保证本地的Python环境是OK的,并且已经安装supervisor包,如果没有安装可以用ea ...

随机推荐

  1. python 单行写法

    if not any([_ in fingers for _ in finger_ids])

  2. 微信小程序做radio,可以拖动进度条

    很简单的一个音乐播放器 data:{ src: 'http://ws.stream.qqmusic.qq.com/M500001VfvsJ21xFqb.mp3?guid=ffffffff82def4a ...

  3. h5页面

    <!DOCTYPE html><html lang="utf-8"><head> <meta charset="UTF-8&qu ...

  4. mysql安装了半天参考了文章搞定了

    https://blog.csdn.net/yelllowcong/article/details/79641313 mysql -uroot -pbrucelee 总结下: 1.安装时注意具体的路径 ...

  5. 【自动化测试】使用Java+selenium填写验证码成功登录

    这是我第一次发博客,若有问题,请多多指教! 本次是为了帮忙解决,如果在平时自动化遇到有验证码填写的情况,我们如何成功登录情况. 思路: 首先我们先将验证码复制并保存成一个图片,然后使用tesserac ...

  6. container

    容器是轻量级的操作系统级虚拟化,可以让我们在一个资源隔离的进程中运行应用及其依赖项.运行应用程序所必需的组件都将打包成一个镜像并可以复用.执行镜像时,它运行在一个隔离环境中,并且不会共享宿主机的内存. ...

  7. GMA Round 1 新程序

    传送门 新程序 程序框图如图所示,当输入的n=时,输出结果的ans是多少? 容易看出该程序求n以内质数个数,50以内有15个. 定位:简单题

  8. __x__(30)0908第五天__导航条的练习 <div>版本

    效果图:  html源代码: <!doctype html> <html> <head> <meta charset="utf-8" /& ...

  9. ElasticSeaarch 遇到的问题 (-)

    1 elasticSearch 不能通过ip访问 智只能通过localhost访问,或者在外网部署的时候不能访问: elasticsearch.yml文件 中将下面的配置去掉注释符,  network ...

  10. java学习之路--I/O流

      java基础学习总结——流 一.JAVA流式输入/输出原理