From 87612fac2cee2e406a3cc78a01acd1d086bb2400 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Mon, 27 Sep 2021 22:48:13 +0530 Subject: [PATCH] delete interface during cleanup Read the previous commit for some unhelpful remarks. --- naxalnet.service | 9 --------- naxalnet/__init__.py | 2 +- naxalnet/network.py | 3 ++- naxalnet/scripts.py | 7 ++++--- 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/naxalnet.service b/naxalnet.service index 340c1be..14187c5 100644 --- a/naxalnet.service +++ b/naxalnet.service @@ -23,15 +23,6 @@ Restart=on-failure RestartSec=2sec ExecStart=/usr/bin/naxalnet --systemd KillSignal=SIGINT -# Reload systemd-networkd after naxalnet signals it is ready -#ExecStartPost=/usr/bin/networkctl reload -# When naxalnet exits, delete all files starting -# with mesh.* in /run/systemd/network -#ExecStopPost=/usr/bin/find /run/systemd/network -type f -delete -name "mesh.*" -# Then delete the two interfaces created... -#ExecStopPost=/usr/bin/networkctl delete bridge0 bat0 -# ... and reload the configuration files. -#ExecStopPost=/usr/bin/networkctl reload # naxalnet already logs to systemd journal so we don't need # stdout and stderr. StandardOutput=null diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py index 0d57703..1509d4b 100644 --- a/naxalnet/__init__.py +++ b/naxalnet/__init__.py @@ -35,4 +35,4 @@ See README.md for documentation. # # In case you forgot to change the version, skip the number # and put the next number in the next commit. -__version__ = "0.4.0a5.dev3" +__version__ = "0.4.0a5.dev4" diff --git a/naxalnet/network.py b/naxalnet/network.py index 1529215..f1df64a 100644 --- a/naxalnet/network.py +++ b/naxalnet/network.py @@ -21,7 +21,7 @@ network.py This submodule manages the systemd-networkd configuration. TODO: Add more details """ - +import subprocess from pathlib import Path from dasbus.connection import SystemMessageBus @@ -71,6 +71,7 @@ class NetworkD: def delete_interface(self, name: str) -> None: """delete the given interface""" + subprocess.run(["networkctl", "delete", name], check=True) def remove_config(self, name: str) -> None: """ diff --git a/naxalnet/scripts.py b/naxalnet/scripts.py index 1aa3ea4..ed1ce02 100644 --- a/naxalnet/scripts.py +++ b/naxalnet/scripts.py @@ -188,12 +188,10 @@ def setup_devices(): sys.exit(4) -def cleanup(signal=None, frame=None): +def cleanup(): """ Remove all network config, poweroff used wireless devices and exit with 0. - - signal and frame are ununsed """ networkd = NetworkD(runtime_dir=args.networkd_runtime_dir) logger.info("Exiting gracefully") @@ -202,6 +200,8 @@ def cleanup(signal=None, frame=None): device = Device(i) device.set_mode("station") device.power_off() + networkd.delete_interface(args.batman_device) + networkd.delete_interface(args.bridge_device) def print_wifi(): @@ -263,5 +263,6 @@ def main(): notify("STATUS=Waiting for changes") daemon.start() + # systemd uses SIGINT to kill this program except KeyboardInterrupt: cleanup()