aboutsummaryrefslogtreecommitdiff
path: root/bin/luxcena-neo.sh
diff options
context:
space:
mode:
authorjakob.stendahl <jakob.stendahl@infomedia.dk>2022-12-17 21:31:41 +0100
committerJakob Stendahl <jakob.stendahl@outlook.com>2022-12-17 21:31:41 +0100
commit1e588718a855ae2871a8841f6c6e621f49795454 (patch)
tree6599b3959554b307a571a73373114cb2d34a98ef /bin/luxcena-neo.sh
parent6c37c28d7044a813fcde9ef80bf8852529b8305f (diff)
downloadLuxcena-Neo-1e588718a855ae2871a8841f6c6e621f49795454.tar.gz
Luxcena-Neo-1e588718a855ae2871a8841f6c6e621f49795454.zip
Start moving to esm, work on updater
Diffstat (limited to 'bin/luxcena-neo.sh')
-rwxr-xr-xbin/luxcena-neo.sh32
1 files changed, 30 insertions, 2 deletions
diff --git a/bin/luxcena-neo.sh b/bin/luxcena-neo.sh
index c9a6d97..9653d20 100755
--- a/bin/luxcena-neo.sh
+++ b/bin/luxcena-neo.sh
@@ -5,5 +5,33 @@
# the server needs root as well.
#runuser -l pi -c "export NODE_ENV=production; node ~/luxcena-neo-install/src/app.js"
-export NODE_ENV=development
-node /opt/luxcena-neo/app.js >> /var/log/luxcena-neo/service.log 2>&1
+
+set -o pipefail
+
+# Root directory of the installation
+BASEDIR=$(dirname $(dirname "$0"))
+SYSTEMD_SRC_FILE="$BASEDIR/bin/luxcena-neo.service"
+SYSTEMD_DEST_FILE="/etc/systemd/system/luxcena-neo.service"
+
+echo "Verifying that we are running the newest systemd service file"
+SYSTEMD_TMP=$(mktemp)
+sed "s|{{WD}}|$BASEDIR|" "$SYSTEMD_SRC_FILE" > "$SYSTEMD_TMP"
+
+if [[ -f "$SYSTEMD_DEST_FILE" ]] && cmp -s "$SYSTEMD_TMP" "$SYSTEMD_DEST_FILE"; then
+ echo "Newest service file installed."
+ rm "$SYSTEMD_TMP"
+else
+ echo "Serice file not up to date, attempting to update."
+ cp "$SYSTEMD_TMP" "$SYSTEMD_DEST_FILE"
+ rm "$SYSTEMD_TMP"
+ systemctl daemon-reload
+ systemctl enable luxcena-neo
+ systemctl restart luxcena-neo
+ echo "Service file updated, exiting with the hopes that the new file will automatically restart luxcena-neo."
+ exit 0
+fi
+
+echo "Starting luxcena-neo"
+export NODE_ENV=production
+node "$BASEDIR/app.js" >> /var/log/luxcena-neo/service.log 2>&1
+echo "Luxcena neo exited $?"