supervisor升級

前言

centos7.X系統yum安裝的supervisor版本是3.X,版本較python工具安裝的低java

  • yum安裝supervisor
yum -y install supervisor
  • 若是以前已經使用yum安裝過,先備份配置,卸載supervisor便可
  • 刪除supervisor
yum -y remove supervisor

升級supervisor

Supervisor安裝與配置

安裝Python包管理工具(easy_install)

yum install python-setuptools

安裝Supervisor

easy_install supervisor

配置Supervisor應用守護

a) 經過運行echo_supervisord_conf程序生成supervisor的初始化配置文件,以下所示:python

mkdir /etc/supervisord.d
echo_supervisord_conf > /etc/supervisord.conf

而後查看路徑下的supervisord.conf。在文件尾修改配置git

[include]
files = supervisord.d/*.ini

建立一個.ini文件,放在目錄"/etc/supervisord.d/github

[program:app-portal]    ;程序名稱,終端控制時須要的標識
directory=/data/services/app-portal/        ; 命令執行的目錄
environment=JAVA_HOME="/usr/local/jdk/",JAVA_BIN="/usr/local/jdk/bin",java="/usr/local/jdk/bin/java"        ; 進程環境變量
command=/usr/local/jdk/bin/java -Xms2g -Xmx2g -jar /data/services/app-portal/app-portal.jar     ; 運行程序的命令
autostart=true      ;自動啓動
autorestart=true        ; 程序意外退出是否自動重啓
user=root        ; 進程執行的用戶身份
startsecs=5
priority=1
stopasgroup=true
killasgroup=true
stdout_logfile=/data/logs/supervisor/%(program_name)s.log
stderr_logfile=/data/logs/supervisor/%(program_name)s.log

運行supervisord,查看是否生效shell

supervisord -c /etc/supervisord.conf
ps -ef | grep MGToastServer

配置Supervisor開機啓動

  • 新建一個「supervisord.service」文件
# dservice for systemd (CentOS 7.0+)
# by aiker (https://github.com/donxan)
[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl shutdown
ExecReload=/usr/bin/supervisorctl reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
  • 將文件拷貝至"/usr/lib/systemd/system/supervisord.service"centos

  • 執行命令
systemctl enable supervisord
  • 執行命令來驗證是否爲開機啓動
systemctl is-enabled supervisord

配置完成

經常使用的相關管理命令

supervisorctl restart <application name> ;重啓指定應用
supervisorctl stop <application name> ;中止指定應用
supervisorctl start <application name> ;啓動指定應用
supervisorctl restart all ;重啓全部應用
supervisorctl stop all ;中止全部應用
supervisorctl start all ;啓動全部應用
相關文章
相關標籤/搜索