-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst_time_vm_setup_script.sh
More file actions
executable file
·82 lines (70 loc) · 2.37 KB
/
Copy pathfirst_time_vm_setup_script.sh
File metadata and controls
executable file
·82 lines (70 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/bash
# First Time VM Setup Script
# This script sets up a fresh Azure VM with Docker and deploys the Service Deployment Manager
# Usage: ./first_time_vm_setup_script.sh [traefik=true]
set -e # Exit on any error
# Parse command line arguments
MANAGE_TRAEFIK=false
for arg in "$@"; do
case $arg in
traefik=true)
MANAGE_TRAEFIK=true
shift
;;
*)
# Unknown option
;;
esac
done
# Configuration - Update these values for your environment
REMOTE_USER="azureuser"
REMOTE_HOST="74.225.129.126" # Change this to your VM's IP or hostname
REMOTE_PATH="/home/azureuser/ws"
SSH_KEY_PATH="~/.ssh/apprunner.pem" # Change this to your SSH private key path
ZIP_FILE="app.zip"
echo "=== First Time VM Setup Script ==="
echo "Target: $REMOTE_USER@$REMOTE_HOST"
echo "Traefik enabled: $MANAGE_TRAEFIK"
echo
# Step 1: Test SSH connectivity
echo "Testing SSH connectivity..."
if ! ssh -i $SSH_KEY_PATH -o ConnectTimeout=10 $REMOTE_USER@$REMOTE_HOST "echo 'SSH connection successful'"; then
echo "ERROR: Cannot connect to $REMOTE_HOST. Please check:"
echo " - VM IP address is correct"
echo " - SSH key path is correct: $SSH_KEY_PATH"
echo " - VM is running and accessible"
exit 1
fi
echo "✅ SSH connectivity confirmed"
echo
# Step 2: Copy and run Docker installation script on remote VM
echo "Copying Docker installation script to remote VM..."
scp -i $SSH_KEY_PATH docker_setup_script.sh $REMOTE_USER@$REMOTE_HOST:/tmp/
echo "Running Docker installation script on remote VM..."
ssh -i $SSH_KEY_PATH $REMOTE_USER@$REMOTE_HOST << 'DOCKER_INSTALL_EOF'
chmod +x /tmp/docker_setup_script.sh
/tmp/docker_setup_script.sh
rm /tmp/docker_setup_script.sh
DOCKER_INSTALL_EOF
if [ $? -ne 0 ]; then
echo "ERROR: Docker installation failed on remote VM"
exit 1
fi
echo "✅ Docker installation completed successfully"
echo
# Step 3: Run deployment script
echo "Running deployment script..."
if [ "$MANAGE_TRAEFIK" = true ]; then
./deploy_to_common_subscription.sh traefik=true
else
./deploy_to_common_subscription.sh
fi
if [ $? -ne 0 ]; then
echo "ERROR: Application deployment failed"
exit 1
fi
echo
echo "🎉 First-time VM setup completed successfully!"
echo
echo "Your VM is now configured with Docker and the Service Deployment Manager is deployed."
echo "For future updates, simply run: ./deploy.sh"