GO overseer 平滑重启

涉及知识点:

overseer: go 平滑重启库   
github.com/jpillora/overseer

gspt: go 设置进程名字, 方便区分不同进程 github.com/erikdubbelboer/gspt

kill [参数] [进程ID]
用于向进程发送信号
例如:kill -HUP 520
转载:https://blog.csdn.net/junyucsdn/article/details/50519248

overseer代码:

package main

import (
    "fmt"
    "github.com/erikdubbelboer/gspt"
    "github.com/jpillora/overseer"
    "log"
    "net/http"
)
// 设置进程名字 用户平滑重启(通过向进程发送信号,即可完成重启)
func mainInit(){
    procTitle := "haiyoushui"
    gspt.SetProcTitle(procTitle)
}

func main() {
    mainInit()
  
    overseer.Run(overseer.Config{
        Program: prog,
        Address: ":3000",
    })
}

//prog(state) runs in a child process
func prog(state overseer.State) {
    log.Printf("app (%s) listening...", state.ID)
    http.Handle("/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "app (%s) says hello\n", state.ID)
    }))
    http.Serve(state.Listener, nil)
}

 

posted @ 2021-02-19 14:56  Black_Climber  阅读(844)  评论(0编辑  收藏  举报