feat: add various infrastructure check and automation scripts
This commit is contained in:
53
scripts/update_npm_direct.py
Normal file
53
scripts/update_npm_direct.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import paramiko
|
||||
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect("140.44.4.71", username="snarf", password="Katzir476!", timeout=10)
|
||||
|
||||
py_code = """
|
||||
import sqlite3
|
||||
import json
|
||||
|
||||
db_path = '/var/lib/docker/volumes/nginx-proxy-manager_nginx-data/_data/database.sqlite'
|
||||
con = sqlite3.connect(db_path)
|
||||
cur = con.cursor()
|
||||
domains = ["portal.snarfnet.net", "heimdall.snarfnet.net"]
|
||||
cur.execute("UPDATE proxy_host SET domain_names = ? WHERE id = 4", (json.dumps(domains),))
|
||||
con.commit()
|
||||
print("Updated DB host 4 domain_names:", cur.execute("SELECT id, domain_names FROM proxy_host WHERE id=4").fetchone())
|
||||
con.close()
|
||||
|
||||
# Also update 4.conf on disk directly
|
||||
conf_path = '/var/lib/docker/volumes/nginx-proxy-manager_nginx-data/_data/nginx/proxy_host/4.conf'
|
||||
with open(conf_path, 'r') as f:
|
||||
text = f.read()
|
||||
|
||||
if 'heimdall.snarfnet.net' not in text:
|
||||
text = text.replace('server_name portal.snarfnet.net;', 'server_name portal.snarfnet.net heimdall.snarfnet.net;')
|
||||
with open(conf_path, 'w') as f:
|
||||
f.write(text)
|
||||
print("Updated 4.conf successfully!")
|
||||
else:
|
||||
print("4.conf already has heimdall.snarfnet.net")
|
||||
"""
|
||||
|
||||
stdin, stdout, stderr = c.exec_command("cat > /tmp/update_npm_conf.py")
|
||||
stdin.write(py_code)
|
||||
stdin.close()
|
||||
stdout.channel.recv_exit_status()
|
||||
|
||||
_, o, e = c.exec_command("echo Katzir476! | sudo -S python3 /tmp/update_npm_conf.py")
|
||||
print(o.read().decode())
|
||||
if e.read().decode(): print("ERR:", e.read().decode())
|
||||
|
||||
# Test and reload nginx inside NPM container
|
||||
cid_cmd = "docker ps -q -f name=nginx-proxy-manager"
|
||||
_, cid_out, _ = c.exec_command(f"echo Katzir476! | sudo -S {cid_cmd}")
|
||||
cid = cid_out.read().decode().strip()
|
||||
if cid:
|
||||
_, o, e = c.exec_command(f"echo Katzir476! | sudo -S docker exec {cid} nginx -t")
|
||||
print("Nginx -t:\n", o.read().decode(), e.read().decode())
|
||||
_, o, e = c.exec_command(f"echo Katzir476! | sudo -S docker exec {cid} nginx -s reload")
|
||||
print("Nginx reload:\n", o.read().decode(), e.read().decode())
|
||||
|
||||
c.close()
|
||||
Reference in New Issue
Block a user