#!/usr/bin/env bash # # Run Systemd Architecture Diagnosis on Remote Server # Executes the diagnostic script on the actual server to get real data # set -e # Script configuration SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_DIR="$(cd "$SCRIPT_DIR/../.." && pwd)" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # Remote connection configuration (using same pattern as other scripts) REMOTE_HOST="${1:-192.168.20.65}" REMOTE_USER="${2:-thrillwiki}" REMOTE_PORT="${3:-22}" SSH_OPTIONS="-o IdentitiesOnly=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=30" echo -e "${BLUE}๐Ÿ” Running ThrillWiki Systemd Service Architecture Diagnosis on Remote Server${NC}" echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" echo "" echo "Target: ${REMOTE_USER}@${REMOTE_HOST}:${REMOTE_PORT}" echo "" # Test SSH connection first echo -e "${YELLOW}๐Ÿ”— Testing SSH connection...${NC}" if ssh $SSH_OPTIONS -p $REMOTE_PORT $REMOTE_USER@$REMOTE_HOST "echo 'SSH connection successful'" 2>/dev/null; then echo -e "${GREEN}โœ… SSH connection verified${NC}" else echo -e "${RED}โŒ SSH connection failed${NC}" echo "Please check:" echo "1. SSH key is set up correctly" echo "2. Remote host is accessible: $REMOTE_HOST" echo "3. Remote user exists: $REMOTE_USER" echo "4. SSH port is correct: $REMOTE_PORT" exit 1 fi echo "" echo -e "${YELLOW}๐Ÿ“ค Uploading diagnostic script to remote server...${NC}" # Upload the diagnostic script to the remote server if scp $SSH_OPTIONS -P $REMOTE_PORT "$SCRIPT_DIR/diagnose-systemd-architecture.sh" "$REMOTE_USER@$REMOTE_HOST:/tmp/diagnose-systemd-architecture.sh" 2>/dev/null; then echo -e "${GREEN}โœ… Diagnostic script uploaded successfully${NC}" else echo -e "${RED}โŒ Failed to upload diagnostic script${NC}" exit 1 fi echo "" echo -e "${YELLOW}๐Ÿ”ง Making diagnostic script executable on remote server...${NC}" # Make the script executable if ssh $SSH_OPTIONS -p $REMOTE_PORT $REMOTE_USER@$REMOTE_HOST "chmod +x /tmp/diagnose-systemd-architecture.sh" 2>/dev/null; then echo -e "${GREEN}โœ… Script made executable${NC}" else echo -e "${RED}โŒ Failed to make script executable${NC}" exit 1 fi echo "" echo -e "${YELLOW}๐Ÿš€ Running diagnostic on remote server...${NC}" echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" echo "" # Run the diagnostic script on the remote server ssh $SSH_OPTIONS -p $REMOTE_PORT $REMOTE_USER@$REMOTE_HOST "/tmp/diagnose-systemd-architecture.sh" || { echo "" echo -e "${RED}โŒ Diagnostic script execution failed${NC}" exit 1 } echo "" echo "โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”" echo -e "${GREEN}โœ… Remote diagnostic completed successfully${NC}" echo "" echo -e "${YELLOW}๐Ÿงน Cleaning up temporary files on remote server...${NC}" # Clean up the uploaded script ssh $SSH_OPTIONS -p $REMOTE_PORT $REMOTE_USER@$REMOTE_HOST "rm -f /tmp/diagnose-systemd-architecture.sh" 2>/dev/null || { echo -e "${YELLOW}โš ๏ธ Warning: Could not clean up temporary file${NC}" } echo -e "${GREEN}โœ… Cleanup completed${NC}" echo "" echo -e "${BLUE}๐Ÿ“‹ Diagnosis complete. Review the output above to identify systemd service issues.${NC}"