From 9abd7e543cbcc30ff3c822ef4246b21e611de09e Mon Sep 17 00:00:00 2001 From: Ky Li <982209032@qq.com> Date: Tue, 20 Jul 2021 12:16:51 +0800 Subject: [PATCH 1/3] Update entrypoint.sh We build clickhouse cluster in k8s by clickhouse-operator. clickhouse-server.log is mounted by emptydir on the path `/var/log/clickhouse-server`. It causes the file system error called `Necessary directory '/var/log/clickhouse-server' isn't owned by user with id '101' ` when CLICKHOUSE_DO_NOT_CHOWN is set to true(1). Because emptydir file and dir is owned by root when it started, it has to do the chown cmd. But it will take a long time to run chown cmd when the cluster has much data (in table data dir), the cluster cannot even restart because of `initialDelaySeconds` So chown operation is necessary to check if the file owner and group is owned by user 101. --- docker/server/entrypoint.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docker/server/entrypoint.sh b/docker/server/entrypoint.sh index c93017bd0d3..074a9987eac 100755 --- a/docker/server/entrypoint.sh +++ b/docker/server/entrypoint.sh @@ -72,7 +72,8 @@ do if [ "$DO_CHOWN" = "1" ]; then # ensure proper directories permissions - chown -R "$USER:$GROUP" "$dir" + if [ "$(stat -c %u "$dir")" != "$USER" ] || [ "$(stat -c %g "$dir")" != "$GROUP" ]; then + chown -R "$USER:$GROUP" "$dir" elif ! $gosu test -d "$dir" -a -w "$dir" -a -r "$dir"; then echo "Necessary directory '$dir' isn't accessible by user with id '$USER'" exit 1 From 4df50d349038ce4e7812a4da1e2536a2472d6fc0 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Tue, 20 Jul 2021 15:02:20 +0300 Subject: [PATCH 2/3] Update entrypoint.sh --- docker/server/entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/server/entrypoint.sh b/docker/server/entrypoint.sh index 074a9987eac..8f295bb3144 100755 --- a/docker/server/entrypoint.sh +++ b/docker/server/entrypoint.sh @@ -72,6 +72,7 @@ do if [ "$DO_CHOWN" = "1" ]; then # ensure proper directories permissions + # but skip it for if directory already has proper premissions, cause recursive chown may be slow if [ "$(stat -c %u "$dir")" != "$USER" ] || [ "$(stat -c %g "$dir")" != "$GROUP" ]; then chown -R "$USER:$GROUP" "$dir" elif ! $gosu test -d "$dir" -a -w "$dir" -a -r "$dir"; then From e0c5dc144925a40fb6f1f195fb5d5e806162cf42 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Tue, 20 Jul 2021 16:10:29 +0300 Subject: [PATCH 3/3] Update entrypoint.sh --- docker/server/entrypoint.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/server/entrypoint.sh b/docker/server/entrypoint.sh index 8f295bb3144..f6e1d3c2402 100755 --- a/docker/server/entrypoint.sh +++ b/docker/server/entrypoint.sh @@ -75,6 +75,7 @@ do # but skip it for if directory already has proper premissions, cause recursive chown may be slow if [ "$(stat -c %u "$dir")" != "$USER" ] || [ "$(stat -c %g "$dir")" != "$GROUP" ]; then chown -R "$USER:$GROUP" "$dir" + fi elif ! $gosu test -d "$dir" -a -w "$dir" -a -r "$dir"; then echo "Necessary directory '$dir' isn't accessible by user with id '$USER'" exit 1