diff options
Diffstat (limited to 'bin/luxcena-neo.sh')
-rwxr-xr-x | bin/luxcena-neo.sh | 32 |
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 $?" |