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": { 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/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 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 <