nsqlookupd使用go-svc包来启动的
github地址:https://github.com/judwhite/go-svc
这个包我看到了类似于守护进程的方式运行程序,下面是一个demo,go-svc也是使用了这个方法
package main import ( "fmt" "os" "os/signal" "syscall" ) func main() { c := make(chan os.Signal, 1) sig := []os.Signal{syscall.SIGINT, syscall.SIGTERM} fmt.Println("start") signal.Notify(c, sig...) fmt.Println("processA") //程序会阻塞在这里, 等待系统信号量 s := <-c fmt.Println("processB") fmt.Println("Got signal:", s) }
运行的结果,如图
如果程序结束输出
processB Got signal: interrupt