From 9e9606b8cf8fd49b072384b524bb639aa6c36312 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sun, 5 Dec 2021 16:05:43 +0100 Subject: [PATCH] Systemd service support and documentation update --- RNS/Reticulum.py | 7 +++ RNS/Utilities/rnsd.py | 17 ++++-- docs/manual/_sources/using.rst.txt | 93 +++++++++++++++++++++++++++++- docs/manual/index.html | 5 ++ docs/manual/searchindex.js | 2 +- docs/manual/using.html | 78 +++++++++++++++++++++++++ docs/source/using.rst | 93 +++++++++++++++++++++++++++++- 7 files changed, 288 insertions(+), 7 deletions(-) mode change 100644 => 100755 RNS/Utilities/rnsd.py diff --git a/RNS/Reticulum.py b/RNS/Reticulum.py index 2723077..64300c6 100755 --- a/RNS/Reticulum.py +++ b/RNS/Reticulum.py @@ -101,6 +101,12 @@ class Reticulum: RNS.exit() + @staticmethod + def sigterm_handler(signal, frame): + RNS.Transport.detach_interfaces() + RNS.exit() + + def __init__(self,configdir=None, loglevel=None): """ Initialises and starts a Reticulum instance. This must be @@ -182,6 +188,7 @@ class Reticulum: atexit.register(Reticulum.exit_handler) signal.signal(signal.SIGINT, Reticulum.sigint_handler) + signal.signal(signal.SIGTERM, Reticulum.sigterm_handler) def __start_local_interface(self): if self.share_instance: diff --git a/RNS/Utilities/rnsd.py b/RNS/Utilities/rnsd.py old mode 100644 new mode 100755 index 383b56b..173ab42 --- a/RNS/Utilities/rnsd.py +++ b/RNS/Utilities/rnsd.py @@ -2,15 +2,23 @@ import RNS import argparse +import time from RNS._version import __version__ -def program_setup(configdir, verbosity = 0, quietness = 0): - reticulum = RNS.Reticulum(configdir = configdir, loglevel = 3+verbosity-quietness) +def program_setup(configdir, verbosity = 0, quietness = 0, service = False): + targetloglevel = 3+verbosity-quietness + + if service: + RNS.logdest = RNS.LOG_FILE + RNS.logfile = RNS.Reticulum.configdir+"/logfile" + targetloglevel = None + + reticulum = RNS.Reticulum(configdir=configdir, loglevel=targetloglevel) RNS.log("Started rnsd version {version}".format(version=__version__), RNS.LOG_NOTICE) while True: - input() + time.sleep(1) def main(): try: @@ -18,6 +26,7 @@ def main(): parser.add_argument("--config", action="store", default=None, help="path to alternative Reticulum config directory", type=str) parser.add_argument('-v', '--verbose', action='count', default=0) parser.add_argument('-q', '--quiet', action='count', default=0) + parser.add_argument('-s', '--service', action='store_true', default=False, help="rnsd is running as a service and should log to file") parser.add_argument("--version", action="version", version="rnsd {version}".format(version=__version__)) args = parser.parse_args() @@ -27,7 +36,7 @@ def main(): else: configarg = None - program_setup(configdir = configarg, verbosity=args.verbose, quietness=args.quiet) + program_setup(configdir = configarg, verbosity=args.verbose, quietness=args.quiet, service=args.service) except KeyboardInterrupt: print("") diff --git a/docs/manual/_sources/using.rst.txt b/docs/manual/_sources/using.rst.txt index 8a1e66a..946ff67 100644 --- a/docs/manual/_sources/using.rst.txt +++ b/docs/manual/_sources/using.rst.txt @@ -162,4 +162,95 @@ destinations will not have this option enabled, and will not be probable. -h, --help show this help message and exit --config CONFIG path to alternative Reticulum config directory --version show program's version number and exit - -v, --verbose \ No newline at end of file + -v, --verbose + + +Improving System Configuration +------------------------------ + +If you are setting up a system for permanent use with Reticulum, there is a +few system configuration changes that can make this easier to administrate. +These changes will be detailed here. + + +Fixed Serial Port Names +======================= + +On a Reticulum node with several serial port based interfaces, it can be +beneficial to use the fixed name device nodes for the serial ports, instead +of the dynamically allocated shorthands such as ``/dev/ttyUSB0``. Under most +Debian-based distributions, including Ubuntu and Raspberry Pi OS, these nodes +can be found under ``/dev/serial/by-id``. + +You can use such a device path directly in place of the numbered shorthands. +Here is an example of a packet radio TNC configured as such: + +.. code:: text + + [[Packet Radio KISS Interface]] + type = KISSInterface + interface_enabled = True + outgoing = true + port = /dev/serial/by-id/usb-FTDI_FT230X_Basic_UART_43891CKM-if00-port0 + speed = 115200 + databits = 8 + parity = none + stopbits = 1 + preamble = 150 + txtail = 10 + persistence = 200 + slottime = 20 + +Using this methodology avoids potential naming mix-ups where physical devices +might be plugged and unplugged in different orders, or when node name +assignment varies from one boot to another. + + +Run Reticulum as a Service +========================== + +Instead of starting Reticulum manually, you can install ``rnsd`` as a system +service and have it start automatically at boot. + +If you installed Reticulum with ``pip``, the ``rnsd`` program will most likely +be located in a user-local installation path only, which means ``systemd`` will not +be able to execute it. In this case, you can simply symlink the ``rnsd`` program +into a directory that is in systemd's path: + +.. code:: text + + sudo ln -s $(which rnsd) /usr/local/bin/ + +You can then create the service file ``/etc/systemd/system/rnsd.service`` with the +following content: + +.. code:: text + + [Unit] + Description=Reticulum Network Stack Daemon + After=network.target + StartLimitIntervalSec=0 + + [Service] + Type=simple + Restart=always + RestartSec=3 + User=USERNAMEHERE + ExecStart=rnsd --service + + [Install] + WantedBy=multi-user.target + +Be sure to replace ``USERNAMEHERE`` with the user you want to run ``rnsd`` as. + +To manually start ``rnsd`` run: + +.. code:: text + + sudo systemctl start rnsd + +If you want to automatically start ``rnsd`` at boot, run: + +.. code:: text + + sudo systemctl enable rnsd \ No newline at end of file diff --git a/docs/manual/index.html b/docs/manual/index.html index fc692df..73cb6ad 100644 --- a/docs/manual/index.html +++ b/docs/manual/index.html @@ -68,6 +68,11 @@ to participate in the development of Reticulum itself.
If you are setting up a system for permanent use with Reticulum, there is a +few system configuration changes that can make this easier to administrate. +These changes will be detailed here.
+On a Reticulum node with several serial port based interfaces, it can be
+beneficial to use the fixed name device nodes for the serial ports, instead
+of the dynamically allocated shorthands such as /dev/ttyUSB0
. Under most
+Debian-based distributions, including Ubuntu and Raspberry Pi OS, these nodes
+can be found under /dev/serial/by-id
.
You can use such a device path directly in place of the numbered shorthands. +Here is an example of a packet radio TNC configured as such:
+[[Packet Radio KISS Interface]]
+ type = KISSInterface
+ interface_enabled = True
+ outgoing = true
+ port = /dev/serial/by-id/usb-FTDI_FT230X_Basic_UART_43891CKM-if00-port0
+ speed = 115200
+ databits = 8
+ parity = none
+ stopbits = 1
+ preamble = 150
+ txtail = 10
+ persistence = 200
+ slottime = 20
+
Using this methodology avoids potential naming mix-ups where physical devices +might be plugged and unplugged in different orders, or when node name +assignment varies from one boot to another.
+Instead of starting Reticulum manually, you can install rnsd
as a system
+service and have it start automatically at boot.
If you installed Reticulum with pip
, the rnsd
program will most likely
+be located in a user-local installation path only, which means systemd
will not
+be able to execute it. In this case, you can simply symlink the rnsd
program
+into a directory that is in systemd’s path:
sudo ln -s $(which rnsd) /usr/local/bin/
+
You can then create the service file /etc/systemd/system/rnsd.service
with the
+following content:
[Unit]
+Description=Reticulum Network Stack Daemon
+After=network.target
+StartLimitIntervalSec=0
+
+[Service]
+Type=simple
+Restart=always
+RestartSec=3
+User=USERNAMEHERE
+ExecStart=rnsd --service
+
+[Install]
+WantedBy=multi-user.target
+
Be sure to replace USERNAMEHERE
with the user you want to run rnsd
as.
To manually start rnsd
run:
sudo systemctl start rnsd
+
If you want to automatically start rnsd
at boot, run:
sudo systemctl enable rnsd
+