Linux:supervisor命令的使用

supervisor是Linux下一个便利的启动和监控服务的命令。

举例来说:假如我想同时管理一堆的服务,包括他们的运行和停止。我就可以使用supervisor来管理。

supervisor包括两个命令:supervisord和supervisorctl,分别是后台的守护进程以及命令行管理命令。要安装这两个命令只需要执行sudo apt-get install supervisor即可。

两个命令共用一个配置文件,默认是:/etc/supervisor/supervisor.conf,而supervisor.conf 通过[include] 这个section来引入其它配置文件,一般放在/etc/supervisor/conf.d目录,所以我们可以将需要的文件放到这个目录之下,并将后缀改为.conf。

除了默认的配置之外,一个常用的配置方式是在使用启动的时候指定特定的配置文件,配置方式为:  sudo  supervisord  -c  /path/to/supervisor.conf    ,注意,这时候的配置文件要使用绝对路径,并且配置文件要完整,否则可能会报错。

supervisord只会启动一个supervisord守护进程,剩下的管理工作都交给supervisorctl命令来完成。同样的,如果指定了某一个配置文件来启动服务,那么supervisorctl的命令也要加上相对应的路径来管理:sudo supervisorctl -c /path/to/supervisor.conf,这个命令敲下之后就会进入命令行模式,对应用进行管理。

典型的supervisor.conf配置如下:(配置文件的注释用分号开头)

; supervisor config file
[unix_http_server]  ; supervisor与supervisorctl的通讯
file=/var/run/supervisor.sock   ; (the path to the socket file)  should match serverurl in section supervisorctl
chmod=0700                       ; sockef file mode (default 0700)

[supervisord]  ; 必须有,用来配置supervisord
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; (‘AUTO‘ child log dir, default $TEMP)

; 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]   ; 必须有,用于配置supervisorctl
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; 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 = /path/to/*.conf  # other configuration files you want to include

[program:api4c]  ;应用程序的配置
command=/path/to/python/env/bin/gunicorn -w 1 -b 0.0.0.0:8888  wsgi:application ; 执行你的命令,不能是用于启动守护进程,因为supervisor就是用来作为守护进程的
directory=/home/ubuntu/4c-entry/api4c  ; chdir to here before command run
startsecs=0        ;
stopwaitsecs=0     ;
autostart=true    ; supervisord启动的时候自动运行
autorestart=true  ; 当程序中断的时候是否重启 stop,true,false,unexpected
stdout_logfile=/path/to/logfile.log  ; 必须已经存在stderr_logfile=/path/to/std/err/log/for4c.err

上面是一个基本的服务,用于管理一个服务进程,包含几个必要的section:supervisord、supervisorctl、program:your_program_name、rpcinterface:supervisor、include。

这几个是一定要配置的,缺少supervisord和supervisorctl和rpcinterface:supervisor会报错,include是可选的,如果你没有引入其他的配置文件的话。

关于supervisord和supervisorctl的通讯方式有两种:一种是通过sock来传输,也就是unix_http_server的配置,另一种是inet_http_server,通过http进行通讯,详细的设置可以参考supervisor的配置文档。

supervisor的常用命令:

supervisord -c supervisor.conf                             通过配置文件启动supervisor
supervisorctl -c supervisor.conf status                    察看supervisor的状态
supervisorctl -c supervisor.conf reload                    重新载入 配置文件  更新后可以选择重新载入
supervisorctl -c supervisor.conf start [all] |  [appname]     启动指定/所有 supervisor管理的程序进程
supervisorctl -c supervisor.conf stop [all] | [appname]

命令使用实例:

来源: http://chenxiaoyu.org/2011/05/31/python-supervisor.html

配置项:

[program:hello] 
command=python /home/smallfish/hello.py 
autorstart=true 
stdout_logfile=/home/smallfish/hello.log
命令
shell> sudo /etc/init.d/supervisor start   -- 启动supervisor服务 
shell> sudo supervisorctl status hello     -- 获取hello服务的状态,因为是autorstart,这里已经启动了 hello  RUNNING    pid 1159, uptime 0:20:32 
shell> sudo supervisorctl stop hello       -- 停止hello服务 hello: stopped 
shell> sudo supervisorctl stop hello       -- 再次停止hello,会有错误信息 hello: ERROR (not running) 
shell> sudo supervisorctl start hello      -- 启动hello服务 hello: started

常用的配置项:

详见: http://supervisord.org/configuration.html

时间: 2024-08-28 00:41:02

Linux:supervisor命令的使用的相关文章

Linux常用命令(echo、date、ls、cd、history、cat)

一.linux常用命令有很多今天我们来总结一下常用的入门命令: 1.linux下关机命令:poweroff.init 0.halt.shutdown -h now 2.linux下重启命令:reboot.init 6.shutdown -r now 3.shutdown命令: 格式:shutdown  options TIME 其中options有以下几个: -r:执行重启 -c:取消shutdown命令 -h:执行关机 其中TIME有以下几个: now:表示现在 +m:相对时间表示法,从命令提

Linux常用命令学习

补充: 管道符号:   | 含义: 命令1 的正确输出作为命令2的输出对象. 格式: 命令1   |  命令2 举例: ls -ctrl |  more 常用命令: netstat   -an    |  grep    ESTABLISHED         查看正在连接的端口 netstat   -an    |   grep   LISTEN find   .    -name   test.txt    |     cat    -n          在当前目录下找到文件名为test.

linux 解压缩命令

linux zip命令 zip -r myfile.zip ./*将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件,-r表示递归压缩子目录下所有文件. 2.unzipunzip -o -d /home/sunny myfile.zip把myfile.zip文件解压到 /home/sunny/-o:不提示的情况下覆盖文件:-d:-d /home/sunny 指明将文件解压缩到/home/sunny目录下: 3.其他zip -d myfile.zip smart.txt删除压缩文件中

linux常用命令详解

linux常用命令 cut命令 例如:cut -d\| -f1,4 xx.txt -d 表示字段分隔符 -f 表示要显示的字段域,如果域之间,(逗号)隔开表示显示对应的单个域,如果用-隔开表示显示连续的域 sort命令 例如:sort -t\| -k2 xx.txt -n 按数值排序 -r 降序 -t 字段分隔符 -k 以哪个字段为关键字进行排序 -u 去重 -f 排序时不区分大小写 uniq命令 注意:使用uniq命令时,一定要先进行排序 -c 显示文件中行重复的次数 -d 只显示重复的行 -

linux mail 命令参数

使用mail发邮件时,必须先将sendmail服务启动. mail –s “邮件主题” –c”抄送地址” –b “密送地址” -- -f 发送人邮件地址 –F 发件人姓名 < 要发送的邮件内容 三种常用格式发信    mail -s test [email protected]                         #第一种方法,你可以把当前shell当成编辑器来用,编辑完内容后Ctrl-D结束    echo “mail content”|mail -s test [email pr

使用配置hadoop中常用的Linux(ubuntu)命令

生成key: $ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa $ cat ~/.ssh/id_dsa.pub >> ~/.ssh/authorized_keys -t   密钥类型可以用 -t 选项指定.如果没有指定则默认生成用于SSH-2的RSA密钥. -f filename             指定密钥文件名. 来源:http://www.aboutyun.com/thread-6487-1-1.html 远程登录执行shell命令key ssh远

Linux常用命令大全

系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS / DMI) hdparm -i /dev/hda 罗列一个磁盘的架构特性 hdparm -tT /dev/sda 在磁盘上执行测试性读取操作 cat /proc/cpuinfo 显示CPU info的信息 cat /proc/interrupts 显示中断 cat /proc/meminfo 校验

(转)linux常用命令

原地址:http://www.cnblogs.com/svage/p/3700122.html 1.删除目录及子目录下的 .svn目录 find . -type d -name ".svn" | xargs rm -rf 2./tmp 目录的权限 drwxrwxrwt rwt的意思是:对目录有执行权限,但不能删除,即sticky bit rwx : 可读可写可执行 4+2+1 3.改变群组.用户.权限 chgrp   群组名   改变的目录 groupadd -g gid gname

linux date 命令使用

http://blog.sina.com.cn/s/blog_654c6ec70101mx99.html http://codingstandards.iteye.com/blog/1157513 linux date 命令使用,码迷,mamicode.com

Linux 常用命令之文件和目录

1. cd 命令格式:cd  [dirName](cd和目录之间使用空格隔开) 作用:切换当前目录至dirName. 实例: cd /home 切换当前目录到/home (查看当前目录命令为pwd) cd .. 返回上一级目录 cd ../.. 返回上两级目录 cd ~ 进入个人的主目录 2. ls 命令格式:ls [选项] [目录名] (目录名为空时表示当前目录) 作用: 查看目录中的文件 常用选项: -a, –all 列出目录下的所有文件,包括以 . 开头的隐含文件. -l 除了文件名之外,