ok
Direktori : /opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/ |
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/daemon_base.py |
# 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 # # pylint: disable=no-absolute-import import logging import os import signal from clcommon.utils import get_process_pid from clwpos.daemon_config import load_config logger = logging.getLogger(__name__) class WposDaemonBase: """ AccelerateWP daemon base class. Signals, signal handlers, setup daemon logger, pid file operations """ _PID_FILENAME = "/var/run/clwpos_monitoring.pid" def __init__(self): self._reload_config_need = False self._is_terminate = False self._config = load_config() logger.info("Cloudlinux AccelerateWP daemon uses monitoring interval: %d seconds", self._config.monitoring_interval) if not self._config.enable_reload_rate_limit: logger.info("NOTE: Cloudlinux AccelerateWP daemon check reload interval is OFF by config") logger.info("NOTE: Cloudlinux AccelerateWP daemon logging level=%s", self._config.logging_level) def _setup_signals(self): """ Setup daemon signal handlers """ # Setup SIGHUP signal handler for config reload signal.signal(signal.SIGHUP, self._sighup_handler) # Setup Ctrl-C signal handler. Used for console debug signal.signal(signal.SIGINT, self._sigint_handler) # Setup SIGTERM signal. Called when daemon stops signal.signal(signal.SIGTERM, self._sigterm_handler) def run(self): """ Main work daemon function (implement in child class) """ raise NotImplementedError() def stop(self, *args, **kwargs): """ Stops a working daemon process (implement in child class) """ raise NotImplementedError() def reload(self): """ Reload working daemon process by sending SIGHUP signal to it """ try: pid = get_process_pid(self._PID_FILENAME) if pid: os.kill(pid, signal.SIGHUP) except: pass def _sighup_handler(self, signum, frame): """ SIGHUP signal handler """ # Load new user configuration from config file self._reload_config_need = True logger.info("SIGHUP: Cloudlinux AccelerateWP daemon sheduled for reload") def _sigint_handler(self, signum, frame): """ SIGINT (Ctrl-C) signal handler. For console debug """ logger.info("Ctrl-C received, exit") # Terminate main cycle self._is_terminate = True def _sigterm_handler(self, signum, frame): """ SIGTERM signal handler. Called when daemon stopping """ # Terminate main cycle self._is_terminate = True