Write PID file before signal the parent process.
Write PID file before signal the parent process.

This fixes the race with systemd reload.

P - parent, C - child

During live reload scenario,
the following happens:

P -> forks C
P -> blocks  on pipe read
C -> writes to  pipe
C -> writes pid file
P < - reads message from pipe
P <- shuts down

However, there is a race:

P -> forks C
P -> blocks  on pipe read
C -> writes to pipe
P < - reads message from pipe
P <- shuts down
C -> writes pid file

In this case parent process exited
before child process writes new pid file
what makes systemd think that main process
is down and stop both processes.

This fix changes the sequence to:

P -> forks C
P -> blocks on pipe read
C -> writes pid file
C -> writes to pipe
P < - reads message from pipe
P <- shuts down

to make sure the race can't happen any more.

gravitational/teleport,gravitational/teleport,gravitational/teleport,yacloud-io/teleport,yacloud-io/teleport,gravitational/teleport,yacloud-io/teleport,gravitational/teleport,yacloud-io/teleport,yacloud-io/teleport,yacloud-io/teleport,yacloud-io/teleport,gravitational/teleport