layout: post
title: 守護進程之supervisor
categories: [blog]
tags: [SOA]
description:
守護進程之supervisor
? SOA服務需要守護進程保證服務不會掛掉,可以在Container啟動的時候或者使用發布系統啟動Damon,SOA中間件同時接收到supervisor對上一個Git Head的INT信號,實現新的git commit的發布,這里面涉及到一個注冊中心通知服務的時間。
? 這意味著,可以在發布系統接入supervisor實現更好的管控。
[TOC]
介紹
Supervisor is a client/server system that allows its users to control a number of processes on UNIX-like operating systems.
安裝supervisor
brew install supervisor
sudo apt-get install supervisor
修改配置文件
sudo vim /etc/supervisord.d/arena.api.melody.ini
跳到最后一行,插入以下內容:
[www-data@vpca-arena-api-melody-1 supervisord.d]$ cat arena.api.melody.ini
[program:arena.api.melody]
command=sh script/start_service.sh //要后臺運行的命令[program:程序名]
autorestart=true //程序隨supervisor啟動
process_name=arena.api.melody
numprocs=1
stopsignal=INT
directory=/data/arena.api.melody
user=www-data
redirect_stderr=true
stdout_logfile=/data/log/supervisor/arena.api.melody.out //指定標準日志輸出文件
stdout_logfile_maxbytes=100MB
stdout_logfile_backups=10
stopasgroup=true
killasgroup=true
可使用模版生成配置文件
echo_supervisord_conf > /etc/supervisord.d/servername.conf
啟動supervisor和server
sudo service supervisor start
ps -ef | grep servername
客戶端控制
作為C/S架構,supervisord是服務端,可以通過客戶端supervisorctl控制服務端的運行。
sudo supervisorctl start servername
sudo supervisorctl stop servername
sudo supervisorctl restart servername
sudo supervisorctl reload
sudo supervisorctl start all