%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/share/l.v.e-manager/hooks/universal/
Upload File :
Create Path :
Current File : //usr/share/l.v.e-manager/hooks/universal/hook_update_cl_summary.py

#!/opt/cloudlinux/venv/bin/python3 -bb
# -*- coding: utf-8 -*-
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2025 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

import os
import json
import subprocess

CL_SUMMARY_BIN = '/usr/sbin/cloudlinux-summary'
CL_WIZARD_BIN = '/usr/sbin/cloudlinux-wizard'


def is_wizard_in_progress():
    """
    Check if wizard in progress
    return: bool
    """
    result = subprocess.run(
        [CL_WIZARD_BIN, "status"],
        capture_output=True,
        text=True
    )

    if result.returncode != 0:
        return False

    try:
        status_info = json.loads(result.stdout)
        return status_info.get('wizard_status') == 'in_progress'
    except json.JSONDecodeError:
        return False


def is_summary_status_collecting():
    """
    Check if data collecting
    return: bool
    """
    result = subprocess.run(
        [CL_SUMMARY_BIN, 'status', '--json'],
        capture_output=True,
        text=True
    )
    try:
        return json.loads(result.stdout).get('status') == 'collecting'
    except json.JSONDecodeError:
        return False


def main():
    """
    Main function used to trigger cloudlinux-summary
    """
    wizard_progress = is_wizard_in_progress()
    summary_progress = is_summary_status_collecting()

    if wizard_progress or summary_progress:
        return

    print('Run cloudlinux-summary for collecting data.')
    subprocess.call(
        [CL_SUMMARY_BIN, '--send', '--async', '--json'],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL
    )


if __name__ == "__main__":
    main()

Zerion Mini Shell 1.0