Add ntfy push and Listmonk newsletter with lightweight Docker deploy tooling.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
55
scripts/ssh-cleanup-heavy.py
Normal file
55
scripts/ssh-cleanup-heavy.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Stop and remove Cal.com / Owncast / PeerTube from China VPS."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import paramiko
|
||||
|
||||
HOST = os.getenv("NOMAD_SSH_HOST", "82.157.112.245")
|
||||
USER = os.getenv("NOMAD_SSH_USER", "ubuntu")
|
||||
PASSWORD = os.getenv("NOMAD_SSH_PASSWORD", "Xiao4669805")
|
||||
REMOTE_DIR = "/opt/nomadro-services/integrations"
|
||||
NGINX_DIR = "/www/server/panel/vhost/nginx"
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
HEAVY_DOMAINS = ["cal.nomadro.cn", "owncast.nomadro.cn", "peertube.nomadro.cn"]
|
||||
|
||||
|
||||
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 300) -> None:
|
||||
print(f"\n$ {cmd.replace(PASSWORD, '***')}")
|
||||
_, o, e = c.exec_command(f"echo '{PASSWORD}' | sudo -S bash -lc \"{cmd}\"", timeout=timeout, get_pty=True)
|
||||
sys.stdout.buffer.write(o.read())
|
||||
sys.stdout.buffer.write(e.read())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect(HOST, username=USER, password=PASSWORD, timeout=30)
|
||||
try:
|
||||
run(c, f"cd {REMOTE_DIR} && docker compose stop calcom owncast peertube redis-int 2>/dev/null || true")
|
||||
run(c, f"cd {REMOTE_DIR} && docker compose rm -f calcom owncast peertube redis-int 2>/dev/null || true")
|
||||
run(c, "docker rmi calcom/cal.com:v4.6.1 owncast/owncast:latest chocobozzz/peertube:production-bullseye 2>/dev/null || true")
|
||||
|
||||
for domain in HEAVY_DOMAINS:
|
||||
run(c, f"rm -f {NGINX_DIR}/{domain}.conf")
|
||||
|
||||
sftp = c.open_sftp()
|
||||
sftp.put(str(ROOT / "docker" / "integrations" / "docker-compose.yml"), f"{REMOTE_DIR}/docker-compose.yml")
|
||||
sftp.close()
|
||||
|
||||
run(c, f"cd {REMOTE_DIR} && docker compose up -d postgres-listmonk listmonk 2>/dev/null || "
|
||||
f"cd {REMOTE_DIR} && docker compose up -d postgres-int listmonk 2>/dev/null || true")
|
||||
run(c, "free -h | head -2")
|
||||
run(c, f"cd {REMOTE_DIR} && docker compose ps -a 2>/dev/null || docker ps -a")
|
||||
run(c, "nginx -t && nginx -s reload")
|
||||
run(c, "curl -sI https://listmonk.nomadro.cn/ | head -3")
|
||||
print("\n=== Heavy services removed, Listmonk kept ===")
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
76
scripts/ssh-fix-ntfy.py
Normal file
76
scripts/ssh-fix-ntfy.py
Normal file
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fix ntfy HTTPS nginx + verify push endpoint."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import paramiko
|
||||
|
||||
HOST = os.getenv("NOMAD_SSH_HOST", "82.157.112.245")
|
||||
USER = os.getenv("NOMAD_SSH_USER", "ubuntu")
|
||||
PASSWORD = os.getenv("NOMAD_SSH_PASSWORD", "Xiao4669805")
|
||||
NGINX_DIR = "/www/server/panel/vhost/nginx"
|
||||
WEBROOT = "/www/wwwroot/www.nomadro.cn"
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 120) -> None:
|
||||
print(f"\n$ {cmd.replace(PASSWORD, '***')}")
|
||||
_, o, e = c.exec_command(f"echo '{PASSWORD}' | sudo -S bash -lc \"{cmd}\"", timeout=timeout, get_pty=True)
|
||||
sys.stdout.buffer.write(o.read())
|
||||
sys.stdout.buffer.write(e.read())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect(HOST, username=USER, password=PASSWORD, timeout=30)
|
||||
try:
|
||||
# HTTP temp for certbot if needed
|
||||
http_only = f"""server {{
|
||||
listen 80;
|
||||
server_name ntfy.nomadro.cn;
|
||||
root {WEBROOT};
|
||||
location ^~ /.well-known/acme-challenge/ {{
|
||||
allow all;
|
||||
root {WEBROOT};
|
||||
}}
|
||||
location / {{
|
||||
proxy_pass http://127.0.0.1:9180;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
}}
|
||||
}}
|
||||
"""
|
||||
sftp = c.open_sftp()
|
||||
with sftp.file("/tmp/ntfy.http.conf", "w") as f:
|
||||
f.write(http_only)
|
||||
sftp.put(str(ROOT / "docker" / "integrations" / "nginx" / "ntfy.nomadro.cn.conf"), "/tmp/ntfy.https.conf")
|
||||
sftp.close()
|
||||
|
||||
run(c, f"cp /tmp/ntfy.http.conf {NGINX_DIR}/ntfy.nomadro.cn.conf")
|
||||
run(c, "nginx -t && nginx -s reload")
|
||||
|
||||
run(
|
||||
c,
|
||||
f"certbot certonly --webroot -w {WEBROOT} -d ntfy.nomadro.cn "
|
||||
f"--non-interactive --agree-tos -m xiaoshuang.eric@gmail.com || true",
|
||||
)
|
||||
|
||||
run(c, f"cp /tmp/ntfy.https.conf {NGINX_DIR}/ntfy.nomadro.cn.conf")
|
||||
run(c, "nginx -t && nginx -s reload")
|
||||
|
||||
# Recreate ntfy with base URL (optional env)
|
||||
run(c, "docker inspect nomadro-ntfy --format '{{.Config.Env}}' | head -1")
|
||||
run(c, "curl -sI http://127.0.0.1:9180/ | head -5")
|
||||
run(c, "curl -sI https://ntfy.nomadro.cn/ | head -8")
|
||||
run(c, "curl -s -X POST https://ntfy.nomadro.cn/nomadcna-healthcheck -H 'Title: NomadCNA' -d 'ntfy https ok'")
|
||||
print("\n=== ntfy HTTPS fix done ===")
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
55
scripts/ssh-git-pull-prod.py
Normal file
55
scripts/ssh-git-pull-prod.py
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Git pull on production VPS and restart API."""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
import paramiko
|
||||
|
||||
HOST = os.getenv("NOMAD_SSH_HOST", "82.157.112.245")
|
||||
USER = os.getenv("NOMAD_SSH_USER", "ubuntu")
|
||||
SSH_PASSWORD = os.getenv("NOMAD_SSH_PASSWORD", "Xiao4669805")
|
||||
REPO = "/home/ubuntu/gitlab-instance-0a899031_cnomadcna"
|
||||
GIT_USER = os.getenv("GIT_USER", "eric")
|
||||
GIT_PASSWORD = os.getenv("GIT_PASSWORD", "")
|
||||
GIT_REMOTE = os.getenv(
|
||||
"GIT_REMOTE",
|
||||
"https://gitea.dsx2020.com/eric/gitlab-instance-0a899031_cnomadcna.git",
|
||||
)
|
||||
BRANCH = os.getenv("GIT_BRANCH", "test2")
|
||||
|
||||
|
||||
def run(c: paramiko.SSHClient, cmd: str, timeout: int = 180) -> int:
|
||||
safe = cmd.replace(GIT_PASSWORD, "***").replace(SSH_PASSWORD, "***")
|
||||
print(f"\n$ {safe}")
|
||||
_, o, e = c.exec_command(f"echo '{SSH_PASSWORD}' | sudo -S bash -lc \"{cmd}\"", timeout=timeout, get_pty=True)
|
||||
out = o.read().decode("utf-8", errors="replace")
|
||||
err = e.read().decode("utf-8", errors="replace")
|
||||
code = o.channel.recv_exit_status()
|
||||
if out:
|
||||
sys.stdout.buffer.write(out.encode("utf-8", errors="replace"))
|
||||
if err:
|
||||
sys.stdout.buffer.write(err.encode("utf-8", errors="replace"))
|
||||
return code
|
||||
|
||||
|
||||
def main() -> int:
|
||||
auth_url = GIT_REMOTE.replace("https://", f"https://{GIT_USER}:{GIT_PASSWORD}@")
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect(HOST, username=USER, password=SSH_PASSWORD, timeout=30)
|
||||
try:
|
||||
run(c, f"cd {REPO} && git fetch {auth_url} {BRANCH}")
|
||||
run(c, f"cd {REPO} && git checkout {BRANCH}")
|
||||
run(c, f"cd {REPO} && git pull {auth_url} {BRANCH}")
|
||||
run(c, "systemctl restart cnomadcna-api.service")
|
||||
run(c, "systemctl is-active cnomadcna-api.service")
|
||||
run(c, f"cd {REPO} && git log -1 --oneline")
|
||||
return 0
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
45
scripts/ssh-restart-listmonk.py
Normal file
45
scripts/ssh-restart-listmonk.py
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env python3
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import paramiko
|
||||
|
||||
HOST = os.getenv("NOMAD_SSH_HOST", "82.157.112.245")
|
||||
USER = os.getenv("NOMAD_SSH_USER", "ubuntu")
|
||||
PASSWORD = os.getenv("NOMAD_SSH_PASSWORD", "Xiao4669805")
|
||||
REMOTE_DIR = "/opt/nomadro-services/integrations"
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
|
||||
def run(c: paramiko.SSHClient, cmd: str) -> None:
|
||||
print(f"\n$ {cmd.replace(PASSWORD, '***')}")
|
||||
_, o, e = c.exec_command(f"echo '{PASSWORD}' | sudo -S bash -lc \"{cmd}\"", timeout=120, get_pty=True)
|
||||
sys.stdout.buffer.write(o.read())
|
||||
sys.stdout.buffer.write(e.read())
|
||||
|
||||
|
||||
def main() -> None:
|
||||
c = paramiko.SSHClient()
|
||||
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||||
c.connect(HOST, username=USER, password=PASSWORD, timeout=30)
|
||||
try:
|
||||
sftp = c.open_sftp()
|
||||
sftp.put(str(ROOT / "docker" / "integrations" / "docker-compose.yml"), f"{REMOTE_DIR}/docker-compose.yml")
|
||||
sftp.close()
|
||||
run(c, f"cd {REMOTE_DIR} && docker compose rm -f postgres-listmonk listmonk 2>/dev/null || true")
|
||||
run(c, f"cd {REMOTE_DIR} && docker compose up -d postgres-int listmonk")
|
||||
run(c, "sleep 6")
|
||||
run(c, "docker logs integrations-listmonk-1 --tail 10")
|
||||
run(c, "curl -sI http://127.0.0.1:9030/ | head -3")
|
||||
run(c, "curl -sI https://listmonk.nomadro.cn/ | head -3")
|
||||
run(c, f"cd {REMOTE_DIR} && docker compose ps")
|
||||
run(c, "free -h | head -2")
|
||||
finally:
|
||||
c.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user