feat: add various infrastructure check and automation scripts

This commit is contained in:
2026-11-15 17:17:41 -05:00
parent 336b7759d0
commit b301aa3ece
232 changed files with 8274 additions and 298 deletions

View File

@@ -0,0 +1,139 @@
import sys
import time
import paramiko
HOST = "140.44.44.80"
USER = "root"
KEY_FILE = r"C:\Users\Snarf\.ssh\id_ed25519_snarfnet"
def main():
print(f"Connecting to {USER}@{HOST}...")
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(HOST, username=USER, key_filename=KEY_FILE, timeout=10)
print("Connected!")
def run(cmd, check=True):
print(f"\n>>> [RUN] {cmd}")
stdin, stdout, stderr = ssh.exec_command(cmd)
while not stdout.channel.exit_status_ready():
time.sleep(0.5)
out = stdout.read().decode()
err = stderr.read().decode()
rc = stdout.channel.recv_exit_status()
if out:
print(out.strip())
if err and "warning" not in err.lower() and "already exists" not in err.lower():
print(f"[STDERR] {err.strip()}", file=sys.stderr)
if check and rc != 0:
print(f"[FAIL] Exit code: {rc}", file=sys.stderr)
return rc, out, err
# ==========================================
# Step 1: Format and Mount Empty Disks
# ==========================================
print("\n--- Step 1: Formatting and Mounting Secondary Disks ---")
run("mkfs.ext4 -F -m 1 -L nvme-games /dev/nvme0n1")
run("mkfs.ext4 -F -m 1 -L storage-games /dev/sdb")
# Get UUIDs
_, out_nvme, _ = run("blkid -s UUID -o value /dev/nvme0n1")
nvme_uuid = out_nvme.strip()
_, out_sdb, _ = run("blkid -s UUID -o value /dev/sdb")
sdb_uuid = out_sdb.strip()
print(f"NVMe UUID: {nvme_uuid}")
print(f"SDB UUID: {sdb_uuid}")
run("mkdir -p /mnt/nvme-games /mnt/storage-games")
# Update /etc/fstab
fstab_add = f"""
UUID={nvme_uuid} /mnt/nvme-games ext4 defaults,noatime,discard 0 2
UUID={sdb_uuid} /mnt/storage-games ext4 defaults,noatime,discard 0 2
"""
run(f"grep -qs '{nvme_uuid}' /etc/fstab || cat << 'EOF' >> /etc/fstab{fstab_add}EOF")
run("mount -a")
run("df -h /mnt/nvme-games /mnt/storage-games")
# Move /opt/game-servers to NVMe and link / create directory structure
run("mkdir -p /mnt/nvme-games/game-servers")
run("cp -a /opt/game-servers/* /mnt/nvme-games/game-servers/ 2>/dev/null || true")
run("rm -rf /opt/game-servers")
run("ln -s /mnt/nvme-games/game-servers /opt/game-servers")
run("ln -s /mnt/storage-games /opt/game-storage 2>/dev/null || true")
run("chown -R snarf:snarf /mnt/nvme-games /mnt/storage-games")
run("chmod -R 775 /mnt/nvme-games/game-servers")
# Ensure all game server subdirs exist on NVMe
run("mkdir -p /opt/game-servers/{enshrouded,fs25,stationeers,valheim,vrising}/{savegame,saves,worlds,data}")
run("chown -R snarf:snarf /opt/game-servers")
# ==========================================
# Step 2: Install and Configure Zabbix Agent 2
# ==========================================
print("\n--- Step 2: Installing and Configuring Zabbix Agent 2 ---")
run("DEBIAN_FRONTEND=noninteractive apt-get install -y zabbix-agent2 || true")
# Configure PSK
run("mkdir -p /etc/zabbix")
run("echo 'a1142332ccfa9c53040e36171bb551ceb2865fb4051d203404df39e88ebe94f0' > /etc/zabbix/zabbix_agent2.psk")
run("chmod 600 /etc/zabbix/zabbix_agent2.psk")
run("chown zabbix:zabbix /etc/zabbix/zabbix_agent2.psk 2>/dev/null || true")
zbx_conf = """Server=140.44.4.70,zabbix.snarfnet.net
ServerActive=140.44.4.70
HostnameItem=system.hostname
HostMetadata=Linux
TLSConnect=psk
TLSAccept=psk
TLSPSKIdentity=PSK_autoregister
TLSPSKFile=/etc/zabbix/zabbix_agent2.psk
LogFile=/var/log/zabbix/zabbix_agent2.log
LogFileSize=10
BufferSend=5
BufferSize=100
"""
run(f"cat << 'EOF' > /etc/zabbix/zabbix_agent2.conf\n{zbx_conf}\nEOF")
run("systemctl enable --now zabbix-agent2.service")
run("systemctl restart zabbix-agent2.service")
time.sleep(2)
run("systemctl is-active zabbix-agent2.service")
# ==========================================
# Step 3: Game Seeds Environment & Compose
# ==========================================
print("\n--- Step 3: Configuring Game Server Passwords (.env) ---")
sftp = ssh.open_sftp()
sftp.put(r"C:\Users\Snarf\OneDrive\Desktop\code\SnarfCode\snarfnet-game-seeds\core\manager.py", "/opt/snarfnet-game-seeds/core/manager.py")
sftp.close()
run("chmod +x /opt/snarfnet-game-seeds/core/manager.py")
env_content = """# SnarfNet Game Server Passwords & Configuration
ENSHROUDED_SERVER_PASSWORD=SnarfNet2026!
SERVER_PASSWORD=SnarfNet2026!
FS25_SERVER_PASSWORD=SnarfNet2026!
FS25_ADMIN_PASSWORD=SnarfNetAdmin2026!
STATIONEERS_SERVER_PASSWORD=SnarfNet2026!
VALHEIM_SERVER_PASSWORD=SnarfNet2026!
SERVER_PASS=SnarfNet2026!
VRISING_SERVER_PASSWORD=SnarfNet2026!
"""
run(f"cat << 'EOF' > /opt/snarfnet-game-seeds/.env\n{env_content}\nEOF")
run("chown snarf:snarf /opt/snarfnet-game-seeds/.env && chmod 600 /opt/snarfnet-game-seeds/.env")
# Regenerate Compose
run("cd /opt/snarfnet-game-seeds && python3 core/manager.py compose")
# ==========================================
# Step 4: Pull Images and Launch Game Servers
# ==========================================
print("\n--- Step 4: Launching Docker Containers ---")
run("cd /opt/snarfnet-game-seeds && docker compose up -d")
time.sleep(5)
run("docker ps -a")
ssh.close()
print("\n🎉 All steps completed successfully!")
if __name__ == "__main__":
main()