fix(mcp,db,systemd,logrotate): move telemetry DB to /var/lib/hyperstitionstud.io/api-telemetry.db via StateDirectory=hyperstitionstud.io and catch sqlite3.Error (v2.0.22)
This commit is contained in:
1 parent
95a5fc8618
commit
9716a0ab61
24 files changed
+140
-84
No files matched your search
@@ -214,6 +214,23 @@ def get_default_telemetry_db_path() -> Path:
|
||||
env_p = os.environ.get("HYPERSTITION_TELEMETRY_DB_PATH")
|
||||
if env_p:
|
||||
return Path(env_p)
|
||||
state_dir = Path("/var/lib/hyperstitionstud.io")
|
||||
if state_dir.is_dir() and os.access(state_dir, os.W_OK):
|
||||
return state_dir / "api-telemetry.db"
|
||||
if state_dir.parent.is_dir() and os.access(state_dir.parent, os.W_OK):
|
||||
try:
|
||||
state_dir.mkdir(parents=True, exist_ok=True)
|
||||
if os.access(state_dir, os.W_OK):
|
||||
return state_dir / "api-telemetry.db"
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
cache_dir = Path.home() / ".cache" / "hyperstitionstud.io"
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
if os.access(cache_dir, os.W_OK):
|
||||
return cache_dir / "api-telemetry.db"
|
||||
except OSError:
|
||||
pass
|
||||
return Path("/tmp/hyperstition-api-telemetry.db")
|
||||
|
||||
|
||||
@@ -994,8 +1011,15 @@ def record_api_telemetry(
|
||||
raise
|
||||
finally:
|
||||
conn.close()
|
||||
for suf in ("", "-wal", "-shm"):
|
||||
cand = Path(f"{t_path}{suf}")
|
||||
if cand.exists():
|
||||
try:
|
||||
os.chmod(cand, 0o666)
|
||||
except OSError:
|
||||
pass
|
||||
return {"ok": True, "db_path": str(t_path)}
|
||||
except OSError as exc:
|
||||
except Exception as exc:
|
||||
return {"ok": False, "error": str(exc)}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user