-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
103 lines (82 loc) · 2.83 KB
/
setup.sh
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
#!/bin/bash
# -----------------------------
# 1) CONFIGURATION
# -----------------------------
DOMAIN1="chat.uottahack.ca"
DOMAIN2="chat-staging.uottahack.ca"
PORT="3001" # Port your FastAPI app will listen on
FASTAPI_APP="app.py" # Path to your FastAPI file
DISCORD_BOT="bot.py" # Path to your Discord bot file
# -----------------------------
# 2) SYSTEM & NGINX SETUP
# -----------------------------
echo "Updating system packages..."
sudo apt update && sudo apt upgrade -y
echo "Installing NGINX, Certbot, and Python3..."
sudo apt install -y nginx certbot python3-certbot-nginx python3-pip
# -----------------------------
# 3) CONFIGURE NGINX FOR DOMAINS
# -----------------------------
echo "Configuring NGINX for $DOMAIN1 and $DOMAIN2..."
# Create NGINX config for DOMAIN1
cat <<EOF | sudo tee /etc/nginx/sites-available/$DOMAIN1
server {
listen 80;
server_name $DOMAIN1;
location / {
proxy_pass http://127.0.0.1:$PORT;
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
# Enable the site for DOMAIN1
sudo ln -sf /etc/nginx/sites-available/$DOMAIN1 /etc/nginx/sites-enabled/$DOMAIN1
# Create NGINX config for DOMAIN2
cat <<EOF | sudo tee /etc/nginx/sites-available/$DOMAIN2
server {
listen 80;
server_name $DOMAIN2;
location / {
proxy_pass http://127.0.0.1:$PORT;
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
# Enable the site for DOMAIN2
sudo ln -sf /etc/nginx/sites-available/$DOMAIN2 /etc/nginx/sites-enabled/$DOMAIN2
# Test and reload NGINX
sudo nginx -t
sudo systemctl reload nginx
# -----------------------------
# 4) OBTAIN SSL CERTIFICATES
# -----------------------------
echo "Obtaining SSL certificates via Certbot..."
sudo certbot --nginx -d $DOMAIN1 -d $DOMAIN2 --non-interactive --agree-tos -m [email protected]
# Enable auto-renewal
sudo systemctl enable --now certbot.timer
# Restart NGINX
sudo systemctl restart nginx
echo "NGINX has been configured for $DOMAIN1 and $DOMAIN2 with SSL."
# -----------------------------
# 5) PYTHON DEPENDENCIES
# -----------------------------
echo "Installing Python dependencies..."
pip3 install --user -r requirements.txt
# -----------------------------
# 6) LAUNCH FASTAPI & DISCORD BOT
# -----------------------------
echo "Launching FastAPI on port $PORT..."
# Run FastAPI in the background
nohup python3 "$FASTAPI_APP" > fastapi.log 2>&1 &
echo "Launching Discord Bot..."
# Run Discord Bot in the background
nohup python3 "$DISCORD_BOT" > discordbot.log 2>&1 &
echo "All services have been started successfully!"