D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
opt
/
cloudlinux
/
venv
/
lib
/
python3.11
/
site-packages
/
clcagefslib
/
webisolation
/
Filename :
service.py
back
Copy
#!/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 ) subprocess.run( ["/usr/bin/systemctl", "disable", SERVICE_NAME], capture_output=True, text=True, check=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 )