Factor out PID file creation and add tests

This commit factors out the PID file creation from bootstrap and adds
tests for error conditions etc. We also can't rely on DELETE_ON_CLOSE
since it might not even write the file depending on the OS and JVM implementation.
This impl uses a shutdown hook to best-effort remove the pid file if it was written.

Closes #8771
I don't like it much when constructors have side-effects. Can we maybe move the API from
```java
new PidFile(path, deleteOnExit, pid);
```
to something like
```
PidFile pidFile = PidFile.create(path, deleteOnExit, pid);
```
to make it clear that there is something happening (since there is a verb)