supervisor部署go应用

# 开始

1
2
3
4
5
6
7
8
9
sudo dnf install -y epel-release
sudo yum update -y
sudo yum -y install supervisor

systemctl start supervisord.service #启动supervisord服务
systemctl list-unit-files|grep enabled #查看已启动的服务列表
systemctl enable supervisord.service #在开机时启用supervisord服务
systemctl is-enable supervisord.service #显查看supervisord服务是否开机启动
systemctl status supervisord.service #显示supervisord服务的状

备注 systemctl 命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# 启动一个服务
systemctl start xxx.service
# 关闭一个服务
systemctl stop xxx.service
# 重启一个服务
systemctl restart xxx.service
# 显示一个服务的状态
systemctl status xxx.service
# 在开机时启用一个服务
systemctl enable xxx.service
# 在开机时禁用一个服务
systemctl disable xxx.service
# 查看服务是否开机启动
systemctl is-enabled xxx.service
# 查看已启动的服务列表
systemctl list-unit-files|grep enabled
# 查看启动失败的服务列表
systemctl –failed

# 配置supervisor配置文件

安装完之后默认在/etc 目录下有个supervisord.conf我们打开该文件去掉前面的 ; 号

1
2
3
4
5
;[include]
;files = supervisord.d/*.ini

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

打开 /etc/supervisord.d/ 目录下面就是配置文件所在的目录(如果没有该目录可以自己手动创建一个当然也可以修改上面的配置文件**[include]** 下面的 files=xxx 修改成我们想要的) ,配置文件以写多个比如a.ini b.ini…. 这里就不啰嗦了直接搞配置文件这里我们新建一个main.ini 内容如下

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# 子进程名称 xxx
[program:xxx]
directory=/data/cgi/xxx/
command=/data/cgi/xxx/main
autostart=true
autorestart=true
#
user=root
stdout_logfile=/data/cgi/xxx/logs/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=2
stdout_capture_maxbytes=1MB
stderr_logfile=/data/cgi/xxx/logs/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=2
stderr_capture_maxbytes=1MB

# supervisor命令说明

1
2
3
4
5
6
7
supervisorctl status        //查看所有进程的状态
supervisorctl start xxx      //启动xxx
supervisorctl stop xxx       //停止xxx
supervisorctl restart xxx    //重启xxx
supervisorctl restart all    //重启所有
supervisorctl update        //配置文件修改后使用该命令加载新的配置
supervisorctl reload        //重新启动配置中的所有程序
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计