Make PID file handling a little more robust.
Make PID file handling a little more robust.

First, we now use AtomicWriter to write out PID files, which should make
it more resilient to sudden failures. In addition, instead of blindly
unwrapping the result of read_pid, which results a Result, we now check
for the presence of an error and log it.

Crucially, if read_pid returns an error, our branching logic returns None,
which causes the corrupt PID file to get deleted and rewritten by the
supervisor. Now, not only are the chances of having a 0 byte PID file
reduced, but even if it does manage to occur, the supervisor will
proceed along as though no PID file ever existed to begin with,
rather than crashing.

Signed-off-by: Josh Black <2831680e59d3b8be5b278b69b4e783c575edf378@gmail.com>

rsertelon/habitat,habitat-sh/habitat,habitat-sh/habitat,rsertelon/habitat,habitat-sh/habitat,habitat-sh/habitat,rsertelon/habitat,habitat-sh/habitat,rsertelon/habitat,rsertelon/habitat,rsertelon/habitat,rsertelon/habitat,habitat-sh/habitat,habitat-sh/habitat,habitat-sh/habitat