ClickHouse/packages
Azat Khuzhin 630eddbbbc Disable forwarding signals by watchdog in systemd service
With default KillMode=control-group, systemd will send signals to all
processes in cgroup and this will lead to server will be terminated
forcefully due to double signal.

    2023.09.19 12:47:06.369090 [ 763 ] {} <Information> Application: Received termination signal (Terminated)
    2023.09.19 12:47:06.369141 [ 762 ] {} <Debug> Application: Received termination signal.
    2023.09.19 12:47:06.369215 [ 763 ] {} <Information> Application: Received termination signal (Terminated)
    2023.09.19 12:47:06.369225 [ 763 ] {} <Information> Application: This is the second termination signal. Immediately terminate.
    2023.09.19 12:47:06.400959 [ 761 ] {} <Information> Application: Child process exited normally with code 143.

Someone may naively think that, hey, I can change KillMode to
process/mixed, but this will not work either, because in this case
systemd cannot wait for the $MainPID (and main_pid_alien=true in
systemd's sources), because it is not a child of systemd, and this will
lead to double signal again:

    2023.09.19 16:24:19.694473 [ 3118 ] {} <Information> Application: Received termination signal (Terminated)
    2023.09.19 16:24:19.694894 [ 3118 ] {} <Information> Application: Received termination signal (Terminated)
    2023.09.19 16:24:19.695060 [ 3118 ] {} <Information> Application: This is the second termination signal. Immediately terminate.

And this is because it sends signal firstly on a normal termnation and
then when it cleans up left over processes:

    clickhouse-server.service: Found left-over process 3117 (clickhouse-serv) in control group while starting unit. Ignoring.

And yes, even though it prints "Ignoring" here (I guess it is related to
the fact that it can be ignored if the signal will not be handled)

Here is a proof of double signal by systemd:

    # pgrep clickhouse-serv | xargs strace  -e /kill -fp
    strace: Process 3117 attached with 469 threads
    [pid  3582] --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} ---
    [pid  3580] --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=1, si_uid=0} ---
    [pid  3582] --- SIGCONT {si_signo=SIGCONT, si_code=SI_USER, si_pid=1, si_uid=0} ---
    [pid  3580] --- SIGTERM {si_signo=SIGTERM, si_code=SI_USER, si_pid=1, si_uid=0} ---
                                                                      ^^^
    [pid  3118] tgkill(3117, 3118, SIGTERM) = 0 # and this is a force termination

So yes, there is no other way except for disabling signal forwarding.

*Well, there is another way, but I guess it is will be unwelcome (even
though systemd can be configured in multiple ways right now, and there
is even systemd-oomd instead of clickhouse'es watchdog) - disable
watchdog completelly.*

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
2023-09-19 22:09:38 +02:00
..
.gitignore Migrate to nfpm 2022-03-22 11:09:59 +01:00
build Do not use debconf/confmodule in tgz packages 2023-02-03 12:16:19 +01:00
clickhouse-client.yaml Fix preserving user configs in rpm packages 2022-11-03 16:58:12 +01:00
clickhouse-common-static-dbg.yaml Add deb Source for packages 2022-09-19 20:42:02 +02:00
clickhouse-common-static.yaml Revert "Added tests for ClickHouse apps help and fixed help issues" 2023-04-21 01:54:34 +03:00
clickhouse-keeper-dbg.yaml Add deb Source for packages 2022-09-19 20:42:02 +02:00
clickhouse-keeper.postinstall Add necessary postinst steps for clickhouse-keeper 2023-02-03 12:16:18 +01:00
clickhouse-keeper.service fix: keeper systemd service file include invalid inline comment 2023-03-02 02:15:09 +08:00
clickhouse-keeper.yaml Fix clickhouse-keeper-client symlink 2023-09-18 10:40:15 +02:00
clickhouse-rpm.repo
clickhouse-server.init Adding cron config checking before running sed cmd (#42081) 2022-10-10 13:34:38 +02:00
clickhouse-server.postinstall Remove unused variables from clickhouse-server.postinstall 2023-02-03 12:16:18 +01:00
clickhouse-server.service Disable forwarding signals by watchdog in systemd service 2023-09-19 22:09:38 +02:00
clickhouse-server.yaml Add clickhouse-keeper-client to the packages 2023-07-06 11:47:54 +02:00