From 7efb910719b87843486269b1419dece0e183e92f Mon Sep 17 00:00:00 2001 From: "flow.gunso" Date: Thu, 30 Jan 2020 17:45:22 +0100 Subject: [PATCH] Check the repo sync/transfer task states --- seafile-client/seafile-healthcheck.py | 37 ++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/seafile-client/seafile-healthcheck.py b/seafile-client/seafile-healthcheck.py index a11c053..7029df0 100755 --- a/seafile-client/seafile-healthcheck.py +++ b/seafile-client/seafile-healthcheck.py @@ -16,6 +16,10 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +# Given a path to a valid Seafile confdir and a repository, check the +# synchronization status and otherwise the transfer status of that +# repository. + import argparse import os import sys @@ -24,19 +28,38 @@ import seafile if __name__ == "__main__": + # Parse Seafile's confdir and repository ID to check. parser = argparse.ArgumentParser(description="Check the status of a synced repository.") parser.add_argument('repository_id', type=str, help="Repository ID to check the status of.") parser.add_argument('-c', '--confdir', type=str, required=True, help="Seafile configuration directory to load the Socket from.") args = parser.parse_args() + # Instanciate Seafile RPC. seafile_socket = os.path.join(args.confdir, "seafile.sock") if not os.path.exists(seafile_socket): raise Exception("Could not find a Seafile socket at {}".format(args.confdir)) - seafile_rpc = seafile.RpcClient(os.path.join(args.confdir, "seafile.sock")) - repo_sync_task = seafile_rpc.get_repo_sync_task(args.repository_id) - if repo_sync_task is None: - raise Exception("Unable to fetch task informations for repository {}".format(args.repository_id)) - - if repo_sync_task.state == "error": - raise Exception("The repository {} is in an error state.".format(args.repository_id)) + + # Fetch the sync task of the repository. + repository_sync_task = seafile_rpc.get_repo_sync_task(args.repository_id) + if repository_sync_task is not None: + sync_state = repository_sync_task.state + msg = "Repository synchronization state: {}".format(sync_state) + if sync_state == "error": + raise Exception(msg) + else: + print(msg) + sys.exit(0) + + # Fetch the transfer task of the repository. + repository_transfer_task = seafile_rpc.find_transfer_task(args.repository_id) + if repository_transfer_task is not None: + transfer_state = repository_transfer_task.state + msg = "Repository transfer state: {}".format(transfer_state) + if transfer_state == "error": + raise Exception(msg) + else: + print(msg) + sys.exit(0) + + raise Exception("Could not find any information about any repository synchronization or transfer tasks.")