Enhance installer to detect existing installations and update seamlessly
This commit is contained in:
@@ -33,14 +33,72 @@ function setup_service() {
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Create backup of existing service file if it exists
|
||||
if [ -f "/etc/systemd/system/$SERVICE_NAME.service" ]; then
|
||||
backup_file "/etc/systemd/system/$SERVICE_NAME.service"
|
||||
fi
|
||||
|
||||
# Create systemd service file
|
||||
# Check if service file already exists
|
||||
SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"
|
||||
cat > "$SERVICE_FILE" << EOF
|
||||
if [ -f "$SERVICE_FILE" ] && [ "$IS_UPDATE" = true ]; then
|
||||
log "INFO" "Service file already exists. Preserving existing service configuration."
|
||||
|
||||
# Extract existing JWT_SECRET if present to maintain session consistency
|
||||
EXISTING_JWT_SECRET=$(grep "Environment=JWT_SECRET=" "$SERVICE_FILE" | cut -d'=' -f3)
|
||||
|
||||
# Extract existing PORT if it differs from the configured one
|
||||
EXISTING_PORT=$(grep "Environment=PORT=" "$SERVICE_FILE" | cut -d'=' -f3)
|
||||
if [ -n "$EXISTING_PORT" ] && [ "$EXISTING_PORT" != "$PORT" ]; then
|
||||
log "INFO" "Using existing port configuration: $EXISTING_PORT"
|
||||
PORT=$EXISTING_PORT
|
||||
fi
|
||||
|
||||
# Create backup of existing service file
|
||||
backup_file "$SERVICE_FILE"
|
||||
|
||||
# Update the service file while preserving key settings
|
||||
cat > "$SERVICE_FILE" << EOF
|
||||
[Unit]
|
||||
Description=Transmission RSS Manager
|
||||
After=network.target transmission-daemon.service
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=$USER
|
||||
WorkingDirectory=$INSTALL_DIR
|
||||
ExecStart=/usr/bin/node $INSTALL_DIR/server.js
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
Environment=PORT=$PORT
|
||||
Environment=NODE_ENV=production
|
||||
Environment=DEBUG_ENABLED=false
|
||||
Environment=LOG_FILE=$INSTALL_DIR/logs/transmission-rss-manager.log
|
||||
EOF
|
||||
|
||||
# Preserve the existing JWT_SECRET if available
|
||||
if [ -n "$EXISTING_JWT_SECRET" ]; then
|
||||
echo "Environment=JWT_SECRET=$EXISTING_JWT_SECRET" >> "$SERVICE_FILE"
|
||||
else
|
||||
echo "# Generate a random JWT secret for security" >> "$SERVICE_FILE"
|
||||
echo "Environment=JWT_SECRET=$(openssl rand -hex 32)" >> "$SERVICE_FILE"
|
||||
fi
|
||||
|
||||
# Close the service file definition
|
||||
cat >> "$SERVICE_FILE" << EOF
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
else
|
||||
# For fresh installations, create a new service file
|
||||
log "INFO" "Creating new service file"
|
||||
|
||||
# Create backup of existing service file if it exists
|
||||
if [ -f "$SERVICE_FILE" ]; then
|
||||
backup_file "$SERVICE_FILE"
|
||||
fi
|
||||
|
||||
# Create systemd service file
|
||||
cat > "$SERVICE_FILE" << EOF
|
||||
[Unit]
|
||||
Description=Transmission RSS Manager
|
||||
After=network.target transmission-daemon.service
|
||||
@@ -65,6 +123,7 @@ Environment=JWT_SECRET=$(openssl rand -hex 32)
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Create logs directory
|
||||
mkdir -p "$INSTALL_DIR/logs"
|
||||
@@ -146,6 +205,9 @@ server {
|
||||
}
|
||||
EOF
|
||||
|
||||
log "INFO" "Nginx configured to proxy connections from port 80 to port $PORT"
|
||||
log "INFO" "You can access Transmission RSS Manager at http://your-server-ip/ (port 80) via Nginx"
|
||||
|
||||
# Check if Debian/Ubuntu style (need symlink between available and enabled)
|
||||
if [ "$NGINX_AVAILABLE_DIR" != "$NGINX_ENABLED_DIR" ]; then
|
||||
# Create symbolic link to enable the site (if it doesn't already exist)
|
||||
@@ -167,7 +229,10 @@ EOF
|
||||
# Check for port conflicts
|
||||
if ss -lnt | grep ":$PORT " &> /dev/null; then
|
||||
log "WARN" "Port $PORT is already in use. This may cause conflicts with the service."
|
||||
log "WARN" "Consider changing the port if you encounter issues."
|
||||
log "WARN" "The service will fail to start. Please stop any service using port $PORT and try again."
|
||||
else
|
||||
log "INFO" "You can access the web interface at: http://localhost:$PORT or http://your-server-ip:$PORT"
|
||||
log "INFO" "You may need to configure your firewall to allow access to port $PORT"
|
||||
fi
|
||||
|
||||
# Reload systemd
|
||||
|
||||
Reference in New Issue
Block a user