Add an option for watchdog to restart the child process

This commit is contained in:
Alexey Milovidov 2023-02-12 09:45:24 +01:00
parent 4217e65c5a
commit 4315853d95

View File

@ -994,6 +994,11 @@ void BaseDaemon::setupWatchdog()
if (argv0)
original_process_name = argv0;
bool restart = false;
const char * env_watchdog_restart = getenv("CLICKHOUSE_WATCHDOG_RESTART"); // NOLINT(concurrency-mt-unsafe)
if (env_watchdog_restart && 0 == strcmp(env_watchdog_restart, "1"))
restart = true;
while (true)
{
/// This pipe is used to synchronize notifications to the service manager from the child process
@ -1141,14 +1146,14 @@ void BaseDaemon::setupWatchdog()
logger().fatal("Child process was not exited normally by unknown reason.");
}
/// Automatic restart is not enabled but you can play with it.
#if 1
_exit(WEXITSTATUS(status));
#else
logger().information("Will restart.");
if (argv0)
memcpy(argv0, original_process_name.c_str(), original_process_name.size());
#endif
if (restart)
{
logger().information("Will restart.");
if (argv0)
memcpy(argv0, original_process_name.c_str(), original_process_name.size());
}
else
_exit(WEXITSTATUS(status));
}
}