From e35c0a31382dcb4d740f030dcb2e914a47b7a64a Mon Sep 17 00:00:00 2001 From: thediveo Date: Sun, 6 Apr 2025 22:36:15 +0200 Subject: [PATCH 1/3] refact: use setsid and wait for log file creation before proceeding Signed-off-by: thediveo --- src/local-pkgsite/install.sh | 33 ++++++++++++++++++++++++++++----- test/local-pkgsite/test.sh | 5 +++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/local-pkgsite/install.sh b/src/local-pkgsite/install.sh index 8293823..64b267f 100644 --- a/src/local-pkgsite/install.sh +++ b/src/local-pkgsite/install.sh @@ -154,10 +154,30 @@ INT_PORT=$(comm -23 <(seq $(cat /proc/sys/net/ipv4/ip_local_port_range | tr ' ' <(netstat -ntl | awk '/LISTEN/ {split($4,a,":"); print a[2]}' | sort -u) 2>/dev/null \ | shuf | head -n 1) +wait_for_process_logfile() { + local name=\$1 + local file=\$2 + local now=\$(date +%s) + local end=\$((now + 5)) + while true; do + if [ -s "\${file}" ]; then + echo "...\${name} started" + break + fi + now=\$(date +%s) + if [ "\${now}" -ge "\${end}" ]; then + echo "ERROR: \${name} did not start" + break + fi + sleep 0.25 + done +} + # Start browser-sync in the background to proxy from the local pkgsite on a # random/ephemeral HTTP port that the determined above to the "public" port # where browser want to connect to. -nohup bash -c "\ +BROWSYNC_LOGFILE=/tmp/nohup-local-pkgsite-browser-sync.log +setsid --fork bash -c "\ browser-sync start \ --port ${PORT} \ --proxy localhost:\${INT_PORT} \ @@ -165,14 +185,16 @@ nohup bash -c "\ --reload-debounce ${RELOAD_DEBOUNCE} \ --no-ui \ --no-open \ - " >/tmp/nohup-local-pkgsite-browser-sync.log 2>&1 & + >\${BROWSYNC_LOGFILE} 2>&1" +wait_for_process_logfile "browser-sync" \${BROWSYNC_LOGFILE} # Monitor for any *.go or (heaven forbid) our go.mod to change, then first # terminate the already running local pkgsite and restart it; as before, serve # the local pkgsite on a random/ephemeral HTTP port that the determined above. # Then trigger a reload in connected browsers. Please note that we run nodemon -# and it will then run "browser-sync reload" on demand, as well as ). -nohup bash -c "\ +# and it will then run "browser-sync reload" on demand, as well as pkgsite). +NODEM_LOGFILE=/tmp/nohup-local-pkgsite-nodemon.log +setsid --fork bash -c "\ nodemon \ --signal SIGTERM \ --watch './**/*' \ @@ -182,7 +204,8 @@ nohup bash -c "\ browser-sync --port ${PORT} reload \ && ${PKGSITE_BIN} -http=localhost:\${INT_PORT} . \" \ - &" >/tmp/nohup-local-pkgsite-nodemon.log 2>&1 + >\${NODEM_LOGFILE} 2>&1" +wait_for_process_logfile "nodemon" \${NODEM_LOGFILE} EOF chmod 0755 "${PKGSITE_SERVE_PATH}" diff --git a/test/local-pkgsite/test.sh b/test/local-pkgsite/test.sh index 94edf07..cdc6795 100644 --- a/test/local-pkgsite/test.sh +++ b/test/local-pkgsite/test.sh @@ -15,6 +15,11 @@ cat /tmp/nohup-local-pkgsite-browser-sync.log check "nodemon nohup log exists" bash -c "[ -f /tmp/nohup-local-pkgsite-nodemon.log ]" cat /tmp/nohup-local-pkgsite-nodemon.log +echo +ps -o pid,comm,command --forest -e +check "browser-sync process still exists" bash -c "ps -o pid,command --forest -e | grep -v grep | grep -E '/browser-sync start --port'" +check "nodemon process still exists" bash -c "ps -o pid,command --forest -e | grep -v grep | grep -E '/nodemon --signal SIGTERM'" + CMD=$(cat < Date: Sun, 6 Apr 2025 22:47:29 +0200 Subject: [PATCH 2/3] fix: install missing ps for alma and fedora linux scenarios Signed-off-by: thediveo --- test/local-pkgsite/scenarios.json | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/local-pkgsite/scenarios.json b/test/local-pkgsite/scenarios.json index 6d7e793..21deb4c 100644 --- a/test/local-pkgsite/scenarios.json +++ b/test/local-pkgsite/scenarios.json @@ -11,7 +11,8 @@ "image": "ghcr.io/almalinux/almalinux:9", "features": { "local-pkgsite": {} - } + }, + "postCreateCommand": "yum install -y procps" }, "debian": { "image": "mcr.microsoft.com/devcontainers/base:debian-12", @@ -25,6 +26,7 @@ "image": "fedora", "features": { "local-pkgsite": {} - } + }, + "postCreateCommand": "yum install -y procps" } -} \ No newline at end of file +} \ No newline at end of file From 34b2c99533e5c658a55361eb3916f41e4670fbee Mon Sep 17 00:00:00 2001 From: thediveo Date: Sun, 6 Apr 2025 22:48:14 +0200 Subject: [PATCH 3/3] chore: bump up local-pkgsite feature version Signed-off-by: thediveo --- src/local-pkgsite/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/local-pkgsite/devcontainer-feature.json b/src/local-pkgsite/devcontainer-feature.json index 8691886..97607eb 100644 --- a/src/local-pkgsite/devcontainer-feature.json +++ b/src/local-pkgsite/devcontainer-feature.json @@ -1,7 +1,7 @@ { "name": "Local Go Pkgsite", "id": "local-pkgsite", - "version": "0.1.4", + "version": "0.1.5", "description": "A local Go pkgsite serving the module documentation, with automatic browser refresh.", "options": { "port": {