Golang守护进程后台运行
package main
import (
"os"
"os/exec"
)
func main() {
args := os.Args
daemon := false
for k, v := range args {
if v == "-d" {
daemon = true
args[k] = ""
}
}
if daemon {
var newArgs []string
if len(args) >1 {
newArgs = args[1:]
}
cmd := exec.Command(args[0], newArgs...)
cmd.Env = os.Environ()
cmd.Start()
return
}
// TODO NewWebServer().ListenAndServe()
}