From my understanding when Sonarr is running on a *nix platform restarting from the UI works like so:
- Click restart on the UI.
- SpinService stops sleeping.
- SpinService spawns a new process with /restart flag.
- Spawned process kills the original instance.
This has unintended consequences when using a process manager (upstart, smf, etc).
Because the original processes is killed, the process manager assumes that the process crashed and tries to restart it. It also closes the original stderr and stdout file descriptors. So if the process manager was logging stdout and stderr it will fail to log the newly restarted process.
I’m proposing that for *nix platforms that we replace steps 3 and 4 with the execv system calls. Mono provides it as Mono.Unix.Native.Syscall.execv().
This will cause the new process to replace the current process, which will keep the same PID allowing the process manager to keep tracking the same process, and it will also keep the std* file descriptors open allowing logging to continue.