【Linux】Supervisor快速使用教程

整理转载自:
Supervisor的安装与使用入门
CentOS 之 Supervisor

本文档针对CentOS,也是我搭环境记录的笔记,其他系统可以参考最下面的参考资料。

安装supervisor

1
yum install supervisor

生成配置文件

Creating a Configuration File

Once the Supervisor installation has completed, run echo_supervisord_conf. This will print a “sample” Supervisor configuration file to your terminal’s stdout.

Once you see the file echoed to your terminal, reinvoke the command as echo_supervisord_conf > /etc/supervisord.conf. This won’t work if you do not have root access.

If you don’t have root access, or you’d rather not put the supervisord.conf file in /etc/supervisord.conf`, you can place it in the current directory (echo_supervisord_conf > supervisord.conf) and start supervisord with the -c flag in order to specify the configuration file location.

For example, supervisord -c supervisord.conf. Using the -c flag actually is redundant in this case, because supervisord searches the current directory for a supervisord.conf before it searches any other locations for the file, but it will work. See Running Supervisor for more information about the -c flag.

Once you have a configuration file on your filesystem, you can begin modifying it to your liking.

打开supervisor的配置文件

1
vi /etc/supervisord.conf

将supervisord的配置文件拷贝到/home/supervisord/目录下,这是我的习惯,将配置文件集中管理

先创建目录

1
mkdir /home/supervisord/

然后拷贝文件过去

1
cp /etc/supervisord.conf /home/supervisord/supervisord.conf

编辑配置文件

1
vi /home/supervisord/supervisord.conf

在/home/supervisord/supervisord.conf最后追加如下内容,这个例子是配置shadowsocks

1
2
3
4
5
6
7
[program:shadowsocks]
command=ss-server -c /home/ss/config.json
user=root
autostart=true
autorestart=true
stderr_logfile=/home/ss/err.log
stdout_logfile=/home/ss/out.log

最后,启动

1
supervisord -c /home/supervisord/supervisord.conf

如果想要supervisord开机自启动

编辑启动文件

1
vi /etc/rc.local

在新行添加要执行的命令

1
supervisord -c /home/supervisord/supervisord.conf

常用命令

查看所有action

1
supervisorctl help

控制所有进程

1
2
3
supervisorctl start all
supervisorctl stop all
supervisorctl restart all

控制目标进程

1
2
3
supervisorctl stop shadowsocks
supervisorctl start shadowsocks
supervisorctl restart shadowsocks

备用教程

Supervisor是一个进程管理工具,官方的说法

用途就是有一个进程需要每时每刻不断的跑,但是这个进程又有可能由于各种原因有可能中断。当进程中断的时候我希望能自动重新启动它,此时,我就需要使用到了Supervisor

这个工具主要就两个命令:

supervisord : supervisor的服务器端部分,启动supervisor就是运行这个命令

supervisorctl:启动supervisor的命令行窗口。

安装(Centos):

1
2
yum install python-setuptools
easy_install supervisor

如果easy_install不好使就从官方下载:
然后通过python安装:

1
2
3
tar zxf supervisor-3.1.3.tar.gz
cd supervisor
python setup.py install

成功安装后可以登陆python控制台输入import supervisor 查看是否能成功加载。

生成配置文件(supervisord.conf):

1
echo_supervisord_conf > /etc/supervisord.conf

修改配置文件:
(更多配置说明请参考:http://supervisord.org/configuration.html)
运行命令:

1
supervisord -c /etc/supervisord.conf  //启动supervisor
1
supervisorctl //打开命令行

另外有一个坑需要注意:如果修改了 /etc/supervisord.conf ,需要执行 supervisorctl reload 来重新加载配置文件,否则不会生效。。

2