]> git.codecow.com Git - nano-pow.git/commitdiff
Move server execution into npm script.
authorChris Duncan <chris@zoso.dev>
Wed, 18 Jun 2025 14:29:42 +0000 (07:29 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 18 Jun 2025 14:29:42 +0000 (07:29 -0700)
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.

docs/nano-pow.service
package.json
src/bin/nano-pow.sh

index 743ca422a97c08391d00e6cd47eb736c2920474e..c67d7c7a1dffde45499e5fa55f89c0ba1f24d88f 100644 (file)
@@ -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
index 7a440cdd54139b4dacff26baf5dd8155ae56e8a2..e4ce3ed564a573cb78b3d605efc9d46cf7457844 100644 (file)
@@ -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": {
index 0e9555f22980fd72adb5036452830838d20eb9d6..612e8288604bdc866b76db50ca37264a271a6d3f 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 &
+       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);