From: Chris Duncan Date: Wed, 18 Jun 2025 14:29:42 +0000 (-0700) Subject: Move server execution into npm script. X-Git-Tag: v5.1.0~8 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=dbedcb5de995e4e44670b6bd3d6bc160eda97f6e;p=nano-pow.git Move server execution into npm script. This simplifies the bash script. It also allows the example systemd service to use a Type of "simple" and eliminates the PIDFile requirement. The console output is unnecessary when using systemd since the expectation is that logs go to the journal only. --- diff --git a/docs/nano-pow.service b/docs/nano-pow.service index 743ca42..c67d7c7 100644 --- a/docs/nano-pow.service +++ b/docs/nano-pow.service @@ -3,7 +3,7 @@ ## Example systemd service unit file to start the nano-pow server at login. ## Run `systemctl --user edit --force --full nano-pow.service` -## Copy contents below into editor, modifying ExecStart as needed, and save. +## Copy contents below into editor, modify WorkingDirectory as needed, and save. ## Run `systemctl --user enable nano-pow --now` to start it now and at boot. [Unit] @@ -11,15 +11,12 @@ Description=NanoPow Server [Service] # Must point at install path, often in `npm_config_prefix` directory: -ExecStart=%h/.local/bin/nano-pow --server +WorkingDirectory=%h/.local/lib/node_modules/nano-pow -Type=forking -WorkingDirectory=%h +Type=simple +ExecStart=/usr/bin/npm start EnvironmentFile=-%h/.nano-pow/config PassEnvironment=NANO_POW_DEBUG NANO_POW_EFFORT NANO_POW_PORT -PIDFile=%h/.nano-pow/server.pid -StandardOutput=journal+console -StandardError=journal+console [Install] WantedBy=default.target diff --git a/package.json b/package.json index 7a440cd..e4ce3ed 100644 --- a/package.json +++ b/package.json @@ -55,7 +55,7 @@ "gpugenerate": "cd src/lib/generate/webgpu/shaders && rm -rf build && tsc && node build/generate.js > build/compute.wgsl && cp tsconfig.json* build", "prepare": "npm run build", "score": "npm run build && ./dist/bin/nano-pow.sh --effort 4 --benchmark 100 --score 100", - "start": "./dist/bin/nano-pow.sh --server", + "start": "node --max-http-header-size=1024 --max-old-space-size=256 ./dist/bin/server.js", "test": "npm run build && ./test/script.sh" }, "devDependencies": { diff --git a/src/bin/nano-pow.sh b/src/bin/nano-pow.sh index 0e9555f..612e828 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 & + npm start >> "$NANO_POW_LOGS"/nano-pow-server-$(date -I).log 2>&1 & sleep 1; if [ "$(ps | grep $(cat $NANO_POW_HOME/server.pid))" = '' ]; then cat $(ls -td "$NANO_POW_LOGS"/* | head -n1);