部署supervisord
yum install supervisor
systemctl enable supervisord
systemctl start supervisord
如果出现:No package supervisor available.
可以先安装:epel-release
yum install epel-release
配置文件
supervisord的配置文件在/etc/superviosrd.conf
[root@VM-0-14-centos supervisord.d]# tail /etc/supervisord.conf
;priority=999 ; the relative start priority (default 999)
; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves.
[include]
files = supervisord.d/*.ini
在/etc/supervisord.d/目录下,新增一个配置文件xxx.ini
[program:appserver]
user=root
command= /var/www/api/appserver -f /var/www/api/etc/appserver-prod.yaml
directory=/var/www/api/
autostart=true
autorestart=true
stdout_logfile=api.out
stderr_logfile=api.err
[program:xxxx]
...
配置文件参考:Configuration File — Supervisor 4.2.5 documentation (supervisord.org)
注意,修改xxx.ini文件后,需要执行 supervisorctl update 新的配置文件才能生效。
- supervisorctl update 重新加载配置文件
- supervisorctl start all 启动所有的服务
- supervisorctl start xxxx 单独启动xxx服务
- supervisorctl restart xxxx 重启
编译打包, 上传文件,重启服务
go env -w GOOS=linux
cd $projectDir
go build -ldflags "-s -w" -o appserver appserver.go
scp ./appserver $user@$ip:/var/www/api
ssh $user@$ip chmod +x /var/www/api/appserver
ssh $user@$ip supervisorctl restart appserver
# go env -w GOOS=windows 如果在windows下开发,还需要把 GOOS恢复成windows