From dd79c5f4f67a366325b2ddb4c060fd49651c6118 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 14 Feb 2023 09:49:05 +0100 Subject: [PATCH] Easy debugging of clickhouse-server in Docker --- docker/server/entrypoint.sh | 14 +++++++++++++- src/Server/TCPHandler.cpp | 4 ---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docker/server/entrypoint.sh b/docker/server/entrypoint.sh index dfd8f2e3e54..538934f07fa 100755 --- a/docker/server/entrypoint.sh +++ b/docker/server/entrypoint.sh @@ -172,7 +172,19 @@ if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then # so the container can't be finished by ctrl+c CLICKHOUSE_WATCHDOG_ENABLE=${CLICKHOUSE_WATCHDOG_ENABLE:-0} export CLICKHOUSE_WATCHDOG_ENABLE - exec /usr/bin/clickhouse su "${USER}:${GROUP}" /usr/bin/clickhouse-server --config-file="$CLICKHOUSE_CONFIG" "$@" + + # An option for easy restarting and replacing clickhouse-server in a container, especially in Kubernetes. + # For example, you can replace the clickhouse-server binary to another and restart it while keeping the container running. + if [[ "${CLICKHOUSE_DOCKER_RESTART_ON_EXIT:-0}" -eq "1" ]]; then + while true; do + # This runs the server as a child process of the shell script: + /usr/bin/clickhouse su "${USER}:${GROUP}" /usr/bin/clickhouse-server --config-file="$CLICKHOUSE_CONFIG" "$@" + echo >&2 'ClickHouse Server exited, and the environment variable CLICKHOUSE_DOCKER_RESTART_ON_EXIT is set to 1. Restarting the server.' + done + else + # This replaces the shell script with the server: + exec /usr/bin/clickhouse su "${USER}:${GROUP}" /usr/bin/clickhouse-server --config-file="$CLICKHOUSE_CONFIG" "$@" + fi fi # Otherwise, we assume the user want to run his own process, for example a `bash` shell to explore this image diff --git a/src/Server/TCPHandler.cpp b/src/Server/TCPHandler.cpp index 69096a110a9..84587af47bb 100644 --- a/src/Server/TCPHandler.cpp +++ b/src/Server/TCPHandler.cpp @@ -1,5 +1,4 @@ #include -#include #include #include #include @@ -24,7 +23,6 @@ #include #include #include -#include #include #include #include @@ -39,9 +37,7 @@ #include #include #include -#include #include -#include #include #include #include