proxmox-backup/proxmox-rest-server/src
Fabian Ebner e9b9f33aee rest server: daemon: update PID file before sending MAINPID notification
There is a race upon reload, where it can happen that:
1. systemd forks off /bin/kill -HUP $MAINPID
2. Current instance forks off new one and notifies systemd with the
   new MAINPID.
3. systemd sets new MAINPID.
4. systemd receives SIGCHLD for the kill process (which is the current
   control process for the service) and reads the PID of the old
   instance from the PID file, resetting MAINPID to the PID of the old
   instance.
5. Old instance exits.
6. systemd receives SIGCHLD for the old instance, reads the PID of the
   old instance from the PID file once more. systemd sees that the
   MAINPID matches the child PID and considers the service exited.
7. systemd receivese notification from the new PID and is confused.
   The service won't get active, because the notification wasn't
   handled.

To fix it, update the PID file before sending the MAINPID
notification, similar to what a comment in systemd's
src/core/service.c suggests:
> /* Forking services may occasionally move to a new PID.
>  * As long as they update the PID file before exiting the old
>  * PID, they're fine. */
but for our Type=notify "before sending the notification" rather than
"before exiting", because otherwise, the mix-up in 4. could still
happen (although it might not actually be problematic without the
mix-up in 6., it still seems better to avoid).

Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
2022-05-12 11:53:54 +02:00
..
api_config.rs rest server: rust fmt 2022-04-06 16:55:39 +02:00
command_socket.rs rest server: rust fmt 2022-04-06 16:55:39 +02:00
compression.rs rest server: rust fmt 2022-04-06 16:55:39 +02:00
daemon.rs rest server: daemon: update PID file before sending MAINPID notification 2022-05-12 11:53:54 +02:00
environment.rs rest server: rust fmt 2022-04-06 16:55:39 +02:00
file_logger.rs rest server: rust fmt 2022-04-06 16:55:39 +02:00
formatter.rs proxmox-rest-server: OutputFormatter: add new format_data_streaming method 2022-04-13 08:13:36 +02:00
h2service.rs rest server: rust fmt 2022-04-06 16:55:39 +02:00
lib.rs rest server: rust fmt 2022-04-06 16:55:39 +02:00
rest.rs adapt to the new ApiHandler variants 2022-04-13 08:13:40 +02:00
state.rs rest server: rust fmt 2022-04-06 16:55:39 +02:00
worker_task.rs tree wide: some stylistic clippy fixes 2022-04-11 08:14:28 +02:00