From patchwork Wed Mar 30 09:56:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 5414 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KT2034rVjz3wf7 for ; Wed, 30 Mar 2022 09:56:51 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KT1zy2q8yz3vv; Wed, 30 Mar 2022 09:56:46 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KT1zy1ssYz2yr2; Wed, 30 Mar 2022 09:56:46 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KT1zw4G4mz2y0B for ; Wed, 30 Mar 2022 09:56:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4KT1zv580Hz39V; Wed, 30 Mar 2022 09:56:43 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1648634203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hawIf6nZ1XIeqwg4aT1ilIpV1RFZZ8WQ+Qs1WZKYJqc=; b=XGs7Zjmd9/jbMIG/k2+jiy/yPn3Vwhymd0wd8mZH7Ona4kKw9tLfS5nqA+B3bCkuc5EE9+ 6zcCQrpcG04h2pDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1648634203; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=hawIf6nZ1XIeqwg4aT1ilIpV1RFZZ8WQ+Qs1WZKYJqc=; b=wqh3RyWBj7TwecxNTNJnzEjen0ZZ2wYn941xarj4o9d10oH8RQ9RhzzLzLqu5tqWaCdHAA n/RMFcgd9r45YPjmiPkNgvXpHZrFLvZBC6KxxWPMdtZ/t8+JC+SG8wBFwt0DZSXERdC67i d0Wudak0ZYcVwVEvjspju5Zk0vc88C+bemSR0Cv7ZLrHvsQnpWf5cA9TwwysKdkoEDFH9V F0Od9Rr3Kj1gR9jUUKVFP7mgzCvc3v3Aq0bZhm9g8X9KydcfmHoEByEbLeGegHxP283sZN XTZkS8zDylr/MHdV2gDWnjppg/EERPDp3KPfCFNBtFJKSb6TXh7lw7JALB0+og== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH v2 1/5] unbound-dhcp-leases-bridge: Improve logging Date: Wed, 30 Mar 2022 09:56:31 +0000 Message-Id: <20220330095635.621181-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This improves logging and enables logging to the console. Suggested-by: Anthony Heading Signed-off-by: Michael Tremer --- config/unbound/unbound-dhcp-leases-bridge | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge index a2df5f101..ce0cb8614 100644 --- a/config/unbound/unbound-dhcp-leases-bridge +++ b/config/unbound/unbound-dhcp-leases-bridge @@ -30,27 +30,37 @@ import re import signal import stat import subprocess +import sys import tempfile import inotify.adapters LOCAL_TTL = 60 -def setup_logging(loglevel=logging.INFO): - log = logging.getLogger("dhcp") +log = logging.getLogger("dhcp") +log.setLevel(logging.DEBUG) + +def setup_logging(daemon=True, loglevel=logging.INFO): log.setLevel(loglevel) + # Log to syslog by default handler = logging.handlers.SysLogHandler(address="/dev/log", facility="daemon") - handler.setLevel(loglevel) + log.addHandler(handler) + # Format everything formatter = logging.Formatter("%(name)s[%(process)d]: %(message)s") handler.setFormatter(formatter) - log.addHandler(handler) + handler.setLevel(loglevel) - return log + # If we are running in foreground, we should write everything to the console, too + if not daemon: + handler = logging.StreamHandler() + log.addHandler(handler) -log = logging.getLogger("dhcp") + handler.setLevel(loglevel) + + return log def ip_address_to_reverse_pointer(address): parts = address.split(".") @@ -579,12 +589,12 @@ if __name__ == "__main__": elif args.verbose >= 2: loglevel = logging.DEBUG - setup_logging(loglevel) + setup_logging(daemon=args.daemon, loglevel=loglevel) bridge = UnboundDHCPLeasesBridge(args.dhcp_leases, args.fix_leases, args.unbound_leases, args.hosts) - ctx = daemon.DaemonContext(detach_process=args.daemon) + ctx = daemon.DaemonContext(detach_process=args.daemon, stderr=sys.stderr) ctx.signal_map = { signal.SIGHUP : bridge.update_dhcp_leases, signal.SIGTERM : bridge.terminate, From patchwork Wed Mar 30 09:56:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 5415 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KT20350Zkz3wfF for ; Wed, 30 Mar 2022 09:56:51 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KT1zy6khsz4lQ; Wed, 30 Mar 2022 09:56:46 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KT1zy2ZrWz2ysF; Wed, 30 Mar 2022 09:56:46 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KT1zx0H2Rz2y0B for ; Wed, 30 Mar 2022 09:56:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4KT1zw3nwMznF; Wed, 30 Mar 2022 09:56:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1648634204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3uEdpjMXlQ+xrU/s8pPFmgQUSXQaGOLimIpD7xWQgkA=; b=qwIsrej/QJlKt92ll1F0/ujv2JShiv+l0nMV9oauf8rbO4unhUzGiQ6JXqVk1P55qmr4ZX WzkofZlarfsSXj/zbKyBKSpWCpv7dpfVc8ACMYzw/ukLoTk+ePqrPN3vN7zTUE63oYgneC bswgZJjC4sLOkRxD1xa3xkEox9DgJ2X0TD2/Y+hCcygN383TmNrLMZR4+wzWdaXgALwBI/ IDUZfflb2sBixIErXv6AYsSsewbVGK5UMZ5CNBhYc8CDuI2ED141vAihmHUiIGanHcml51 MWFEXJp4OuAaUarx+/oHu/N2SgXQsG6i4R8PEM36N05Qdyxm0loAIhiZK0PT2w== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1648634204; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3uEdpjMXlQ+xrU/s8pPFmgQUSXQaGOLimIpD7xWQgkA=; b=/vGJWXoRaH48cp3mXYAygz8UIuqsKo/TliN/xLLUgBZEAGtVJB6JKmrc66cuHfxEHovezY rE3ycb2wfaqt+6Ag== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH v2 2/5] unbound-dhcp-leases-bridge: Fix inotify handling Date: Wed, 30 Mar 2022 09:56:32 +0000 Message-Id: <20220330095635.621181-2-michael.tremer@ipfire.org> In-Reply-To: <20220330095635.621181-1-michael.tremer@ipfire.org> References: <20220330095635.621181-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This patch changes that the script will listen to changes to the directory instead of the file which got complicated when files got renamed. It also processes all changes at the same time and tries finding out what actions have to be performed in order to avoid unnecessary iterations. The script is also limited to process any changes only once every five seconds to keep resource usage in check on busy systems. Suggested-by: Anthony Heading Signed-off-by: Michael Tremer --- config/unbound/unbound-dhcp-leases-bridge | 70 +++++++++++++++-------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge index ce0cb8614..c0e5977bf 100644 --- a/config/unbound/unbound-dhcp-leases-bridge +++ b/config/unbound/unbound-dhcp-leases-bridge @@ -32,6 +32,7 @@ import stat import subprocess import sys import tempfile +import time import inotify.adapters @@ -82,6 +83,12 @@ class UnboundDHCPLeasesBridge(object): self.fix_leases_file = fix_leases_file self.hosts_file = hosts_file + self.watches = { + self.leases_file : inotify.constants.IN_MODIFY, + self.fix_leases_file : 0, + self.hosts_file : 0, + } + self.unbound = UnboundConfigWriter(unbound_leases_file) self.running = False @@ -89,37 +96,54 @@ class UnboundDHCPLeasesBridge(object): log.info("Unbound DHCP Leases Bridge started on %s" % self.leases_file) self.running = True - # Initial setup - self.hosts = self.read_static_hosts() - self.update_dhcp_leases() + i = inotify.adapters.Inotify() - i = inotify.adapters.Inotify([ - self.leases_file, - self.fix_leases_file, - self.hosts_file, - ]) + # Add watches for the directories of every relevant file + for f, mask in self.watches.items(): + i.add_watch( + os.path.dirname(f), + mask | inotify.constants.IN_CLOSE_WRITE | inotify.constants.IN_MOVED_TO, + ) - for event in i.event_gen(): - # End if we are requested to terminate - if not self.running: - break + # Enabled so that we update hosts and leases on startup + update_hosts = update_leases = True - if event is None: - continue + while self.running: + log.debug("Wakeup of main loop") + + # Process the entire inotify queue and identify what we need to do + for event in i.event_gen(): + # Nothing to do + if event is None: + break + + # Decode the event + header, type_names, path, filename = event - header, type_names, watch_path, filename = event + file = os.path.join(path, filename) - # Update leases after leases file has been modified - if "IN_MODIFY" in type_names: - # Reload hosts - if watch_path == self.hosts_file: - self.hosts = self.read_static_hosts() + log.debug("inotify event received for %s: %s", file, " ".join(type_names)) + # Did the hosts file change? + if self.hosts_file == file: + update_hosts = True + + # We will need to update the leases on any change + update_leases = True + + # Update hosts (if needed) + if update_hosts: + self.hosts = self.read_static_hosts() + + # Update leases (if needed) + if update_leases: self.update_dhcp_leases() - # If the file is deleted, we re-add the watcher - if "IN_IGNORED" in type_names: - i.add_watch(watch_path) + # Reset + update_hosts = update_leases = False + + # Wait a moment before we start the next iteration + time.sleep(5) log.info("Unbound DHCP Leases Bridge terminated") From patchwork Wed Mar 30 09:56:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 5417 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KT2055Jfzz3wf7 for ; Wed, 30 Mar 2022 09:56:53 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KT1zz3BxRz443; Wed, 30 Mar 2022 09:56:47 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KT1zz2zwmz2yqq; Wed, 30 Mar 2022 09:56:47 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KT1zx0rjkz2ySg for ; Wed, 30 Mar 2022 09:56:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4KT1zw71lHz443; Wed, 30 Mar 2022 09:56:44 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1648634205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O8q1ckHCjWC6Bk+aEVoQwAso+FuiY9BXGYn/PjGz2mw=; b=Y+3S//aGAXoadJ5CcZdR6Xom18A/B6BjWd7LFNnk9nf9yrmgnH/4j8PpS4b5aooi44Agc4 SnPcGychM/nWWYCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1648634205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O8q1ckHCjWC6Bk+aEVoQwAso+FuiY9BXGYn/PjGz2mw=; b=SxR0CW3d2rhQXejIqSBQhl5HpMvkr/YUY3Cg7QSYPQECDWzsWzSFLH3ZKlA0tgqBr1BYuF 5WO4sEM6U5OhBGW+bI8qSQj9cNaV9vJkLvKoou3BR4KnlaO7axieC42QJ/ylJ0HveDdZ5J hgmFu5ph2C5tPOkQvOLHJCjSbffD0eBGlWARlMVGqh+p9191s+yDBge3bloreDdJHL2uCY TOpckrqGbDBloo2ElxTzEbC6gouM4/YyChArL8lQtCT3C8lfdYidtgHLyLE4Pu7G/BqjM0 Y9omTbO1A24xk95eSwXxsaCZpgZFWIXjKEvQyk7yGWvv8WyMgzGFOiCLDPyyTQ== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH v2 3/5] unbound-dhcp-leases-bridge: Read configuration only once Date: Wed, 30 Mar 2022 09:56:33 +0000 Message-Id: <20220330095635.621181-3-michael.tremer@ipfire.org> In-Reply-To: <20220330095635.621181-1-michael.tremer@ipfire.org> References: <20220330095635.621181-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This saves some resources when we re-read the same configuration file too often. Suggested-by: Anthony Heading Signed-off-by: Michael Tremer --- config/unbound/unbound-dhcp-leases-bridge | 2 ++ 1 file changed, 2 insertions(+) diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge index c0e5977bf..b098d98b4 100644 --- a/config/unbound/unbound-dhcp-leases-bridge +++ b/config/unbound/unbound-dhcp-leases-bridge @@ -22,6 +22,7 @@ import argparse import datetime import daemon +import functools import ipaddress import logging import logging.handlers @@ -444,6 +445,7 @@ class Lease(object): return "localdomain" @staticmethod + @functools.cache def read_settings(filename): settings = {} From patchwork Wed Mar 30 09:56:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 5416 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KT2040MP3z3wfG for ; Wed, 30 Mar 2022 09:56:52 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KT1zz48P4z39V; Wed, 30 Mar 2022 09:56:47 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KT1zz3PLpz2yqs; Wed, 30 Mar 2022 09:56:47 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KT1zx1hM3z2yqs for ; Wed, 30 Mar 2022 09:56:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4KT1zx0VRfz4PH; Wed, 30 Mar 2022 09:56:45 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1648634205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BR4y16sMtm1+YZVmTnDEcSjpjgz+ePbVVoXoCRtkUF4=; b=u/m9GhgDZqpe2cX4GckKxUmEqMfPewGhUUbpAQO2o7NZbpMc3YDkUBK/MAsL3NihMzNN0l 38kkxHYCEgcKfGDA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1648634205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BR4y16sMtm1+YZVmTnDEcSjpjgz+ePbVVoXoCRtkUF4=; b=PV8RTXjWE9yZR9lQKACeh4Yr9Or9NDpfeUKqrtxHybFCiiYCOHBLPFr9BpQ8qYy33vMa4A HWvlVLubQL+FOy+rWyJ60UQV5z3vkAqp5pJ4k9fcNHzIV6pRSiojDuceq1OO1GwGfyxVcx 9dLGoMbwf12lkKYfZwlWf88cTDi2LKC8KEPfQa21ZCa+9WhXeahAarSbHYEMPquqv1lTXM U9PFfiSm6eENiwG5nwV0OJM2G2B7kRUlJeir8yCgq5N3vYO27J1mBoTKS9NiKd+ixMG4ca a5/QxpMJEmvJagwyHnWLAJES/YFrr/R/w2QggU+66QA8reW5T216m4mqgr1kmw== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH v2 4/5] unbound-dhcp-leases-bridge: Initialize logging after daemonization Date: Wed, 30 Mar 2022 09:56:34 +0000 Message-Id: <20220330095635.621181-4-michael.tremer@ipfire.org> In-Reply-To: <20220330095635.621181-1-michael.tremer@ipfire.org> References: <20220330095635.621181-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Michael Tremer --- config/unbound/unbound-dhcp-leases-bridge | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge index b098d98b4..50a0e516a 100644 --- a/config/unbound/unbound-dhcp-leases-bridge +++ b/config/unbound/unbound-dhcp-leases-bridge @@ -615,8 +615,6 @@ if __name__ == "__main__": elif args.verbose >= 2: loglevel = logging.DEBUG - setup_logging(daemon=args.daemon, loglevel=loglevel) - bridge = UnboundDHCPLeasesBridge(args.dhcp_leases, args.fix_leases, args.unbound_leases, args.hosts) @@ -627,4 +625,6 @@ if __name__ == "__main__": } with ctx: + setup_logging(daemon=args.daemon, loglevel=loglevel) + bridge.run() From patchwork Wed Mar 30 09:56:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tremer X-Patchwork-Id: 5418 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4KT2063VSDz3wfF for ; Wed, 30 Mar 2022 09:56:54 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4KT2001Sh8znF; Wed, 30 Mar 2022 09:56:48 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4KT1zz3rnxz2yxm; Wed, 30 Mar 2022 09:56:47 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4KT1zx2F4bz2ySg for ; Wed, 30 Mar 2022 09:56:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4KT1zx1MkYz4YQ; Wed, 30 Mar 2022 09:56:45 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1648634205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w+sER8ZrGVEQ031e8rfKj0ZS8vk5rFXTU/xgfQ3zT/Y=; b=fKzYjNoOX2Xh/Q2yHQjhlQxmwBAxLxrUGqFFszdUgcoh39OtfR3OTL+TUjrWpbPDvp6+ms VQsx9GRmJZRlTcCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1648634205; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=w+sER8ZrGVEQ031e8rfKj0ZS8vk5rFXTU/xgfQ3zT/Y=; b=pEARISwAlEty23ImBrOu+W816tWDOOvNHXDfwYoiRDYzGbVxeDwTCLwVEJCl3Y/rtK3og2 81tK9Wa40w3THgdFMLyKTnwrq2qRwHOwOqEFZE7JQhcNuUFpcK/sE8XE78/H0VBFoyt3XC U48I8fzafvc+T+tLn9RMXhaptgt2F773ECofNrilHgdgMoag4CVzjmNfkbFGUX5tVZ4sDk yMBi1KE82nVODaHmkVtkPGKahINqsyPfPnnmpAGD9nujEjmvf91AusKRLVRFkIVsPnbiUe asGNL4b442GFZpzC63AIO/CYe1GPIDwE3aOmoDSpEnx/dyawfqyzLC8uogQPXg== From: Michael Tremer To: development@lists.ipfire.org Subject: [PATCH v2 5/5] unbound-dhcp-leases-bridge: Don't open stderr on daemonization Date: Wed, 30 Mar 2022 09:56:35 +0000 Message-Id: <20220330095635.621181-5-michael.tremer@ipfire.org> In-Reply-To: <20220330095635.621181-1-michael.tremer@ipfire.org> References: <20220330095635.621181-1-michael.tremer@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Tremer Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Michael Tremer --- config/unbound/unbound-dhcp-leases-bridge | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/config/unbound/unbound-dhcp-leases-bridge b/config/unbound/unbound-dhcp-leases-bridge index 50a0e516a..1446c88df 100644 --- a/config/unbound/unbound-dhcp-leases-bridge +++ b/config/unbound/unbound-dhcp-leases-bridge @@ -618,13 +618,14 @@ if __name__ == "__main__": bridge = UnboundDHCPLeasesBridge(args.dhcp_leases, args.fix_leases, args.unbound_leases, args.hosts) - ctx = daemon.DaemonContext(detach_process=args.daemon, stderr=sys.stderr) - ctx.signal_map = { - signal.SIGHUP : bridge.update_dhcp_leases, - signal.SIGTERM : bridge.terminate, - } - - with ctx: + with daemon.DaemonContext( + detach_process=args.daemon, + stderr=None if args.daemon else sys.stderr, + signal_map = { + signal.SIGHUP : bridge.update_dhcp_leases, + signal.SIGTERM : bridge.terminate, + }, + ) as daemon: setup_logging(daemon=args.daemon, loglevel=loglevel) bridge.run()