python 版经常出现一些错误,比如 supervisor.sock 文件找不到的错误。懒得去整,试试二进制的 supervisord ,用 Go 语言编写。
编译
在Go 环境下编译,下载源码
https://github.com/ochinchina/supervisord
我在 Mac 下做交叉编译失败
1
2
3
4
loadinternal: cannot find runtime/cgo
/usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: library not found for -lcrt0.o
clang: error: linker command failed with exit code 1 (use -v to see invocation)
只能到虚拟机里编译:
1
2
go generate
GOOS=linux go build -tags release -a -ldflags "-linkmode external -extldflags -static" -o supervisord
我这里会有一些提示
1
2
3
4
5
6
7
8
9
10
11
12
/tmp/go-link-125451663/000021.o: In function `mygetgrouplist':
/_/os/user/getgrouplist_unix.go:15: warning: Using 'getgrouplist' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-125451663/000020.o: In function `mygetgrgid_r':
/_/os/user/cgo_lookup_unix.go:37: warning: Using 'getgrgid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-125451663/000020.o: In function `mygetgrnam_r':
/_/os/user/cgo_lookup_unix.go:42: warning: Using 'getgrnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-125451663/000020.o: In function `mygetpwnam_r':
/_/os/user/cgo_lookup_unix.go:32: warning: Using 'getpwnam_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-125451663/000020.o: In function `mygetpwuid_r':
/_/os/user/cgo_lookup_unix.go:27: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/tmp/go-link-125451663/000004.o: In function `_cgo_2ac87069779a_C2func_getaddrinfo':
/tmp/go-build/cgo-gcc-prolog:58: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
还好只是警告信息,否则我又会马上放弃。
得到了一个编译好的文件 supervisord
,放到服务环境的某个bin目录下,如 /usr/local/bin
部署
配置文件,我放在 /etc/supervisord.conf
写入基本的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
[inet_http_server]
port=127.0.0.1:9001
[supervisord]
logfile=/logs/supervisord.log
logfileMaxbytes=10MB
logfileBackups=10
loglevel=info
pidfile=/logs/supervisord.pid
identifier=supervisor
[include]
files=/root/srvconf/*.conf
如果忽略log文件就填上 /dev/null
不同的应用统一放在 /root/srvconf
下,用 conf
后缀名
下面是一份简单的应用配置,与python版几乎相同,没挑剔的需求可直接复制过来。
1
2
3
4
5
6
7
8
9
10
11
[program:abc]
command = /srv/www/abc/abc -addr 0.0.0.0:8080
process_name = abc
stopwaitsecs = 11
directory = /srv/www/abc
stdout_logfile = /logs/abc_out.log
stderr_logfile = /logs/abc_err.log
redirect_stderr=true
autostart=true
autorestart=true
stopwaitsecs = 11
管理
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ supervisord ctl status
$ supervisord ctl status program-1 program-2...
$ supervisord ctl status group:*
$ supervisord ctl stop program-1 program-2...
$ supervisord ctl stop group:*
$ supervisord ctl stop all
$ supervisord ctl start program-1 program-2...
$ supervisord ctl start group:*
$ supervisord ctl start all
$ supervisord ctl shutdown
$ supervisord ctl reload
$ supervisord ctl signal <signal_name> <process_name> <process_name> ...
$ supervisord ctl signal all
$ supervisord ctl pid <process_name>
$ supervisord ctl fg <process_name>
注意: 要在 supervisord.conf
文件里设置 inet_http_server
信息才能使用 ctl
子命令控制。
开机自启
推荐一个简单的工具 https://github.com/txthinking/jinbe
一行命令搞定
1
jinbe supervisord -c /etc/supervisord.conf -d
本文网址: https://pylist.com/topic/237.html 转摘请注明来源