-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathec2_setup.sh
More file actions
111 lines (93 loc) · 2.9 KB
/
ec2_setup.sh
File metadata and controls
111 lines (93 loc) · 2.9 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# EC2 Setup Script - Run on fresh Ubuntu 22.04 instance
set -e
echo "Installing dependencies..."
sudo apt update
sudo apt install -y python3.10 python3-pip nodejs npm nginx git
echo "Creating app directory..."
sudo mkdir -p /opt/opsforge
sudo chown -R ubuntu:ubuntu /opt/opsforge
echo "Installing Python packages..."
cd /opt/opsforge
pip3 install fastapi uvicorn boto3 pydantic networkx anthropic python-dotenv
echo "Installing Node packages..."
cd /opt/opsforge/frontend
npm install
npm run build
echo "Configuring nginx..."
sudo tee /etc/nginx/sites-available/opsforge > /dev/null <<'EOF'
server {
listen 80;
server_name _;
# Frontend
location / {
root /opt/opsforge/frontend/dist;
try_files $uri $uri/ /index.html;
}
# Backend API proxy
location /api/ {
proxy_pass http://localhost:8000/api/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
EOF
sudo rm -f /etc/nginx/sites-enabled/default
sudo ln -sf /etc/nginx/sites-available/opsforge /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
echo "Creating systemd service for backend..."
sudo tee /etc/systemd/system/opsforge-backend.service > /dev/null <<'EOF'
[Unit]
Description=OpsForge Backend API
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/opt/opsforge
Environment="PATH=/home/ubuntu/.local/bin:/usr/local/bin:/usr/bin:/bin"
Environment="AWS_REGION=us-east-1"
Environment="STRANDS_MODEL_ID=us.anthropic.claude-sonnet-4-20250514-v1:0"
Environment="ENVIRONMENT=production"
Environment="CORS_ORIGIN=*"
ExecStart=/usr/bin/python3 backend_api.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable opsforge-backend
sudo systemctl start opsforge-backend
echo "Creating systemd service for data generator..."
sudo tee /etc/systemd/system/opsforge-generator.service > /dev/null <<'EOF'
[Unit]
Description=OpsForge Live Data Generator
After=network.target opsforge-backend.service
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/opt/opsforge
Environment="PATH=/home/ubuntu/.local/bin:/usr/local/bin:/usr/bin:/bin"
Environment="AWS_REGION=us-east-1"
Environment="STRANDS_MODEL_ID=us.anthropic.claude-sonnet-4-20250514-v1:0"
ExecStart=/usr/bin/python3 live_data_generator.py
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable opsforge-generator
sudo systemctl start opsforge-generator
echo "Setup complete!"
echo ""
echo "Services status:"
sudo systemctl status opsforge-backend --no-pager
sudo systemctl status opsforge-generator --no-pager
sudo systemctl status nginx --no-pager
echo ""
echo "Access application at: http://$(curl -s http://169.254.169.254/latest/meta-data/public-ipv4)"