From 669ce20a844d6f871f0ec7773f26573b0d0b4050 Mon Sep 17 00:00:00 2001 From: jokob-sk Date: Fri, 4 Oct 2024 11:25:54 +1000 Subject: [PATCH] AVAHISCAN / mDNS #815 --- front/plugins/avahi_scan/avahi_scan.py | 29 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/front/plugins/avahi_scan/avahi_scan.py b/front/plugins/avahi_scan/avahi_scan.py index d7bb5c55..e50db705 100755 --- a/front/plugins/avahi_scan/avahi_scan.py +++ b/front/plugins/avahi_scan/avahi_scan.py @@ -41,8 +41,7 @@ def main(): # timeout = get_setting_value('AVAHI_RUN_TIMEOUT') timeout = 20 - # ensure service is running - ensure_avahi_running() + # Create a database connection db = DB() # instance of class DB @@ -65,6 +64,10 @@ def main(): # ] mylog('verbose', [f'[{pluginName}] Unknown devices count: {len(unknown_devices)}']) + + if len(unknown_devices) > 0: + # ensure service is running + ensure_avahi_running() for device in unknown_devices: domain_name = execute_name_lookup(device['dev_LastIP'], timeout) @@ -152,15 +155,15 @@ def ensure_avahi_running(): # except subprocess.CalledProcessError as e: # mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to install D-Bus: {e.output}']) # return - - # Start the D-Bus service + + # Check rc-status try: - subprocess.run(['rc-service', 'dbus', 'start'], check=True) + subprocess.run(['rc-status'], check=True) except subprocess.CalledProcessError as e: - mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to start D-Bus: {e.output}']) - return - - # Create OpenRC soft level if needed + mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to check rc-status: {e.output}']) + return + + # Create OpenRC soft level subprocess.run(['touch', '/run/openrc/softlevel'], check=True) # Add Avahi daemon to runlevel @@ -169,6 +172,13 @@ def ensure_avahi_running(): except subprocess.CalledProcessError as e: mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to add Avahi to runlevel: {e.output}']) return + + # Start the D-Bus service + try: + subprocess.run(['rc-service', 'dbus', 'start'], check=True) + except subprocess.CalledProcessError as e: + mylog('verbose', [f'[{pluginName}] ⚠ ERROR - Failed to start D-Bus: {e.output}']) + return # Start the Avahi daemon try: @@ -180,6 +190,7 @@ def ensure_avahi_running(): # Check status status_output = subprocess.run(['rc-service', 'avahi-daemon', 'status'], capture_output=True, text=True) mylog('verbose', [f'[{pluginName}] Avahi Daemon Status: {status_output.stdout.strip()}']) + if __name__ == '__main__': main()