Add a health check for the daemon and RPC endpoint (#34)
* Add a health check for the daemon and RPC endpoint SeafileClient.is_healthy() checks seaf-cli status and makes a real RPC call (get_repo_list) against the daemon's Unix socket - neither needs the Seafile server, so it works without a token or password. healthcheck.py exposes it as a plain script for Docker's HEALTHCHECK. Each check is a fresh process spawned by the Docker daemon as root, unlike the long-lived start.py process, so it drops to the seafile user with runuser before touching the RPC socket - the one place that mechanism still belongs after the earlier in-process privilege drop. Verified against the real image: healthcheck.py exits 0 once the real daemon is up (through the actual main() entrypoint, not a test fixture) and nonzero when no daemon has been started. * Assert the return value in the daemon-down health check test Copilot review: the test checked the RPC call was skipped but not what is_healthy() actually returned in that case. --------- Co-authored-by: Maxim Shulga <maxim.shulga@alludo.com>
This commit is contained in:
1 parent
ba5ad177b7
commit
28db575c92
7 files changed
+133
-4
No files matched your search
@@ -165,6 +165,22 @@ class SeafileClient:
|
||||
self.__wait_for_daemon(False, const.DAEMON_STOP_TIMEOUT, "stopping")
|
||||
_lg.info("Seafile daemon is stopped")
|
||||
|
||||
def is_healthy(self) -> bool:
|
||||
"""
|
||||
Report whether the daemon process and its RPC socket both respond.
|
||||
|
||||
Used by the container's HEALTHCHECK. Neither check needs the Seafile
|
||||
server, so this works without a token or password.
|
||||
"""
|
||||
if not self.daemon_ready:
|
||||
return False
|
||||
try:
|
||||
self.rpc.get_repo_list(-1, -1)
|
||||
except Exception as err:
|
||||
_lg.warning("RPC endpoint is not responding: %s", err)
|
||||
return False
|
||||
return True
|
||||
|
||||
def get_library_id(self, library) -> Optional[str]:
|
||||
"""
|
||||
Resolve a requested name or ID to the one library ID it names.
|
||||
|
||||
Reference in new issue
Block a user