[TOC] > [参考](https://github.com/ochinchina/supervisord) ## 概述 go版本的 supervisord,自带 gui 支持window 与 linux ,window 需要自行编译 **具体用法参考 python的`supervisord`** [supervisor](supervisordgo%E7%89%88%E5%B8%A6gui/supervisor%E5%B8%B8%E8%A7%84%E7%94%A8%E6%B3%95.md) ### 支持 python `[supervisord] `中的 ``` logfile logfile_maxbytes logfile_backups loglevel pidfile minfds minprocs identifier ``` ### 支持 `program:x` 的配置 ``` program command process name numprocs numprocs_start autostart startsecs startretries autorestart exitcodes stopsignal stopwaitsecs stdout_logfile stdout_logfile_maxbytes stdout_logfile_backups redirect_stderr stderr_logfile stderr_logfile_maxbytes stderr_logfile_backups environment priority user directory stopasgroup killasgroup restartpause ``` ## bug 修复 ## 命令行操作 ``` 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:program-1 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> ``` ## 配置 ### 服务依赖 ``` [program:A] depends_on = B, C [program:B] ... [program:C] ... ``` ### 服务所属 user/group ``` [program:xxx] user = user_name ... ``` or ``` [program:xxx] user = user_name:group_name ... ``` ## 实例 ### hello <details> <summary>main.go</summary> ``` package main import ( "net/http" "os" ) var ( port string ) func init() { port = os.Getenv("port") if port=="" { port=":5051" } } func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("hello world")) }) err := http.ListenAndServe(port, nil) if err != nil { panic(err) } } ``` </details> <br/> 编译为linux 版本 <details> <summary>supervisor.conf</summary> ``` [program:web] environment=port=":5052" command = /root/main autorestart=true ; 程序崩溃时自动重启 ;redirect_stderr=true ; 重定向输出的日志 ;stdout_logfile = /var/log/supervisor/tornado_server.log ;loglevel=info # command = ./main 可用相对路径 [inet_http_server] port=:9001 ``` </details> <br/> 启动 ``` ./supervisord -c supervisor.conf ``` 访问: http://ip:9001 可查看gui