Fix systemd service startup issues

- 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 <noreply@anthropic.com>
This commit is contained in:
MasterDraco 2025-03-07 10:11:20 +00:00
parent 35420335d7
commit 852de32907
2 changed files with 44 additions and 6 deletions

View File

@ -82,9 +82,28 @@ if [ ! -f "$DATA_DIR/rss-items.json" ]; then
echo "[]" > "$DATA_DIR/rss-items.json" echo "[]" > "$DATA_DIR/rss-items.json"
fi 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 # Start the application
cd "$APP_DIR" || { echo "Failed to change to application directory"; exit 1; } 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 EOF
chmod +x "$TEST_START_SCRIPT" chmod +x "$TEST_START_SCRIPT"

View File

@ -1,4 +1,4 @@
#\!/bin/bash #!/bin/bash
# Script to ensure data directory exists and start the application # Script to ensure data directory exists and start the application
# Define paths # Define paths
@ -10,7 +10,7 @@ echo "Application directory: $APP_DIR"
echo "Data directory: $DATA_DIR" echo "Data directory: $DATA_DIR"
# Ensure the data directory exists # Ensure the data directory exists
if [ \! -d "$DATA_DIR" ]; then if [ ! -d "$DATA_DIR" ]; then
echo "Creating data directory: $DATA_DIR" echo "Creating data directory: $DATA_DIR"
mkdir -p "$DATA_DIR" mkdir -p "$DATA_DIR"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
@ -28,16 +28,35 @@ fi
chmod -R 755 "$DATA_DIR" chmod -R 755 "$DATA_DIR"
# Check for RSS files # 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 "Creating initial empty rss-feeds.json file"
echo "[]" > "$DATA_DIR/rss-feeds.json" echo "[]" > "$DATA_DIR/rss-feeds.json"
fi 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 "Creating initial empty rss-items.json file"
echo "[]" > "$DATA_DIR/rss-items.json" echo "[]" > "$DATA_DIR/rss-items.json"
fi 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 # Start the application
cd "$APP_DIR" || { echo "Failed to change to application directory"; exit 1; } 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"