|
| 1 | +# π Deploy Secondary Server Setup Guide |
| 2 | + |
| 3 | +This guide helps you set up the AI Platform sync on the secondary server (192.168.0.1). |
| 4 | + |
| 5 | +## π **What You Need To Do** |
| 6 | + |
| 7 | +**On the secondary server (192.168.0.1), run these commands:** |
| 8 | + |
| 9 | +### Option 1: Copy Script Content |
| 10 | +```bash |
| 11 | +# Create the setup script on secondary server |
| 12 | +cat > ~/setup-secondary-sync-complete.sh << 'SCRIPT_EOF' |
| 13 | +#!/bin/bash |
| 14 | +# Complete Secondary Server Setup for AI Platform Sync |
| 15 | +# Run this script on the secondary server (192.168.0.1) |
| 16 | +
|
| 17 | +set -e |
| 18 | +
|
| 19 | +# Colors |
| 20 | +GREEN='\033[0;32m' |
| 21 | +BLUE='\033[0;34m' |
| 22 | +YELLOW='\033[1;33m' |
| 23 | +NC='\033[0m' |
| 24 | +
|
| 25 | +echo -e "${BLUE}π§ Setting up AI Platform Sync on Secondary Server${NC}" |
| 26 | +echo "==================================================" |
| 27 | +
|
| 28 | +# SSH public key from primary server |
| 29 | +PUBLIC_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDsx9ByhVFwBOXsvAo+ioYp21wuPeurcZbZYpRRs2rst5zocIa6aROHh9K9sGaqLEd1o02NdFaBs+PpNClD/Ih9cW/XN7FKYIsrW/ogbV/C7BTG25BOgR291sqwNvmMgLgArbY7TP4o7lU/roW/9pRrxxV5T6v4mGme8hkeB7sO16/jZhJOBTjFvm+ixBsh9TrGrxQTDGm8ROfCKQEv+VHzXCE+iz2Bqz42c7DwzfOfdGHeZgaZwP5tdPbtZp/fl5z/ziXxJ8k6aRJ7/XI6Q6jHVOvudk0svsS6eOoOWKI36qe3cJkR3u+C0i7eBP21gugZeajvouWgDNZY9zujaTiy0P1w9Tr1oqE8z8EyUBRRi5BXy57fiU3tIMMHDurHo1oVvEbHyhH27yabtfRAXmbC8Q03q8KiKzp1aFNYn06bAM72OfqBgP+xiWa/nFet4BZWCXD7nml3W9t4caW00QzgI/ChawuWogEcwruO2jebr6G0DHoFV5phV8EEyJHxkZEV43GJfOObsVUOHaUyFspf1CFnHXuiNSZ3B8adl5M38F+fXEE5O3AaWfA45zzWYalqGR+ylTtPBBsCL016b9+YJK4zdcGNNM1KQpCWcxhAm2fMSIvr0S661iWtxNm9IzCwvPbwuW1PIPnCT+uiwzFdrvoOdK6KUi92CsM5fvuSmw== [email protected]" |
| 30 | +
|
| 31 | +echo -e "${YELLOW}Step 1: Creating service user 'ai-platform-sync'${NC}" |
| 32 | +
|
| 33 | +# Create service user if it doesn't exist |
| 34 | +if ! id ai-platform-sync &>/dev/null; then |
| 35 | + sudo useradd -m -s /bin/bash -c "AI Platform Sync Service" ai-platform-sync |
| 36 | + echo "β
Service user created" |
| 37 | +else |
| 38 | + echo "β
Service user already exists" |
| 39 | +fi |
| 40 | +
|
| 41 | +echo -e "${YELLOW}Step 2: Setting up SSH directory and keys${NC}" |
| 42 | +
|
| 43 | +# Set up SSH directory |
| 44 | +sudo mkdir -p /home/ai-platform-sync/.ssh |
| 45 | +sudo chmod 700 /home/ai-platform-sync/.ssh |
| 46 | +
|
| 47 | +# Add the public key |
| 48 | +echo "$PUBLIC_KEY" | sudo tee /home/ai-platform-sync/.ssh/authorized_keys > /dev/null |
| 49 | +
|
| 50 | +# Set correct permissions |
| 51 | +sudo chmod 600 /home/ai-platform-sync/.ssh/authorized_keys |
| 52 | +sudo chown -R ai-platform-sync:ai-platform-sync /home/ai-platform-sync/.ssh |
| 53 | +
|
| 54 | +echo "β
SSH keys configured" |
| 55 | +
|
| 56 | +echo -e "${YELLOW}Step 3: Creating staging directory${NC}" |
| 57 | +
|
| 58 | +# Create staging directory |
| 59 | +sudo -u ai-platform-sync mkdir -p /home/ai-platform-sync/sync-staging/{webapp/public,webapi/wwwroot} |
| 60 | +echo "β
Staging directory created" |
| 61 | +
|
| 62 | +echo -e "${YELLOW}Step 4: Creating apply-sync script${NC}" |
| 63 | +
|
| 64 | +# Create apply-sync script |
| 65 | +sudo -u ai-platform-sync tee /home/ai-platform-sync/apply-sync.sh > /dev/null << 'EOF' |
| 66 | +#!/bin/bash |
| 67 | +# Apply Sync Script - Secondary Server |
| 68 | +set -e |
| 69 | +
|
| 70 | +LOG_FILE="$HOME/apply-sync.log" |
| 71 | +STAGING_DIR="$HOME/sync-staging" |
| 72 | +PLATFORM_ROOT="/home/keith-ransom/chat-copilot" |
| 73 | +
|
| 74 | +log_msg() { |
| 75 | + echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" | tee -a "$LOG_FILE" |
| 76 | +} |
| 77 | +
|
| 78 | +log_msg "π Applying sync from primary server..." |
| 79 | +
|
| 80 | +declare -a FILES=( |
| 81 | + "webapp/public/applications.html" |
| 82 | + "webapp/public/control-panel.html" |
| 83 | + "webapi/wwwroot/applications.html" |
| 84 | + "webapi/wwwroot/control-panel.html" |
| 85 | +) |
| 86 | +
|
| 87 | +for file in "${FILES[@]}"; do |
| 88 | + if [[ -f "$STAGING_DIR/$file" ]]; then |
| 89 | + log_msg " π Applying $file" |
| 90 | + target_dir="$(dirname "$PLATFORM_ROOT/$file")" |
| 91 | + mkdir -p "$target_dir" 2>/dev/null || sudo mkdir -p "$target_dir" |
| 92 | + |
| 93 | + if cp "$STAGING_DIR/$file" "$PLATFORM_ROOT/$file" 2>/dev/null; then |
| 94 | + log_msg " β
Applied successfully" |
| 95 | + else |
| 96 | + sudo cp "$STAGING_DIR/$file" "$PLATFORM_ROOT/$file" |
| 97 | + sudo chown keith-ransom:keith-ransom "$PLATFORM_ROOT/$file" |
| 98 | + log_msg " β
Applied with elevated privileges" |
| 99 | + fi |
| 100 | + fi |
| 101 | +done |
| 102 | +
|
| 103 | +# Clean up staging |
| 104 | +rm -rf "$STAGING_DIR" |
| 105 | +mkdir -p "$STAGING_DIR/webapp/public" "$STAGING_DIR/webapi/wwwroot" |
| 106 | +log_msg "β
Sync application completed" |
| 107 | +EOF |
| 108 | +
|
| 109 | +sudo chmod +x /home/ai-platform-sync/apply-sync.sh |
| 110 | +echo "β
Apply-sync script created" |
| 111 | +
|
| 112 | +echo -e "${YELLOW}Step 5: Configuring sudo permissions${NC}" |
| 113 | +
|
| 114 | +# Create sudo permissions |
| 115 | +sudo tee /etc/sudoers.d/ai-platform-sync-secondary > /dev/null << 'EOF' |
| 116 | +ai-platform-sync ALL=(root) NOPASSWD: /bin/cp |
| 117 | +ai-platform-sync ALL=(root) NOPASSWD: /bin/chown |
| 118 | +ai-platform-sync ALL=(root) NOPASSWD: /bin/mkdir |
| 119 | +EOF |
| 120 | +
|
| 121 | +sudo chmod 440 /etc/sudoers.d/ai-platform-sync-secondary |
| 122 | +echo "β
Sudo permissions configured" |
| 123 | +
|
| 124 | +echo -e "${YELLOW}Step 6: Testing configuration${NC}" |
| 125 | +
|
| 126 | +# Test sudo permissions |
| 127 | +if sudo -u ai-platform-sync sudo -l &>/dev/null; then |
| 128 | + echo "β
Sudo permissions working" |
| 129 | +else |
| 130 | + echo "β οΈ Sudo permissions test failed - may need manual verification" |
| 131 | +fi |
| 132 | +
|
| 133 | +echo "" |
| 134 | +echo -e "${GREEN}π Secondary server setup completed!${NC}" |
| 135 | +echo "" |
| 136 | +echo "Next steps:" |
| 137 | +echo "1. Test SSH connection from primary server:" |
| 138 | +echo " sudo -u ai-platform-sync ssh [email protected] 'echo Connection successful'" |
| 139 | +echo "" |
| 140 | +echo "2. Run sync test from primary server:" |
| 141 | +echo " sudo -u ai-platform-sync /home/ai-platform-sync/platform-sync.sh test" |
| 142 | +echo "" |
| 143 | +echo "3. Enable automatic sync timer on primary server:" |
| 144 | +echo " ./install-sync-service.sh" |
| 145 | +echo "" |
| 146 | +echo "Files created on this server:" |
| 147 | +echo "β’ /home/ai-platform-sync/.ssh/authorized_keys" |
| 148 | +echo "β’ /home/ai-platform-sync/apply-sync.sh" |
| 149 | +echo "β’ /home/ai-platform-sync/sync-staging/" |
| 150 | +echo "β’ /etc/sudoers.d/ai-platform-sync-secondary" |
| 151 | +SCRIPT_EOF |
| 152 | + |
| 153 | +# Make it executable and run it |
| 154 | +chmod +x ~/setup-secondary-sync-complete.sh |
| 155 | +./setup-secondary-sync-complete.sh |
| 156 | +``` |
| 157 | + |
| 158 | +### Option 2: Quick Commands (if script doesn't work) |
| 159 | +```bash |
| 160 | +# Create service user |
| 161 | +sudo useradd -m -s /bin/bash -c "AI Platform Sync Service" ai-platform-sync |
| 162 | + |
| 163 | +# Set up SSH |
| 164 | +sudo mkdir -p /home/ai-platform-sync/.ssh |
| 165 | +sudo chmod 700 /home/ai-platform-sync/.ssh |
| 166 | + |
| 167 | +# Add SSH key (all one line) |
| 168 | +echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDsx9ByhVFwBOXsvAo+ioYp21wuPeurcZbZYpRRs2rst5zocIa6aROHh9K9sGaqLEd1o02NdFaBs+PpNClD/Ih9cW/XN7FKYIsrW/ogbV/C7BTG25BOgR291sqwNvmMgLgArbY7TP4o7lU/roW/9pRrxxV5T6v4mGme8hkeB7sO16/jZhJOBTjFvm+ixBsh9TrGrxQTDGm8ROfCKQEv+VHzXCE+iz2Bqz42c7DwzfOfdGHeZgaZwP5tdPbtZp/fl5z/ziXxJ8k6aRJ7/XI6Q6jHVOvudk0svsS6eOoOWKI36qe3cJkR3u+C0i7eBP21gugZeajvouWgDNZY9zujaTiy0P1w9Tr1oqE8z8EyUBRRi5BXy57fiU3tIMMHDurHo1oVvEbHyhH27yabtfRAXmbC8Q03q8KiKzp1aFNYn06bAM72OfqBgP+xiWa/nFet4BZWCXD7nml3W9t4caW00QzgI/ChawuWogEcwruO2jebr6G0DHoFV5phV8EEyJHxkZEV43GJfOObsVUOHaUyFspf1CFnHXuiNSZ3B8adl5M38F+fXEE5O3AaWfA45zzWYalqGR+ylTtPBBsCL016b9+YJK4zdcGNNM1KQpCWcxhAm2fMSIvr0S661iWtxNm9IzCwvPbwuW1PIPnCT+uiwzFdrvoOdK6KUi92CsM5fvuSmw== [email protected]" | sudo tee /home/ai-platform-sync/.ssh/authorized_keys |
| 169 | + |
| 170 | +# Fix permissions |
| 171 | +sudo chmod 600 /home/ai-platform-sync/.ssh/authorized_keys |
| 172 | +sudo chown -R ai-platform-sync:ai-platform-sync /home/ai-platform-sync/.ssh |
| 173 | + |
| 174 | +# Create staging directory |
| 175 | +sudo -u ai-platform-sync mkdir -p /home/ai-platform-sync/sync-staging/{webapp/public,webapi/wwwroot} |
| 176 | + |
| 177 | +# Create sudo permissions |
| 178 | +sudo tee /etc/sudoers.d/ai-platform-sync-secondary << 'EOF' |
| 179 | +ai-platform-sync ALL=(root) NOPASSWD: /bin/cp |
| 180 | +ai-platform-sync ALL=(root) NOPASSWD: /bin/chown |
| 181 | +ai-platform-sync ALL=(root) NOPASSWD: /bin/mkdir |
| 182 | +EOF |
| 183 | + |
| 184 | +sudo chmod 440 /etc/sudoers.d/ai-platform-sync-secondary |
| 185 | +``` |
| 186 | + |
| 187 | +## β
**After Secondary Setup is Complete** |
| 188 | + |
| 189 | +Return to the primary server (192.168.0.5) and run these tests: |
| 190 | + |
| 191 | +```bash |
| 192 | +# Test SSH connection |
| 193 | +sudo -u ai-platform-sync ssh -o StrictHostKeyChecking=no [email protected] "echo 'Connection successful'" |
| 194 | + |
| 195 | +# If SSH works, test the sync |
| 196 | +sudo -u ai-platform-sync /home/ai-platform-sync/platform-sync.sh test |
| 197 | + |
| 198 | +# Install the automatic sync timer |
| 199 | +./install-sync-service.sh |
| 200 | +``` |
| 201 | + |
| 202 | +## π§ **Troubleshooting** |
| 203 | + |
| 204 | +If SSH connection fails: |
| 205 | +```bash |
| 206 | +# Check SSH service on secondary server |
| 207 | +sudo systemctl status ssh |
| 208 | + |
| 209 | +# Check firewall |
| 210 | +sudo ufw status |
| 211 | + |
| 212 | +# Test basic connectivity |
| 213 | +ping 192.168.0.1 |
| 214 | +``` |
| 215 | + |
| 216 | +If permissions fail: |
| 217 | +```bash |
| 218 | +# Check sudoers syntax |
| 219 | +sudo visudo -c |
| 220 | + |
| 221 | +# Test manually |
| 222 | +sudo -u ai-platform-sync sudo -l |
| 223 | +``` |
0 commit comments