Skip to content

Commit 3df4f96

Browse files
committed
fix(ns-ha): selective stop services
Just stop only services that should not run on backup node. Previously the script was stopping also services that need to be running like the firewall.
1 parent ce7b117 commit 3df4f96

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/ns-ha/files/ns-ha-disable

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ def disable_hotspot():
6464
logger.info("Restored original mac address on device %s to %s: %s", device.get('name'), original_mac, "success" if proc.returncode == 0 else "fail")
6565

6666
def stop_services():
67+
# Force stop of services managed by keepalived on backup node:
68+
# it seems the sh code is not very reliable
6769
services = set()
68-
exceptions = {'nginx', 'dropbear', 'rpcd'}
6970
hotplug_dir = "/etc/hotplug.d/keepalived"
7071
try:
7172
for fname in sorted(os.listdir(hotplug_dir)):
@@ -74,10 +75,15 @@ def stop_services():
7475
continue
7576
try:
7677
with open(path, 'r') as fh:
77-
for line in fh:
78+
content = fh.read()
79+
# Only consider this file if it contains the marker to stop services on backup
80+
if 'set_stop_if_backup' not in content:
81+
continue
82+
83+
for line in content.splitlines():
7884
# match: set_service_name <name> (allow optional quotes)
79-
m = re.search(r'\bset_service_name\s+([\'"]?)([A-Za-z0-9._-]+)\1', line)
80-
if m and m.group(2) not in exceptions:
85+
m = re.search(r'\bset_service_name\s+([\'\"]?)([A-Za-z0-9._-]+)\1', line)
86+
if m:
8187
services.add(m.group(2))
8288
except Exception:
8389
# ignore unreadable files

0 commit comments

Comments
 (0)