Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PID file not removed #95

Open
manuelmeurer opened this issue Oct 12, 2015 · 12 comments
Open

PID file not removed #95

manuelmeurer opened this issue Oct 12, 2015 · 12 comments
Milestone

Comments

@manuelmeurer
Copy link

Shouldn't the PID file be removed when I run kill -TERM?

$ cat /etc/remote_syslog.yml
files:
  - /var/log/nginx/access.log
  - /var/log/nginx/error.log

destination:
  host: logs3.papertrailapp.com
  port: 123
  protocol: tls

$ ls /var/run/remote_syslog.pid
ls: cannot access /var/run/remote_syslog.pid: No such file or directory

$ sudo /usr/local/bin/remote_syslog -c /etc/remote_syslog.yml --pid-file=/var/run/remote_syslog.pid

$ ps aux | grep remote_syslog
root     24305  3.0  0.1  11972  6172 ?        Sl   11:09   0:00 /usr/local/bin/remote_syslog -c /etc/remote_syslog.yml --pid-file=/var/run/remote_syslog.pid
admin    24916  0.0  0.0   9732  2044 pts/0    S+   11:09   0:00 grep --color=auto remote_syslog

$ ls /var/run/remote_syslog.pid
-rw------- 1 root root 6 Oct 12 11:03 /var/run/remote_syslog.pid

$ sudo kill -TERM 24305

$ ps aux | grep remote_syslog
admin    24879  0.0  0.0   9732  2172 pts/0    S+   11:09   0:00 grep --color=auto remote_syslog

$ ls /var/run/remote_syslog.pid
-rw------- 1 root root 6 Oct 12 11:03 /var/run/remote_syslog.pid
@troy
Copy link
Contributor

troy commented Oct 12, 2015

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.

@manuelmeurer
Copy link
Author

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?

@leonsodhi
Copy link

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.

@leonsodhi leonsodhi removed their assignment Oct 13, 2015
@manuelmeurer
Copy link
Author

@leonsodhi
Copy link

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.

@manuelmeurer
Copy link
Author

👍

@QuinnyPig
Copy link

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.

@troy
Copy link
Contributor

troy commented Dec 8, 2015

@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).

@Bowbaq
Copy link
Contributor

Bowbaq commented Dec 16, 2015

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?

@QuinnyPig
Copy link

@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.

@Bowbaq
Copy link
Contributor

Bowbaq commented Jan 12, 2016

@QuinnyPig I'm definitely interested in a good init script, if you don't mind submitting a PR

@huygn
Copy link
Contributor

huygn commented Feb 26, 2016

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.

@johlym johlym added this to the 0.18 Beta 2 milestone Jun 14, 2016
@johlym johlym self-assigned this Jun 14, 2016
@johlym johlym modified the milestones: 0.19, 0.18 Beta 2 Jun 22, 2016
@johlym johlym removed their assignment Aug 16, 2016
@johlym johlym modified the milestone: 0.19 Nov 23, 2016
@snorecone snorecone added this to the 0.20 milestone Nov 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants