Golang 版 supervisord 使用记录

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 转摘请注明来源

Suggested Topics

使用Golang selenium WebDriver 自动登录微博

有时候在Golang 程序里需要读取微博的某个页面内容,提示需要登录。最简单的方法是在浏览器里登录后,直接复制Cookie 的内容,然后 http 请求带上Cookie。这样会有人工介入,不是很方便,这里借用 selenium WebDriver 来打开微博登录页面,然后自动填入用户名与密码。...

在 Nginx 和 Golang web 上抢先体验 QUIC

QUIC(Quick UDP Internet Connection)是谷歌推出的一套基于 UDP 的传输协议,它实现了 TCP + HTTPS + HTTP/2 的功能,目的是保证可靠性的同时降低网络延迟。QUIC 是使用 UDP 协议,可以与原来的 TCP 服务不冲突。...

Golang 服务之坑:too many open files

出现这个问题是因为服务的文件句柄超出系统限制。当Go服务程序出现这个问题,首先应该看系统设置,然后再看程序本身。...

golang 计算大文件md5

以前介绍过用python 计算大文件的md5 值,这里将介绍使用 golang 计算大文件md5...

Leave a Comment