endless
endless copied to clipboard
fork() should use cmd.Run() rather than cmd.Start()
func (c *Cmd) Run() error { if err := c.Start(); err != nil { return err } return c.Wait() // if execute the command fails,return error } I use endless in my project. In a production environment, we need to modify the configuration file frequently, and then restart the program for the new configuration to take effect. But the configuration file often has syntax errors, making the program unable to restart successfully. We need to modify the configuration again and restart again, but endless output "Fork err: Another process already forked. Ignoring this one."
In my scenario, I use'./app -s restart' to restart server, when app get the arg of '-s restart', it's will do
- check config file(include format)
- get PIDFile in cofig file
- When the process pointed to by pid is running, send
SIGHUP
to it
- so I think u should check config file before send restart signal
- about fork() use the cmd.Start(), I use it to run a deamon process, so the cmd.Run() con't return, until daemon process exit
This is just my suggestion, I hope it will be useful to you