-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguardian_ctl.py
More file actions
30 lines (24 loc) · 1012 Bytes
/
Copy pathguardian_ctl.py
File metadata and controls
30 lines (24 loc) · 1012 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Command-line status and lifecycle control for the singleton Guardian."""
from __future__ import annotations
import argparse
import json
from guardian_client import ensure_broker, job_status, ping, stop_broker
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("action", choices=("status", "start", "stop", "job"))
parser.add_argument("job_id", nargs="?")
options = parser.parse_args()
if options.action == "status":
result = ping() or {"ok": False, "status": "stopped"}
elif options.action == "start":
result = ensure_broker()
elif options.action == "stop":
result = stop_broker() if ping() else {"ok": True, "status": "already stopped"}
else:
if not options.job_id:
parser.error("job requires a job_id")
result = job_status(options.job_id)
print(json.dumps(result, indent=2))
return 0 if result.get("ok") else 1
if __name__ == "__main__":
raise SystemExit(main())