Skip to content
This repository has been archived by the owner on Feb 4, 2022. It is now read-only.

PID File is supposed to be deleted on heiko stop. #1

Closed
psiayn opened this issue May 21, 2021 · 2 comments · Fixed by #4
Closed

PID File is supposed to be deleted on heiko stop. #1

psiayn opened this issue May 21, 2021 · 2 comments · Fixed by #4

Comments

@psiayn
Copy link
Owner

psiayn commented May 21, 2021

PID File generated in daemon mode is supposed to be deleted via the context.Release() call. As of right now, any form of interrupt ( SIGTERM / SIGINT ) doesn't seem to change it's behaviour.

Also go-daemon seems to be pretty old, could that be the issue?

@MadhavJivrajani
Copy link

imo the reason that the PID files don't get deleted is that in the code, context.Release() is defered, and defer isn't run if signals like SIGTERM and SIGINT are sent to the process because the process itself is basically stopped. You can try running this snippet and sending different signals to it.

This behaviour can be changed by adding some form of signal handling, like here. This works pretty well.

@Samyak2
Copy link
Collaborator

Samyak2 commented May 24, 2021

imo the reason that the PID files don't get deleted is that in the code, context.Release() is defered, and defer isn't run if signals like SIGTERM and SIGINT are sent to the process because the process itself is basically stopped. You can try running this snippet and sending different signals to it.

Ah that explains it. The example helped me see it in action, the defer statement isn't run on any of SIGINT, SIGHUP or SIGTERM. Thanks for that!

This behaviour can be changed by adding some form of signal handling, like here. This works pretty well.

We had explored this before, but we weren't sure of how to pass the flags from cobra/viper. go-daemon seems to use the flag package along with their own interface for specific flags. Do you know of a way to convert viper flags to the flags required by go-daemon?

My initial idea was to pass a pointer to daemon.BoolFlag using the value from viper, but that seems like a hack.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants