From f826245953c4615fe2fdf88584a2e58527a2995b Mon Sep 17 00:00:00 2001 From: Lars Windolf Date: Sat, 18 Nov 2023 13:35:38 +0100 Subject: [PATCH] Stop start handling --- backend/package.json | 1 + backend/wurm | 38 +++++++++++++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/backend/package.json b/backend/package.json index 5971722..6489aed 100644 --- a/backend/package.json +++ b/backend/package.json @@ -3,6 +3,7 @@ "main": "server.js", "description": "WurmTerm, a friendly wurm walking along your SSH sessions. Backend service.", "license": "GPL-3.0", + "version": "0.9.0", "repository": { "type": "git", "url": "https://github.com/lwindolf/wurmterm.git" diff --git a/backend/wurm b/backend/wurm index b29ffcb..e8e9e57 100755 --- a/backend/wurm +++ b/backend/wurm @@ -1,8 +1,36 @@ #!/bin/bash # Start nodejs server if needed, always start in background -if ! pgrep -f WurmTermBacken >/dev/null; then - (nohup node server.js >/dev/null 2>&1 &) -else - echo "Already running." -fi +start() { + if ! pgrep -f WurmTermBacken >/dev/null; then + # Locate source (either in /../lib/node_modules or in same dir) + if [ "$(dirname $0)" = "/usr/local/bin" ]; then + cd /usr/local/lib/node_modules/wurmterm-backend + else + cd "$(dirname $0)" + fi + + (nohup node server.js >/dev/null 2>&1 &) + echo "WurmTerm backend started." + else + echo "Already running." + fi +} + +stop() { + if pgrep -f WurmTermBacken >/dev/null; then + echo "Stopping..." + pkill -fe WurmTermBacken + else + echo "Not running." + fi +} + +case "${1-start}" in + start) + start + ;; + stop) + stop + ;; +esac