50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
import sys
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding='utf-8')
|
|
|
|
NODES = [
|
|
("swm01", "140.44.4.71"),
|
|
("swm02", "140.44.4.72"),
|
|
("swm03", "140.44.4.73"),
|
|
("swm04", "140.44.4.74"),
|
|
("swm05", "140.44.4.75"),
|
|
]
|
|
|
|
SCRIPT_CONTENT = """#!/bin/bash
|
|
# Check docker daemon health
|
|
systemctl is-active --quiet docker || exit 1
|
|
|
|
# If NPM container is running on this node, verify HTTP responsiveness
|
|
if docker ps --format '{{.Names}}' 2>/dev/null | grep -q "nginx-proxy-manager_app"; then
|
|
curl -sf -m 2 http://127.0.0.1:80 >/dev/null 2>&1 || curl -sf -m 2 http://127.0.0.1:81 >/dev/null 2>&1 || exit 1
|
|
fi
|
|
|
|
exit 0
|
|
"""
|
|
|
|
def main():
|
|
for name, ip in NODES:
|
|
print(f"=== Updating {name} ({ip}) ===")
|
|
ssh = paramiko.SSHClient()
|
|
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
ssh.connect(ip, username='snarf', key_filename=r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet', timeout=10)
|
|
|
|
# Write to temp file then sudo mv
|
|
sftp = ssh.open_sftp()
|
|
with sftp.open('/tmp/check_docker.sh', 'w') as f:
|
|
f.write(SCRIPT_CONTENT.replace('\r\n', '\n'))
|
|
sftp.close()
|
|
|
|
cmd = "sudo mv /tmp/check_docker.sh /etc/keepalived/scripts/check_docker.sh && sudo chmod +x /etc/keepalived/scripts/check_docker.sh && sudo /etc/keepalived/scripts/check_docker.sh && echo 'TEST: OK'"
|
|
stdin, stdout, stderr = ssh.exec_command(cmd)
|
|
print(stdout.read().decode().strip())
|
|
err = stderr.read().decode().strip()
|
|
if err:
|
|
print("ERR:", err)
|
|
|
|
ssh.close()
|
|
|
|
if __name__ == '__main__':
|
|
main()
|