From a13066b0ee37db54a96433c4b71e6d1747cb07f3 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 16 Jun 2025 14:52:01 -0700 Subject: [PATCH] Write PID file from within server instead of launch script. --- src/bin/nano-pow.sh | 2 +- src/bin/server.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bin/nano-pow.sh b/src/bin/nano-pow.sh index 42c7403..714c730 100755 --- a/src/bin/nano-pow.sh +++ b/src/bin/nano-pow.sh @@ -10,7 +10,7 @@ NANO_POW_LOGS="$NANO_POW_HOME"/logs; mkdir -p "$NANO_POW_LOGS"; if [ "$1" = '--server' ]; then shift; - node --max-http-header-size=1024 --max-old-space-size=256 "$SCRIPT_DIR"/server.js >> "$NANO_POW_LOGS"/nano-pow-server-$(date -I).log 2>&1 & echo "$!" > "$NANO_POW_HOME"/server.pid; + node --max-http-header-size=1024 --max-old-space-size=256 "$SCRIPT_DIR"/server.js >> "$NANO_POW_LOGS"/nano-pow-server-$(date -I).log 2>&1 & sleep 0.1; if [ "$(ps | grep $(cat $NANO_POW_HOME/server.pid))" = '' ]; then cat $(ls -td "$NANO_POW_LOGS"/* | head -n1); diff --git a/src/bin/server.ts b/src/bin/server.ts index f31011a..c5c8193 100755 --- a/src/bin/server.ts +++ b/src/bin/server.ts @@ -5,7 +5,7 @@ import * as http from 'node:http' import { Serializable } from 'node:child_process' import { hash } from 'node:crypto' -import { readFile } from 'node:fs/promises' +import { readFile, writeFile } from 'node:fs/promises' import { homedir } from 'node:os' import { join } from 'node:path' import { launch } from 'puppeteer' @@ -27,6 +27,7 @@ type NanoPowServerConfig = { } process.title = 'NanoPow Server' +await writeFile(`${homedir()}/.nano-pow/server.pid`, `${process.pid}\n`) const logger = new Logger() const MAX_CONNECTIONS = 1024 -- 2.47.3