essentialkaos / anicorn

Simple utility for starting/restarting Unicorn
https://kaos.sh/anicorn
Apache License 2.0
1 stars 0 forks source link

Validate PID after getting it from pidfile #11

Closed vassilevsky closed 6 years ago

vassilevsky commented 6 years ago

What did you implement:

Closes #10

How did you implement it:

Added a check for PID existence (via /proc fs) after reading it from pidfile.

Now, the absence of pidfile and stale pidfile are both discarded and no pid is returned from the function.

How can we verify it:

I tested this function in isolation with the following script:

echo 'NO FILE'
getPID

echo 'FILE WITH STALE PID'
pid_file=NOPID # actual file with nonexistent pid 999
getPID

echo 'FILE WITH ACTIVE PID'
pid_file=YESPID # actual file with existing pid from ps
getPID

Here are the results:

NO FILE

FILE WITH STALE PID

FILE WITH ACTIVE PID
13333

So, it only returns existing pids now.

TODO's:

Is this ready for review?: Yes Is it a breaking change?: No

vassilevsky commented 6 years ago

Not sure what docs I need to write. LMK if needed.

andyone commented 6 years ago

Thanks for this fix!