|
|
@@ -67,6 +67,7 @@ config = None
|
|
|
def setup_systemd_watchdog():
|
|
|
"""Setup systemd watchdog notifications"""
|
|
|
import os
|
|
|
+ import shutil
|
|
|
|
|
|
# Check if we have systemd watchdog enabled
|
|
|
watchdog_usec = os.environ.get('WATCHDOG_USEC')
|
|
|
@@ -74,6 +75,11 @@ def setup_systemd_watchdog():
|
|
|
logger.info("Systemd watchdog not enabled")
|
|
|
return False
|
|
|
|
|
|
+ # Check if systemd-notify command exists
|
|
|
+ if not shutil.which('systemd-notify'):
|
|
|
+ logger.warning("systemd-notify command not found, watchdog disabled")
|
|
|
+ return False
|
|
|
+
|
|
|
try:
|
|
|
# Convert microseconds to seconds and send notifications at half the interval
|
|
|
interval = int(watchdog_usec) / 2000000 # Half interval in seconds
|
|
|
@@ -82,9 +88,14 @@ def setup_systemd_watchdog():
|
|
|
def watchdog_ping():
|
|
|
while True:
|
|
|
try:
|
|
|
- subprocess.run(['systemd-notify', 'WATCHDOG=1'],
|
|
|
- check=False, stdout=subprocess.DEVNULL,
|
|
|
- stderr=subprocess.DEVNULL, timeout=5)
|
|
|
+ result = subprocess.run(['systemd-notify', 'WATCHDOG=1'],
|
|
|
+ check=False, stdout=subprocess.DEVNULL,
|
|
|
+ stderr=subprocess.DEVNULL, timeout=5)
|
|
|
+ if result.returncode != 0:
|
|
|
+ logger.debug(f"systemd-notify returned {result.returncode}")
|
|
|
+ time.sleep(interval)
|
|
|
+ except subprocess.TimeoutExpired:
|
|
|
+ logger.warning("systemd-notify timeout")
|
|
|
time.sleep(interval)
|
|
|
except Exception as e:
|
|
|
logger.warning(f"Failed to send watchdog notification: {e}")
|
|
|
@@ -554,10 +565,19 @@ def main():
|
|
|
|
|
|
# Notify systemd that we're ready
|
|
|
try:
|
|
|
- subprocess.run(['systemd-notify', 'READY=1'],
|
|
|
- check=False, stdout=subprocess.DEVNULL,
|
|
|
- stderr=subprocess.DEVNULL, timeout=5)
|
|
|
- logger.info("Sent READY=1 to systemd")
|
|
|
+ import shutil
|
|
|
+ if shutil.which('systemd-notify'):
|
|
|
+ result = subprocess.run(['systemd-notify', 'READY=1'],
|
|
|
+ check=False, stdout=subprocess.DEVNULL,
|
|
|
+ stderr=subprocess.DEVNULL, timeout=10)
|
|
|
+ if result.returncode == 0:
|
|
|
+ logger.info("Successfully sent READY=1 to systemd")
|
|
|
+ else:
|
|
|
+ logger.warning(f"systemd-notify returned {result.returncode}")
|
|
|
+ else:
|
|
|
+ logger.info("systemd-notify not available, skipping READY notification")
|
|
|
+ except subprocess.TimeoutExpired:
|
|
|
+ logger.error("Timeout sending READY=1 to systemd")
|
|
|
except Exception as e:
|
|
|
logger.warning(f"Failed to notify systemd ready: {e}")
|
|
|
|