transmission-rss-manager/scripts/test-and-start.sh
MasterDraco 852de32907 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>
2025-03-07 10:11:20 +00:00

62 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# Script to ensure data directory exists and start the application
# Define paths
APP_DIR="$(dirname "$(dirname "$(readlink -f "$0")")")"
DATA_DIR="$APP_DIR/data"
echo "Starting Transmission RSS Manager..."
echo "Application directory: $APP_DIR"
echo "Data directory: $DATA_DIR"
# Ensure the data directory exists
if [ ! -d "$DATA_DIR" ]; then
echo "Creating data directory: $DATA_DIR"
mkdir -p "$DATA_DIR"
if [ $? -ne 0 ]; then
echo "Failed to create data directory. Trying alternative method..."
# Try alternative method if standard mkdir fails
cd "$APP_DIR" && mkdir -p data
if [ $? -ne 0 ]; then
echo "ERROR: Both methods to create data directory failed. Please check permissions."
exit 1
fi
fi
fi
# Set permissions
chmod -R 755 "$DATA_DIR"
# Check for RSS files
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
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; }
echo "Starting node.js application with: $NODE_PATH $APP_DIR/server.js"
exec "$NODE_PATH" "$APP_DIR/server.js"