]> git.codecow.com Git - nano-pow.git/commitdiff
Write PID file from within server instead of launch script.
authorChris Duncan <chris@zoso.dev>
Mon, 16 Jun 2025 21:52:01 +0000 (14:52 -0700)
committerChris Duncan <chris@zoso.dev>
Mon, 16 Jun 2025 21:52:01 +0000 (14:52 -0700)
src/bin/nano-pow.sh
src/bin/server.ts

index 42c7403fa544de95adb4dd31722c855c2f79e60b..714c730b24ae8441b17f380a71aab9c4b53cb22d 100755 (executable)
@@ -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);
index f31011a04b6e0caa59967c16497aa71e4e42a710..c5c8193373425d53bd7f58bcaa778cbe0ad6cd02 100755 (executable)
@@ -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