Supervisor 进程自动重启
安装
- 安装python pip
sudo apt-get install python-pip
- 安装supervisor
# 用python安装
python -m pip install supervisor
配置文件
生成配置文件
echo_supervisord_conf > /etc/supervisor/supervisord.conf
# 或者使用
sudo su - root -c "echo_supervisord_conf > /etc/supervisor/supervisord.conf"
1.supervisord.conf配置
unix_http_server
[unix_http_server]
file=/tmp/supervisor.sock ; the path to the socket file
chmod=0766 ; socket file mode (default 0700)
;chown=nobody:nogroup ; socket file uid:gid owner
;username=user ; default is no username (open server)
;password=123 ; default is no password (open server)
在底部新增代码
[program:app_name] # 程序名字
directroy=/home/data/www/WalletAppService # 程序所在的主目录
command=node /home/data/www/WalletAppService/bin/www # 执行程序的命令
autostart=true # 是否自动启动程序
startsecs=5 # 程序启动5秒种没有中断默认启动成功
autorestart=true # 是否重启
startretries=3 # 重启失败尝试次数
user=root # 执行程序的用户
启动 supervisor
sudo supervisord
或
sudo supervisord -c /etc/supervisor/supervisord.conf
supervisorctl的使用
sudo supervisorctl
显示下面结果表示成功
app_name STARTING
supervisorctl常用命令
### 当配置文件改变时, 重新启动supervisor
> reload
Really restart the remote supervisord process y/N?
>y
### 停止supervisord
sudo supervisorctl shutdown
### 停止进程
sudo supervisorctl stop app_name
### 停止全部进程
sudo supervisorctl stop all