aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-11-21 21:26:01 +0100
committerWojtek Kosior <koszko@koszko.org>2022-11-21 21:48:21 +0100
commitd9e2c6ca4b22257820028df3adcd9bd290c12e24 (patch)
treeed7be4d4a941d4709ef0c279033576f44957b61f
parent76090eb283086b06aa57375be965a9e03686a08e (diff)
downloadkoszko-org-server-d9e2c6ca4b22257820028df3adcd9bd290c12e24.tar.gz
koszko-org-server-d9e2c6ca4b22257820028df3adcd9bd290c12e24.zip
make container write logs to a directory shared with host
-rw-r--r--.gitignore2
-rw-r--r--Makefile12
-rwxr-xr-xguix-container.sh9
-rwxr-xr-xrun-with-fake-mounts.sh7
4 files changed, 21 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index dd17935..fcd3471 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,7 +5,7 @@
# Available under the terms of Creative Commons Zero v1.0 Universal.
container-runner
-log/
+log
pidfile
hosts
*.touchfile
diff --git a/Makefile b/Makefile
index 2b179a2..9c02eec 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,8 @@ GUIX_SHELL = $(GUIX_TM) shell
KOSZKO_ORG_WEBSITE_INFO = \
subrepos/koszko-org-website/src/koszko_org_website.egg-info/PKG-INFO
+LOGDIR = "/tmp/$$(pwd | sed 's|/|!|g')!log"
+
all: | container-runner.touchfile log
$(KOSZKO_ORG_WEBSITE_INFO):
@@ -43,18 +45,18 @@ hosts: hosts-extra /etc/hosts
cat $^ > $@
log:
- mkdir -p log
+ ln -sf $(LOGDIR) $@
start-container: guix-container.sh container-runner.touchfile | log
- unshare --mount ./run-with-fake-mounts.sh \
- ./$< start -e ./container-runner -p ./pidfile -l ./log
+ unshare --mount ./run-with-fake-mounts.sh $(LOGDIR) \
+ ./$< start -e ./container-runner -p ./pidfile -l $(LOGDIR)
stop-container: guix-container.sh
./$< stop -e ./container-runner -p ./pidfile
restart-container: guix-container.sh container-runner.touchfile | log
- unshare --mount ./run-with-fake-mounts.sh \
- ./$< restart -e ./container-runner -p ./pidfile -l ./log
+ unshare --mount ./run-with-fake-mounts.sh $(LOGDIR) \
+ ./$< restart -e ./container-runner -p ./pidfile -l $(LOGDIR)
enter-container: pidfile
nsenter -a -t "$$(cat pidfile)" \
diff --git a/guix-container.sh b/guix-container.sh
index 2430d8a..9218a54 100755
--- a/guix-container.sh
+++ b/guix-container.sh
@@ -81,14 +81,17 @@ onexit() {
start() {
KOSZKO_SIDELOAD_REAL=/var/www/koszko.org/html
KOSZKO_SIDELOAD_INSIDE=/srv/http/koszko.org
+ LOG_REAL="$LOG_DIR"/container
+ LOG_INSIDE=/var/log
HTTP_DIR_SHARE_OPT=--share="$KOSZKO_SIDELOAD_REAL"="$KOSZKO_SIDELOAD_INSIDE"
+ LOG_DIR_SHARE_OPT=--share="$LOG_REAL"="$LOG_INSIDE"
mkdir -p "$(dirname "$LOG_DIR")"
mkdir --mode=700 -p "$LOG_DIR"
+ mkdir --mode=700 -p "$LOG_DIR"/container
- "$EXECUTABLE" $HTTP_DIR_SHARE_OPT \
- >> "$LOG_DIR"/stdout.log \
- 2>> "$LOG_DIR"/stderr.log &
+ "$EXECUTABLE" "$HTTP_DIR_SHARE_OPT" "$LOG_DIR_SHARE_OPT" \
+ >> "$LOG_DIR"/stdout.log 2>> "$LOG_DIR"/stderr.log &
GUILE_PID=$!
WAIT_TIME=0
diff --git a/run-with-fake-mounts.sh b/run-with-fake-mounts.sh
index 75675ed..57b3078 100755
--- a/run-with-fake-mounts.sh
+++ b/run-with-fake-mounts.sh
@@ -8,10 +8,17 @@
set -e
+LOGDIR="$1"
+
+shift
+
mkdir -p /var/www
mount -t tmpfs dummy /var/www
mkdir -p /var/www/koszko.org/html
+rm -rf "$LOGDIR"
+mkdir -p "$LOGDIR"
+
printf ':D\n' > /var/www/koszko.org/html/index.html
"$@"