From d18160c46c9bf1c47a623a2bd9cbde8db60c0a3c Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Mon, 16 Aug 2021 18:56:17 +0530 Subject: [PATCH] disabled buffering in python Buffering makes the systemd journal not show the logs at the right time. And changed the systemd service file so that the new batman and bridge interfaces are deleted when naxalnet.service is stopped. Also simplified the Stopping section in the README because of this change. --- Makefile | 2 +- README.md | 5 ++--- naxalnet.service | 23 ++++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 252c231..e65d74d 100644 --- a/Makefile +++ b/Makefile @@ -19,4 +19,4 @@ uninstall: clean: - rm -rf build naxalnet.egg-info + rm -rf build naxalnet.egg-info **/__pycache__ diff --git a/README.md b/README.md index b91555d..5d306cf 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ with anyone currently at risk of death in overcrowded prisons. - two or more computers, or laptops with WiFi adapter, called nodes - systemd-resolved (optional, for DNS) - batctl (optional, for debugging) +- python pip (optional, for uninstalling) ## Installing @@ -112,6 +113,7 @@ To start naxalnet, do the command on all the nodes: sudo systemctl start naxalnet.service ``` +This will start a mesh network and connect to all nodes. To test if it works, run `sudo batctl n -w` and check for nodes. If there are any nodes, your network is up. @@ -152,10 +154,7 @@ sudo systemctl disable naxalnet.service ### Stopping the service ```sh -# Stop the services sudo systemctl stop naxalnet systemd-networkd systemd-resolved iwd -# Delete the virtual interfaces created by naxalnet -sudo networkctl delete bat0 bridge0 ``` If your distribution uses NetworkManager, starting `naxalnet.service` diff --git a/naxalnet.service b/naxalnet.service index fae1a57..411374e 100644 --- a/naxalnet.service +++ b/naxalnet.service @@ -1,16 +1,11 @@ -# naxalnet systemd service +# The naxalnet systemd service # See man:systemd.service(5) and man:systemd.unit(5) # before editing this file. [Unit] -Description=Naxalnet +Description=Setup mesh networks Requires=systemd-networkd.service Requires=iwd.service Wants=systemd-resolved.service -# naxalnet does not reload networkd, so networkd -# should be started only afer naxalnet exits. -# This should be changed when naxalnet becomes -# a daemon. -Before=systemd-networkd.service After=iwd.service # Stops NetworkManager and wpa_supplicant if already running Conflicts=NetworkManager.service @@ -22,16 +17,22 @@ After=wpa_supplicant.service Type=oneshot RemainAfterExit=yes Restart=on-failure -# Probably not needed now RestartSec=2sec # IWD takes some time to find devices. # If naxalnet is run before iwd finds devices, -# naxalnet cannot start a mesh network. -# Without the delay, naxalnet could not detect the second -# device while testing. +# naxalnet cannot start a mesh network but exits without errors. # TODO: Remove this line when naxalnet becomes a daemon. ExecStartPre=/usr/bin/sleep 2 ExecStart=/usr/bin/naxalnet +# Reload systemd-networkd after naxalnet exits +ExecStartPost=/usr/bin/systemctl reload-or-restart systemd-networkd.service +# Delete the interfaces created +ExecStopPost=/usr/bin/networkctl delete bridge0 bat0 +# Make python flush messages the moment print() is called. +# Without this env variable, python stores output in a +# buffer before flushing to stdout. But this is not needed +# when naxalnet runs as a systemd service. +Environment=PYTHONUNBUFFERED=1 [Install] WantedBy=multi-user.target