Module: check_mk
Branch: master
Commit: 4dfb88f2b1a86c94254481f60f062275939f74b8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4dfb88f2b1a86c…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Jan 28 23:24:44 2019 +0100
Add support for pre-created site directory with tmpfs
In dockerized environments the tmpfs may be managed by docker using the
--tmpfs option). In this case the site directory created as parent of
the tmp directory to mount the tmpfs container initialization. Detect
this situation and don't treat the site as existing in that case.
Change-Id: Iaef722a67e385fd7c42d34e49c17c679a0dc8970
---
docker/docker-entrypoint.sh | 6 +++++-
omd/packages/omd/omdlib/main.py | 18 +++++++++++++++++-
2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh
index d334c62..985a2ee 100755
--- a/docker/docker-entrypoint.sh
+++ b/docker/docker-entrypoint.sh
@@ -28,7 +28,11 @@ if [ ! -z "$MAIL_RELAY_HOST" ]; then
fi
# Create the site in case it does not exist
-if [ ! -d "/opt/omd/sites/$CMK_SITE_ID" ] ; then
+#
+# Check for a file in the directory because the directory itself might have
+# been pre-created by docker when the --tmpfs option is used to create a
+# site tmpfs below tmp.
+if [ ! -d "/opt/omd/sites/$CMK_SITE_ID/etc" ] ; then
echo "### CREATING SITE '$CMK_SITE_ID'"
omd create --no-tmpfs -u 1000 -g 1000 "$CMK_SITE_ID"
omd config "$CMK_SITE_ID" set APACHE_TCP_ADDR 0.0.0.0
diff --git a/omd/packages/omd/omdlib/main.py b/omd/packages/omd/omdlib/main.py
index e5bc7ae..62dde00 100644
--- a/omd/packages/omd/omdlib/main.py
+++ b/omd/packages/omd/omdlib/main.py
@@ -2868,7 +2868,11 @@ def main_rm(site, args, options=None):
def create_site_dir(site):
- os.makedirs(site.dir)
+ try:
+ os.makedirs(site.dir)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
os.chown(site.dir, user_id(site.name), group_id(site.name))
@@ -4217,6 +4221,18 @@ class SiteContext(AbstractSiteContext):
return config
def exists(self):
+ # In dockerized environments the tmpfs may be managed by docker (when
+ # using the --tmpfs option). In this case the site directory is
+ # created as parent of the tmp directory to mount the tmpfs during
+ # container initialization. Detect this situation and don't treat the
+ # site as existing in that case.
+ if is_dockerized():
+ if not os.path.exists(self.dir):
+ return False
+ if os.listdir(self.dir) == ["tmp"]:
+ return False
+ return True
+
return os.path.exists(self.dir)
def is_empty(self):