goreman 服务管理 [神器][golang]

最后更新于:2022-04-02 03:49:22

[TOC] > [github.com](https://github.com/mattn/goreman) ## 安装 `go get github.com/mattn/goreman` ## 概述 控制多个服务的批量启动与单独启动 ## 实例1 同级目录创建 Procfile与main.go
Procfile ``` web1: main.exe -p :9002 goweb: main.exe -p :9003 ```

main.go ``` package main import ( "flag" "fmt" "net/http" "os" ) var addr = flag.String("p", ":8080", "address") func main() { flag.Parse() http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "hello "+os.Getenv("AUTHOR")) }) http.ListenAndServe(*addr, nil) } ```

执行 ``` > goreman.exe start 09:59:17 web1 | Starting web1 on port 5000 09:59:17 goweb | Starting goweb on port 5100 > goreman.exe run status *web1 *goweb > goreman.exe run stop goweb > goreman.exe run status *web1 goweb ``` ## 实例2 可按顺序启动,如下 ``` # 先启动Zookeeper goreman run start zookeeper # 然后启动kafka goreman run start broker # 查看进程状态 goreman run status # 停止broker进程 goreman run stop broker # 重启broker进程 goreman run restart broker ```
';