proxmox-backup/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
..
acme rust fmt for pbs src 2022-04-14 14:03:46 +02:00
api2 datastore: move update_manifest into BackupDir impl 2022-05-12 09:40:43 +02:00
backup datastore: move update_manifest into BackupDir impl 2022-05-12 09:40:43 +02:00
bin rest server: daemon: update PID file before sending MAINPID notification 2022-05-12 11:53:54 +02:00
config rust fmt for pbs src 2022-04-14 14:03:46 +02:00
server pull group: add error context for cleanup_unreferenced_files 2022-05-12 09:40:43 +02:00
tape make datastore BackupGroup/Dir ctors private 2022-04-20 11:56:23 +02:00
tools drop mut on some http client usages 2022-05-05 10:50:51 +02:00
auth.rs rust fmt for pbs src 2022-04-14 14:03:46 +02:00
auth_helpers.rs rust fmt for pbs src 2022-04-14 14:03:46 +02:00
client_helpers.rs make pbs_tools::cert not depend on pbs-buildcfg 2021-09-29 14:11:26 +02:00
lib.rs move src/shared_rate_limiter.rs to src/tools/shared_rate_limiter.rs 2022-02-14 14:57:56 +01:00
rrd_cache.rs rust fmt for pbs src 2022-04-14 14:03:46 +02:00
traffic_control_cache.rs rust fmt for pbs src 2022-04-14 14:03:46 +02:00