mirror of
https://github.com/ehang-io/nps.git
synced 2025-09-02 03:16:53 +00:00
nps some config hot reload
This commit is contained in:
@@ -24,21 +24,40 @@ func InitDaemon(f string, runPath string, pidPath string) {
|
||||
switch os.Args[1] {
|
||||
case "start":
|
||||
start(args, f, pidPath, runPath)
|
||||
os.Exit(0)
|
||||
case "stop":
|
||||
stop(f, args[0], pidPath)
|
||||
os.Exit(0)
|
||||
case "restart":
|
||||
stop(f, args[0], pidPath)
|
||||
start(args, f, pidPath, runPath)
|
||||
os.Exit(0)
|
||||
case "status":
|
||||
if status(f, pidPath) {
|
||||
log.Printf("%s is running", f)
|
||||
} else {
|
||||
log.Printf("%s is not running", f)
|
||||
}
|
||||
os.Exit(0)
|
||||
case "reload":
|
||||
reload(f, pidPath)
|
||||
}
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func reload(f string, pidPath string) {
|
||||
if f == "nps" && !common.IsWindows() && !status(f, pidPath) {
|
||||
log.Println("reload fail")
|
||||
return
|
||||
}
|
||||
var c *exec.Cmd
|
||||
var err error
|
||||
b, err := ioutil.ReadFile(filepath.Join(pidPath, f+".pid"))
|
||||
if err == nil {
|
||||
c = exec.Command("/bin/bash", "-c", `kill -30 `+string(b))
|
||||
} else {
|
||||
log.Fatalln("reload error,pid file does not exist")
|
||||
}
|
||||
if c.Run() == nil {
|
||||
log.Println("reload success")
|
||||
} else {
|
||||
log.Println("reload fail")
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user