116 lines
3.4 KiB
Python
116 lines
3.4 KiB
Python
# Deploy the dynamic site engine to all 8 CTs and start them as services
|
|
import subprocess
|
|
import sys
|
|
import time
|
|
|
|
SITES = {
|
|
"ai": (135, "10.30.20.240"),
|
|
"tech": (136, "10.30.20.241"),
|
|
"science": (137, "10.30.20.242"),
|
|
"crypto": (138, "10.30.20.243"),
|
|
"linux": (139, "10.30.20.244"),
|
|
"gaming": (140, "10.30.20.246"),
|
|
"diy": (141, "10.30.20.247"),
|
|
"guides": (142, "10.30.20.248"),
|
|
}
|
|
|
|
PROXMOX = "root@10.30.20.85"
|
|
|
|
|
|
def ssh(cmd, timeout=30):
|
|
return subprocess.run(
|
|
["ssh", "-o", "ConnectTimeout=5", PROXMOX, cmd],
|
|
capture_output=True, text=True, timeout=timeout
|
|
).stdout.strip()
|
|
|
|
|
|
def deploy_all():
|
|
print("=" * 60)
|
|
print("DEPLOYING DYNAMIC SITE ENGINE TO ALL 8 CTs")
|
|
print("=" * 60)
|
|
|
|
# Create systemd service file content
|
|
service_unit = """[Unit]
|
|
Description=Auto Publisher Site ({vertical})
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=root
|
|
WorkingDirectory=/opt/publisher
|
|
Environment=PUBLISHER_VERTICAL={vertical}
|
|
Environment=PUBLISHER_SECRET=auto-publish-2026
|
|
ExecStart=/usr/bin/python3 /opt/publisher/app.py --port 5000 --host 0.0.0.0
|
|
Restart=always
|
|
RestartSec=5
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
"""
|
|
|
|
nginx_conf = """server {{
|
|
listen 80;
|
|
server_name {vertical}.thetempleofdoom.com;
|
|
|
|
location / {{
|
|
proxy_pass http://127.0.0.1:5000;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
}}
|
|
|
|
location /a/ping {{
|
|
proxy_pass http://127.0.0.1:5000;
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
}}
|
|
}}
|
|
"""
|
|
|
|
for vertical, (vmid, ip) in SITES.items():
|
|
print(f"\n{'─'*40}")
|
|
print(f"📡 {vertical}.thetempleofdoom.com (CT {vmid}, {ip})")
|
|
|
|
# Write systemd unit via base64
|
|
import base64
|
|
unit_b64 = base64.b64encode(
|
|
service_unit.format(vertical=vertical).encode()
|
|
).decode()
|
|
|
|
ssh(f"pct exec {vmid} -- bash -c 'echo {unit_b64} | base64 -d > /etc/systemd/system/publisher.service'")
|
|
ssh(f"pct exec {vmid} -- systemctl daemon-reload")
|
|
ssh(f"pct exec {vmid} -- systemctl enable publisher")
|
|
ssh(f"pct exec {vmid} -- systemctl restart publisher")
|
|
time.sleep(2)
|
|
|
|
# Check if running
|
|
status = ssh(f"pct exec {vmid} -- systemctl is-active publisher")
|
|
print(f" Service: {status}")
|
|
|
|
# Update nginx to proxy to Flask
|
|
nginx_b64 = base64.b64encode(
|
|
nginx_conf.format(vertical=vertical).encode()
|
|
).decode()
|
|
ssh(f"pct exec {vmid} -- bash -c 'echo {nginx_b64} | base64 -d > /etc/nginx/sites-available/default'")
|
|
ssh(f"pct exec {vmid} -- nginx -t 2>&1")
|
|
ssh(f"pct exec {vmid} -- systemctl restart nginx")
|
|
|
|
# Verify
|
|
time.sleep(1)
|
|
print(f" Testing http://{ip}:80/ ...")
|
|
result = subprocess.run(
|
|
["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}",
|
|
f"http://{ip}:80/", "--connect-timeout", "5"],
|
|
capture_output=True, text=True, timeout=10
|
|
)
|
|
print(f" HTTP {result.stdout.strip()}")
|
|
|
|
print(f"\n{'='*60}")
|
|
print("ALL 8 SITES DEPLOYED AS DYNAMIC SERVICES")
|
|
print(f"{'='*60}")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
deploy_all()
|