From patchwork Sun Mar 23 10:27:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Abramov X-Patchwork-Id: 40721 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 2CAA827BBEA; Sun, 23 Mar 2025 10:29:34 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 808F527BBE2 for ; Sun, 23 Mar 2025 10:29:33 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1twIZo-0001v2-J9; Sun, 23 Mar 2025 06:29:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1twIZm-0001ua-Gc for guix-patches@gnu.org; Sun, 23 Mar 2025 06:29:06 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1twIZl-0004bt-V5; Sun, 23 Mar 2025 06:29:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=OyVxftuJNPPzHK8koGrsEswJC3AxUPBzDIuVjCUfBkU=; b=JEwIrvI1zOTUpiCgQ7ui2xeuyEWzLgn1Vrtdl825ke7OQ+ayFnfGQ0hKSF1YfTel/4EhV3HAUUE/rLiLHkp7fgy/YxYPBfjfddXetxhR7NePeu28+8TZnS453WYfGmiZi5P8Up8oCo3sU+Ip8AY2gmRmgVyuO3EVQDaY3mmMK88UffidlD4FPlTFrJCwDQSLPZeVl7+lDidzBoelQ+ZiLKWoILRF0gSgZ0ah1RAuwNbQJlvcePuIlPScCIZJ/rhXP7kTlGhfcgyQvBcHaVRT8Ez7OuhE3lPNatP25FmZCBI5pFrtlz8SFOMXum+zVE4xPh6+Y6BoawMJxlrCYKfu6g==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1twIZl-0006MC-Ow; Sun, 23 Mar 2025 06:29:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77204] [PATCH 3/3] services: dnsmasq: Provide stats and reload actions. Resent-From: Alexey Abramov Original-Sender: "Debbugs-submit" Resent-CC: ludo@gnu.org, maxim.cournoyer@gmail.com, guix-patches@gnu.org Resent-Date: Sun, 23 Mar 2025 10:29:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77204 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77204@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer X-Debbugs-Original-Xcc: Ludovic =?utf-8?q?Court=C3=A8s?= , Maxim Cournoyer Received: via spool by 77204-submit@debbugs.gnu.org id=B77204.174272570024092 (code B ref 77204); Sun, 23 Mar 2025 10:29:05 +0000 Received: (at 77204) by debbugs.gnu.org; 23 Mar 2025 10:28:20 +0000 Received: from localhost ([127.0.0.1]:47818 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1twIZ1-0006GN-HB for submit@debbugs.gnu.org; Sun, 23 Mar 2025 06:28:20 -0400 Received: from mail.mmer.org ([178.22.65.174]:52648) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1twIYq-0006Dx-1U for 77204@debbugs.gnu.org; Sun, 23 Mar 2025 06:28:12 -0400 Received: from mail.mmer.org (localhost [127.0.0.1]) by mail.mmer.org (OpenSMTPD) with ESMTP id a7476dc5 for <77204@debbugs.gnu.org>; Sun, 23 Mar 2025 10:27:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=mmer.org; h=from:to :subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=dkim; bh=9QW5hBEOsyjJQR9wIafBpV6R6 VdGlnwwVOxlf+Sk1R8=; b=N5HqafytSVTXIsB+n30okupWVcn8tyUeNxP14PYfC QQQpAb+tC6azCP5JTWY+yMDBtYiWwFy12vdFb1ReJpHmbxpXv65Y7xWfglh9rPKE VXJy/p+l8q4fRg9SoWqeFFSBnxTnAGOYpbrlnN9rW5uGTjhbj73s98nk/SC8bFfj yQ= Received: from delta (16-254-250-62.ftth.glasoperator.nl [62.250.254.16]) by mail.mmer.org (OpenSMTPD) with ESMTPSA id ec96279c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for <77204@debbugs.gnu.org>; Sun, 23 Mar 2025 10:27:54 +0000 (UTC) Date: Sun, 23 Mar 2025 11:27:52 +0100 Message-ID: <2769b5461f5882a9429042aa5650ba1a982fdfff.1742725327.git.levenson@mmer.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Alexey Abramov X-ACL-Warn: , Alexey Abramov via Guix-patches X-Patchwork-Original-From: Alexey Abramov via Guix-patches via From: Alexey Abramov Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * gnu/services/dns.scm (dnsmasq-service-reload-action) (dnsmasq-service-stats-action): New functions. * doc/guix.texi: Document the change. * gnu/tests/networking.scm: Add tests. --- doc/guix.texi | 10 ++++ gnu/services/dns.scm | 22 +++++++++ gnu/tests/networking.scm | 98 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index a6996e30358..1583ad36c89 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -35165,6 +35165,16 @@ DNS Services @end lisp @end defvar +@code{dnsmasq-service-type} also provides few helpful actions which are +@code{reload} and @code{stats}. For example: + +@example +herd stats dnsmasq +@end example + +Will ask @command{dnsmasq} service to dump its statistics to the system log, which +is usually @file{/var/log/messages}. + @deftp {Data Type} dnsmasq-configuration Data type representing the configuration of dnsmasq. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index 6e2ec7c2067..a091dbfb86c 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -860,6 +860,8 @@ (define (dnsmasq-shepherd-service config) (provision shepherd-provision) (requirement shepherd-requirement) (documentation "Run the dnsmasq DNS server.") + (actions (list (dnsmasq-service-reload-action config) + (dnsmasq-service-stats-action config))) (start #~(make-forkexec-constructor (list #$(file-append package "/sbin/dnsmasq") @@ -951,6 +953,26 @@ (define (dnsmasq-activation config) ;; create directory to store dnsmasq lease file (mkdir-p "/var/lib/misc"))) +(define (dnsmasq-service-reload-action config) + (match-record config () + (shepherd-action + (name 'reload) + (documentation "Send a SIGHUP signal to re-load /etc/hosts and /etc/ethers and any +file given by --dhcp-hostsfile, --dhcp-hostsdir, --dhcp-optsfile, --dhcp-optsdir, +--addn-hosts or --hostsdir. SIGHUP does NOT re-read the configuration file.") + (procedure #~(lambda (running) + (let ((pid (process-id running))) + (kill pid SIGHUP))))))) + +(define (dnsmasq-service-stats-action config) + (match-record config () + (shepherd-action + (name 'stats) + (documentation "Send a SIGUSR1 to write statistics to the system log.") + (procedure #~(lambda (running) + (let ((pid (process-id running))) + (kill pid SIGUSR1))))))) + (define dnsmasq-service-type (service-type (name 'dnsmasq) diff --git a/gnu/tests/networking.scm b/gnu/tests/networking.scm index 7d54ebba50e..fdc515ceb04 100644 --- a/gnu/tests/networking.scm +++ b/gnu/tests/networking.scm @@ -27,6 +27,7 @@ (define-module (gnu tests networking) #:use-module (gnu system vm) #:use-module (gnu services) #:use-module (gnu services base) + #:use-module (gnu services dns) #:use-module (gnu services networking) #:use-module (guix gexp) #:use-module (guix store) @@ -46,6 +47,7 @@ (define-module (gnu tests networking) %test-openvswitch %test-dhcpd %test-dhcpcd + %test-dnsmasq %test-tor %test-iptables %test-ipfs)) @@ -675,6 +677,102 @@ (define %test-dhcpd (description "Test a running DHCP daemon configuration.") (value (run-dhcpd-test)))) + + +;;; +;;; dnsmasq tests +;;; + + +(define dnsmasq-os-configuration + (dnsmasq-configuration)) + +(define %dnsmasq-os + (simple-operating-system + (service dhcp-client-service-type) + (service dnsmasq-service-type + (dnsmasq-configuration + (extra-options + (list "--log-facility=/tmp/dnsmasq.log")))))) + + +(define (run-dnsmasq-test) + (define os + (marionette-operating-system %dnsmasq-os + #:imported-modules '((gnu services herd)))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-64)) + + (define marionette + (make-marionette (list #$(virtual-machine os)))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "dnsmasq") + + (test-assert "dnsmasq is alive" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (wait-for-service 'dnsmasq)) + marionette)) + + (test-assert "pid file exists" + (wait-for-file + '#$(dnsmasq-configuration-pid-file dnsmasq-os-configuration) + marionette)) + + (test-assert "send SIGHUP" + (positive? + (marionette-eval + '(begin + (use-modules (ice-9 rdelim)) + (system* "sync") + (let* ((port (open-input-file "/tmp/dnsmasq.log"))) + (seek port 0 SEEK_END) + (system* "herd" "reload" "dnsmasq") + (system* "sync") + (let ((line (read-line port))) + (close-port port) + (string-contains line "read /etc/hosts")))) + marionette))) + + (test-assert "send SIGUSR1" + (positive? + (marionette-eval + '(begin + (use-modules (ice-9 rdelim)) + (system* "sync") + (let* ((port (open-input-file "/tmp/dnsmasq.log"))) + (seek port 0 SEEK_END) + (system* "herd" "stats" "dnsmasq") + (system* "sync") + (let ((line (read-line port))) + (close-port port) + (string-contains-ci line "time")))) + marionette))) + + (test-assert "dnsmasq is alive" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (wait-for-service 'dnsmasq)) + marionette)) + + (test-end)))) + + (gexp->derivation "dnsmasq-test" test)) + +(define %test-dnsmasq + (system-test + (name "dnsmasq") + (description "Test a running dnsmasq daemon configuration.") + (value (run-dnsmasq-test)))) + + ;;; ;;; DHCPCD Daemon