supervisor 进程管理

主要包含后台进程 supervisord 和控制台 supervisorctl 两个程序

supervisor
# 官方文档 http://www.supervisord.org/installing.html

# 此程序是用python开发,python2.7.x 运行中没有发现问题.
# 目标机器没有pip, 所以使用离线安装. 下载以下三个压缩包最新版:
# https://pypi.org/pypi/supervisor/
# https://pypi.org/pypi/setuptools/
# https://pypi.org/pypi/meld3/ # 复制到目标机器, 解压,安装.
sudo tar zxf meld3-2.0..tar.gz
sudo tar zxf supervisor-4.0..tar.gz
sudo unzip setuptools-41.2..zip cd setuptools-41.2.
sudo python setup.py install cd ../meld3-2.0.
sudo python setup.py install cd ../supervisor-4.0.
sudo python setup.py install # 留意安装信息显示的安装位置
...
Installing echo_supervisord_conf script to /usr/bin
Installing supervisorctl script to /usr/bin
Installing supervisord script to /usr/bin # 生成配置文件示例格式,可在此基础修改
echo_supervisord_conf > /etc/supervisor/supervisord.conf # ------------------------- supervisord.conf ---------------------------
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file) [inet_http_server]
port=0.0.0.0:
username=admin
password= [supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups= ; (num of main logfile rotation backups;default )
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds= ; (min. avail startup file descriptors;default )
minprocs= ; (min. avail process descriptors;default ) [rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
username=admin ; should be same as http_username if set
password= ; should be same as http_password if set [include]
files = conf.d/*.conf # 使用包含子目录的方式,指定单个接管的程序
# ------------------------- /etc/supervisor/conf.d/test.demo.conf ---------------
[program:test.demo]
command=dotnet Csharp_class.dll
directory=/webapp/test.demo/
process_name=%(program_name)s
stderr_logfile=/var/log/test.demo.log
stdout_logfile=/var/log/test.demo.log
environment=ASPNETCORE_ENVIRONMENT=Production
user=root
stopsignal=INT
autostart=true
autorestart=true
startsecs=3 # 启动服务
# 可以 -c 指定配置文件,也可不指定,程序将自动寻找 supervisor.conf
sudo supervisord -c /etc/supervisor/supervisord.conf # 注意:一台机器不能有多个同名配置文件.
# 某服务器就因为有 /etc/supervisord.conf 但是启动服务用的 -c /etc/supervisor/supervisord.conf
# 两处配置文件内容不同导致进入 supervisorctl 始终出现错误: unix ///var/run/supervisor.sock refused connection # ----------------------------- shell ----------------------------------
supervisorctl # 进入shell 如果配置正确,登录后将直接列出管理的程序 status # 列出状态
version # 版本
help
shutdown # 结束 supervisord 服务
reread # 重读配置文件,列出变化
update # 重读配置文件并生效(默认更新全部),指定名称则更新单个

start test # 启动单个
start all # 启动全部
stop test # 停止单个
stop all # 停止全部
restart test # 重启单个
restart all # 重启全部
remove test.demo # 移除 test.demo
## 如果更改了配置文件,一定要先reread, 然后 update ,
# 直接 restart 只会重新载入程序代码,不会重载配置文件。
# 例如我改了/etc/supervisor/conf.d/demo.conf
# 必须先reread, 提示发现变化后,再执行 update demo 才能让配置生效。

如果需要开机自动启动,可将其安装为系统服务:

# --------------- 安装为系统服务 ---------------------------------------
# 安装时会产生服务文件: cat /usr/lib/systemd/system/supervisord.service
# ll /etc/systemd/system/multi-user.target.wants 时可以
# 看到supervisord.service文件的真实链接
# 当 systemctl enable supervisord 时,则将此链接作为服务配置文件 [Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target [Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s [Install]
WantedBy=multi-user.target # 如果已经有运行的 supervisor及程序,需要先进入shell, stop all
# 然后再 kill -9 对应的supervisor主程序,使用服务管理的方式启动。
sudo systemctl enable supervisord
sudo systemctl start supervisord
sudo systemctl status supervisord
sudo systemctl list-unit-files   # 检查列表中是否存在并且 enabled

systemd 参考: http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-commands.html

今天加入了一个nodejs程序, 添加配置文件到 /etc/supervisor/conf.d

[program:parsoid]
command=node bin/server.js
directory=/opt/parsoid
process_name=%(program_name)s
stderr_logfile=/opt/parsoid/logs/err.log
stdout_logfile=/opt/parsoid/logs/parsoid.log user=root
stopsignal=INT
autostart=true
autorestart=true
startsecs=3

依次执行下方测试:

supervisorctl

>reread  # 发现
>update >status
>stop parsoid # 测试停止
>start parsoid # 测试启动
>status

我现在的公司,主要用它来管理 dotnet 程序

centos7 安装 dotnet-sdk

rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm

yum install dotnet-sdk-3.1

最新文章

  1. JavaScript中‘this’关键词的优雅解释
  2. 《苹果开发之Cocoa编程》挑战2 创建一个数据源 练习
  3. Caffe-windows上训练自己的数据
  4. Ant -- Another Neat Tool
  5. 转: $GLOBALS['HTTP_RAW_POST_DATA'] 和$_POST的区别
  6. 终于可以发布Delphi下收点OSGI精髓皮毛而设计的插件框架WisdomPluginFramework
  7. hibernate+mysql 8小时问题
  8. Android:常见错误提示
  9. android报错及解决1--Bitmap加载时,报bitmap size exceeds VM budget
  10. python学习之元组
  11. NIO 入门
  12. vue原来可以这样上手
  13. JavaScript中几个相似方法对比
  14. HTML篇(上)
  15. sqlmap 基本应用
  16. 在Mac下安装mongodb
  17. crtontab定时执行任务
  18. ES6 入门Promise
  19. java ee期末项目相关
  20. js完整教程一 : 基本概念和数组操作

热门文章

  1. 5-5 可视化库Seaborn-多变量分析绘图
  2. 日志分析利器Splunk的搭建、使用、破解
  3. pyquery解析库
  4. Pwn-level2
  5. (day53)五、模型层(ORM)、settings文件配置
  6. 鲜贝7.3--python安装
  7. 【[POI2012]TOU-Tour de Byteotia】
  8. Django signal(信号)
  9. linux 下安装 python ngix 项目发布流程
  10. 【2019.7.26 NOIP模拟赛 T3】化学反应(reaction)(线段树优化建图+Tarjan缩点+拓扑排序)