From 852de329077f62ae4f7ca9e5836e56cc81120b49 Mon Sep 17 00:00:00 2001 From: MasterDraco Date: Fri, 7 Mar 2025 10:11:20 +0000 Subject: [PATCH] Fix systemd service startup issues MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated test-and-start.sh to work with systemd services - Added proper node executable path detection - Fixed issue with shebang line in startup script - Updated service module to use absolute paths correctly - Improved robustness of startup script with better error handling 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- modules/service-setup-module-updated.sh | 21 +++++++++++++++++- scripts/test-and-start.sh | 29 ++++++++++++++++++++----- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/modules/service-setup-module-updated.sh b/modules/service-setup-module-updated.sh index 88fe88f..46bc7be 100755 --- a/modules/service-setup-module-updated.sh +++ b/modules/service-setup-module-updated.sh @@ -82,9 +82,28 @@ if [ ! -f "$DATA_DIR/rss-items.json" ]; then echo "[]" > "$DATA_DIR/rss-items.json" fi +# Find the node executable path +NODE_PATH=$(which node 2>/dev/null) +if [ -z "$NODE_PATH" ]; then + # If node is not in PATH, try common locations + for path in /usr/bin/node /usr/local/bin/node /opt/node/bin/node /usr/lib/node; do + if [ -x "$path" ]; then + NODE_PATH="$path" + break + fi + done + + # If we still can't find node, use the default path + if [ -z "$NODE_PATH" ]; then + NODE_PATH="/usr/bin/node" + echo "Warning: Node.js not found in PATH, using default path: $NODE_PATH" + fi +fi + # Start the application cd "$APP_DIR" || { echo "Failed to change to application directory"; exit 1; } -node server.js +echo "Starting node.js application with: $NODE_PATH $APP_DIR/server.js" +exec "$NODE_PATH" "$APP_DIR/server.js" EOF chmod +x "$TEST_START_SCRIPT" diff --git a/scripts/test-and-start.sh b/scripts/test-and-start.sh index e9073bf..d5af1f0 100755 --- a/scripts/test-and-start.sh +++ b/scripts/test-and-start.sh @@ -1,4 +1,4 @@ -#\!/bin/bash +#!/bin/bash # Script to ensure data directory exists and start the application # Define paths @@ -10,7 +10,7 @@ echo "Application directory: $APP_DIR" echo "Data directory: $DATA_DIR" # Ensure the data directory exists -if [ \! -d "$DATA_DIR" ]; then +if [ ! -d "$DATA_DIR" ]; then echo "Creating data directory: $DATA_DIR" mkdir -p "$DATA_DIR" if [ $? -ne 0 ]; then @@ -28,16 +28,35 @@ fi chmod -R 755 "$DATA_DIR" # Check for RSS files -if [ \! -f "$DATA_DIR/rss-feeds.json" ]; then +if [ ! -f "$DATA_DIR/rss-feeds.json" ]; then echo "Creating initial empty rss-feeds.json file" echo "[]" > "$DATA_DIR/rss-feeds.json" fi -if [ \! -f "$DATA_DIR/rss-items.json" ]; then +if [ ! -f "$DATA_DIR/rss-items.json" ]; then echo "Creating initial empty rss-items.json file" echo "[]" > "$DATA_DIR/rss-items.json" fi +# Find the node executable path +NODE_PATH=$(which node 2>/dev/null) +if [ -z "$NODE_PATH" ]; then + # If node is not in PATH, try common locations + for path in /usr/bin/node /usr/local/bin/node /opt/node/bin/node /usr/lib/node; do + if [ -x "$path" ]; then + NODE_PATH="$path" + break + fi + done + + # If we still can't find node, use the default path + if [ -z "$NODE_PATH" ]; then + NODE_PATH="/usr/bin/node" + echo "Warning: Node.js not found in PATH, using default path: $NODE_PATH" + fi +fi + # Start the application cd "$APP_DIR" || { echo "Failed to change to application directory"; exit 1; } -node server.js +echo "Starting node.js application with: $NODE_PATH $APP_DIR/server.js" +exec "$NODE_PATH" "$APP_DIR/server.js" \ No newline at end of file