mirror of
https://github.com/gyptazy/ProxLB.git
synced 2026-04-05 20:31:57 +02:00
Merge pull request #238 from gyptazy/feature/189-add-reload-function
feature: Add relaod (SIGHUP) function to ProxLB to reload the configuration.
This commit is contained in:
2
.changelogs/1.1.3/189_add_reload_function.yml
Normal file
2
.changelogs/1.1.3/189_add_reload_function.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
feature:
|
||||
- Add relaod (SIGHUP) function to ProxLB to reload the configuration (by @gyptazy). [#189]
|
||||
@@ -13,6 +13,7 @@ __license__ = "GPL-3.0"
|
||||
|
||||
|
||||
import logging
|
||||
import signal
|
||||
from utils.logger import SystemdLogger
|
||||
from utils.cli_parser import CliParser
|
||||
from utils.config_parser import ConfigParser
|
||||
@@ -32,6 +33,9 @@ def main():
|
||||
# Initialize logging handler
|
||||
logger = SystemdLogger(level=logging.INFO)
|
||||
|
||||
# Signal handler for SIGHUP
|
||||
signal.signal(signal.SIGHUP, Helper.handler_sighup)
|
||||
|
||||
# Parses arguments passed from the CLI
|
||||
cli_parser = CliParser()
|
||||
cli_args = cli_parser.parse_args()
|
||||
@@ -51,6 +55,15 @@ def main():
|
||||
proxlb_config["proxmox_api"]["pass"] = "********"
|
||||
|
||||
while True:
|
||||
|
||||
# Validate if reload signal was sent during runtime
|
||||
# and reload the ProxLB configuration and adjust log level
|
||||
if Helper.proxlb_reload:
|
||||
logger.info("Reloading ProxLB configuration.")
|
||||
proxlb_config = config_parser.get_config()
|
||||
logger.set_log_level(proxlb_config.get('service', {}).get('log_level', 'INFO'))
|
||||
Helper.proxlb_reload = False
|
||||
|
||||
# Get all required objects from the Proxmox cluster
|
||||
meta = {"meta": proxlb_config}
|
||||
nodes = Nodes.get_nodes(proxmox_api, proxlb_config)
|
||||
|
||||
@@ -40,6 +40,8 @@ class Helper:
|
||||
get_daemon_mode(proxlb_config: Dict[str, Any]) -> None:
|
||||
Checks if the daemon mode is active and handles the scheduling accordingly.
|
||||
"""
|
||||
proxlb_reload = False
|
||||
|
||||
def __init__(self):
|
||||
"""
|
||||
Initializes the general Helper clas.
|
||||
@@ -162,3 +164,21 @@ class Helper:
|
||||
print(json.dumps(filtered_data, indent=4))
|
||||
|
||||
logger.debug("Finished: print_json.")
|
||||
|
||||
@staticmethod
|
||||
def handler_sighup(signum, frame):
|
||||
"""
|
||||
Signal handler for SIGHUP.
|
||||
|
||||
This method is triggered when the process receives a SIGHUP signal.
|
||||
It sets the `proxlb_reload` class variable to True to indicate that
|
||||
configuration should be reloaded in the main loop.
|
||||
|
||||
Args:
|
||||
signum (int): The signal number (expected to be signal.SIGHUP).
|
||||
frame (frame object): Current stack frame (unused but required by signal handler signature).
|
||||
"""
|
||||
logger.debug("Starting: handle_sighup.")
|
||||
logger.debug("Got SIGHUP signal. Reloading...")
|
||||
Helper.proxlb_reload = True
|
||||
logger.debug("Starting: handle_sighup.")
|
||||
|
||||
Reference in New Issue
Block a user