Supervisor 详细用法

Linux May 26, 2015

之前说 Ghost 博客的时候提到过这个东西,用 Supervisor 守护 node 的进程,当时的配置文件是长这个样子的

[program:homepage]
command = node /var/www/homepage/index.js
directory = /var/www/homepage
user = root
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/homepage.log
stderr_logfile = /var/log/supervisor/homepage_err.log
environment = NODE_ENV="production"

安装

pip install supervisor

创建配置文件

cd /etc/supervisor/conf.d
nano test.conf

配置文件一般是这个格式,

[program:homepage]
command = python /var/www/test/homepage.py
user = root
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/homepage.log
stderr_logfile = /var/log/supervisor/homepage_err.log

应该都能看懂吧。

生效

简单粗暴一点可以直接 service supervisor restart,当然这不是最优雅的方法,优雅一点,可以

supervisorctl start test supervisorctl stop test,查看当前状态可以输入 supervisorctl status,全部关闭可以 supervisorctl shutdown

Web控制台

supervisord.conf 中开启 HTTP 即可

[inet_http_server]
port=xxx.xx.xxx.xxx:8794
username=username
password=pwd

浏览器打开这个地址就可以看到相关内容

可以进行管理,查看日志等操作。

Tags

Jie Li

🚘 On-road / 📉 US Stock / 💻 Full Stack Developer / 🎓 Grad Student / ®️ ENTJ

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.