<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
#!/opt/cloudlinux/venv/bin/python3 -sbb
# -*- coding: utf-8 -*-
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENCE.TXT
#
import os
import shutil
import subprocess

SERVICE_NAME = "cagefs-docroot-monitor.service"
SERVICE_PATH = f"/usr/share/cagefs/service/{SERVICE_NAME}"
SYSTEMD_UNIT_PATH = f"/etc/systemd/system/{SERVICE_NAME}"


def is_running():
    result = subprocess.run(
        ["/usr/bin/systemctl", "is-active", SERVICE_NAME], capture_output=True, text=True
    )
    return result.returncode == 0


def start_monitoring_service():
    if is_running():
        return
    shutil.copy(SERVICE_PATH, SYSTEMD_UNIT_PATH)
    result = subprocess.run(
        ["/usr/bin/systemctl", "enable", SERVICE_NAME], capture_output=True, text=True, check=True
    )
    if result.returncode:
        return
    result = subprocess.run(
        ["/usr/bin/systemctl", "daemon-reload"], capture_output=True, text=True, check=True
    )
    if result.returncode:
        return

    subprocess.run(
        ["/usr/bin/systemctl", "start", SERVICE_NAME], capture_output=True, text=True, check=True
    )


def stop_monitoring_service():
    if is_running():
        subprocess.run(
            ["/usr/bin/systemctl", "stop", SERVICE_NAME], capture_output=True, text=True, check=True
        )
    # disable may fail if the unit file was never installed — that's fine
    subprocess.run(
        ["/usr/bin/systemctl", "disable", SERVICE_NAME], capture_output=True, text=True
    )

    if os.path.exists(SYSTEMD_UNIT_PATH):
        os.remove(SYSTEMD_UNIT_PATH)

    subprocess.run(
        ["/usr/bin/systemctl", "daemon-reload"], capture_output=True, text=True, check=True
    )
