Open manuelmeurer opened 9 years ago
That seems logical to me. I don't think remote_syslog2 is currently using godaemon to handle any signals, but the capability seems to exist.
I don't know what the best practice is, but I'm using the init script, maybe we could add rm $pid_file
in the stop()
function?
I'm seeing the same behaviour here on a Linux box.
We could add something into each init script, but that means it would still be broken for anyone that wants to roll their own. It seems like the binary should take care of this.
If anyone digs up anything on the best way to do this in Golang, I'd love to take a look. If I get a chance, I'll see what I can find.
Here are some examples I found: https://github.com/mindreframer/golang-stuff/blob/master/github.com/youtube/vitess/third_party/go/launchpad.net/gozk/zookeeper/runserver.go#L155 https://github.com/docker/docker/blob/master/pkg/pidfile/pidfile.go https://github.com/etix/mirrorbits/blob/master/process.go#L130 Does that help? Sorry, I'm not experienced in Go, otherwise I would implement it myself in a PR...
Thanks, @manuelmeurer, and that Docker implementation is particularly interesting. Looks like they're handling signals here, which relies on their signal lib and the removal function you linked to.
The mirrorbits implementation was also quite a good read. Seems less sophisticated but might be enough for our needs.
If/when I get a chance, I'll throw something together based on these examples.
:+1:
Just tripped over this almost two months later. Awesome.
service remote_syslog stop; service remote_syslog start
results in the process not running but reporting back that it is to the service handler.
@QuinnyPig: totally agree and on our radar to change. If you happen to get to it first, pull requests are gratefully accepted (and this one would be reviewed and merged quickly).
Just ran into this (@QuinnyPig fancy seeing you here :P). I'm happy to take a stab at fixing, the question is how to go about it.
I'm pretty sure the root cause is in https://github.com/leonsodhi/lockfile/blob/master/lockfile.go#L56-L59. On line 46 in https://golang.org/src/os/exec_unix.go#L39, errFinished
is returned when the process is already dead (which is the case after stop
). The type conversion fails, and the error from the os
package is returned, when really we'd want to return ErrInvalidPid
, which would then trigger the cleanup of the PID file.
With that said, it's fairly straightforward to implement signal handling in the daemon & remove it ourselves. Any preference?
@Bowbaq Small world! I've replaced the init script with something saner (but still an init script); it works really well. Should I submit a pull request, or is this something we're going to stuff into the daemon?
Either way, this init script needs fixing.
@QuinnyPig I'm definitely interested in a good init script, if you don't mind submitting a PR
rm -f $pid_file
if the service stopped successfully, however, imo removing the pid file when it start cover more cases and make sure it have a clean start.
Shouldn't the PID file be removed when I run
kill -TERM
?