[STAGE5] Gateway-only production agent service
This commit is contained in:
1 parent
32f23ed184
commit
15ed2067e8
3 files changed
+60
-4
No files matched your search
@@ -10,14 +10,23 @@
|
||||
- остальное — `REJECT`;
|
||||
- агент запускается как `agent-gw` и ходит только через Tool Gateway.
|
||||
|
||||
## Проверка
|
||||
## Production-style agent
|
||||
|
||||
```text
|
||||
runuser -u agent-gw -- python3 /opt/agent-gw/agent.py
|
||||
gateway_agent_ok catalog.read 6884
|
||||
agent-gw.service
|
||||
User=agent-gw
|
||||
catalog.read every 5 min via 127.0.0.1:9137
|
||||
log: /var/lib/agent-gw/agent.log
|
||||
```
|
||||
|
||||
Проверка:
|
||||
|
||||
```text
|
||||
systemctl is-active agent-gw → active
|
||||
{"tool":"catalog.read","bytes":6884}
|
||||
|
||||
runuser -u agent-gw -- curl http://127.0.0.1:9120/catalog
|
||||
connect failed / direct=000
|
||||
direct=000
|
||||
```
|
||||
|
||||
## Ограничение
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
[Unit]
|
||||
Description=Buryans gateway-only agent
|
||||
After=network.target hub-tools.service
|
||||
Wants=hub-tools.service
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=agent-gw
|
||||
Group=agent-gw
|
||||
ExecStart=/usr/bin/python3 /opt/agent-gw/service.py
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Production-style gateway-only agent: catalog read every 5 minutes."""
|
||||
import json, time, urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
BASE = "http://127.0.0.1:9137"
|
||||
LOG = Path("/var/lib/agent-gw/agent.log")
|
||||
|
||||
|
||||
def call(tool):
|
||||
with urllib.request.urlopen(BASE + "/v1/call?tool=" + tool, timeout=10) as r:
|
||||
return json.loads(r.read().decode())
|
||||
|
||||
|
||||
def main():
|
||||
LOG.parent.mkdir(parents=True, exist_ok=True)
|
||||
while True:
|
||||
try:
|
||||
d = call("catalog.read")
|
||||
with LOG.open("a") as f:
|
||||
f.write(json.dumps({"ts": time.time(), "tool": "catalog.read",
|
||||
"bytes": len(d.get("body") or "")}) + "\n")
|
||||
except Exception as e:
|
||||
with LOG.open("a") as f:
|
||||
f.write(json.dumps({"ts": time.time(), "error": str(e)[:200]}) + "\n")
|
||||
time.sleep(300)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user