notify.py 704 B

123456789101112131415161718192021222324
  1. import os
  2. import subprocess
  3. import sys
  4. def run_notify(cmd, domain, status, error=""):
  5. """Run notification command with stdout/stderr redirected to stderr and timeout protection."""
  6. if not cmd:
  7. return
  8. env = os.environ.copy()
  9. env["AUTODOMAIN"] = str(domain or "")
  10. env["AUTODOMAIN_STATUS"] = str(status or "")
  11. env["AUTODOMAIN_ERROR"] = str(error or "")
  12. try:
  13. subprocess.run(
  14. ["/bin/sh", "-c", cmd],
  15. env=env,
  16. stdout=sys.stderr,
  17. stderr=sys.stderr,
  18. timeout=15,
  19. check=False,
  20. )
  21. except Exception as exc:
  22. print(f"WARN: notify command execution failed: {exc}", file=sys.stderr)