system_service.py 819 B

1234567891011121314151617181920212223
  1. import subprocess
  2. from loguru import logger
  3. def restart_squid() -> tuple[bool, str, str]:
  4. try:
  5. subprocess.run(["systemctl", "restart", "squid"], check=True)
  6. return True, "Squid restarted successfully", None
  7. except Exception:
  8. logger.exception("Error restarting squid")
  9. # Do not expose raw exception details to callers; log only.
  10. return False, "Internal server error", None
  11. def reload_squid() -> tuple[bool, str, str]:
  12. try:
  13. subprocess.run(["systemctl", "reload", "squid"], check=True)
  14. return True, "Configuration reloaded successfully", None
  15. except Exception:
  16. logger.exception("Error reloading squid configuration")
  17. # Do not expose raw exception details to callers; log only.
  18. return False, "Internal server error", None