Package: guix-patches;
Reported by: Alexey Abramov <levenson <at> mmer.org>
Date: Sun, 23 Mar 2025 10:27:04 UTC
Severity: normal
Tags: patch
Done: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Bug is archived. No further changes may be made.
To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 77204 in the body.
You can then email your comments to 77204 AT debbugs.gnu.org in the normal way.
Toggle the display of automated, internal messages from the tracker.
View this report as an mbox folder, status mbox, maintainer mbox
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 10:27:04 GMT) Full text and rfc822 format available.Alexey Abramov <levenson <at> mmer.org>
:ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
.
(Sun, 23 Mar 2025 10:27:04 GMT) Full text and rfc822 format available.Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: guix-patches <at> gnu.org Subject: [PATCH 0/3] dnsmasq service changes Date: Sun, 23 Mar 2025 11:24:30 +0100
Hi all, With these patches, I would like to add extra fields to be able to run multiple instances of dnsmasq. I am using dnsmasq as a local dns server and also as a dhcp for bootstraping nodes over the network. The important thing is that I renamed `provision' field here to shepherd-provision. AFAIK `shepherd-provision' and `shepherd-requirement' are the names we use with other services. Alexey Abramov (3): services: dnsmasq: Provide shepherd-provision and shepherd-requirement fields. services: dnsmasq: Provide pid-file, conf-file and conf-dir configuration fields. services: dnsmasq: Provide stats and reload actions. doc/guix.texi | 35 ++++++- gnu/services/dns.scm | 196 ++++++++++++++++++++++++++------------- gnu/tests/networking.scm | 98 ++++++++++++++++++++ 3 files changed, 263 insertions(+), 66 deletions(-) -- 2.48.1
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 10:29:03 GMT) Full text and rfc822 format available.Message #8 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH 1/3] services: dnsmasq: Provide shepherd-provision and shepherd-requirement fields. Date: Sun, 23 Mar 2025 11:27:50 +0100
* doc/guix.texi: Document the change. * gnu/services/dns.scm (<dnsmasq-configuration>)[provision]: Rename the field to [shepherd-provision] for consistency with other services. * gnu/services/dns.scm (<dnsmasq-configuration>)[shepherd-requirement]: New field. * gnu/services/dns.scm (dnsmasq-shepherd-service): Use newly-created fields. --- doc/guix.texi | 11 ++++++++--- gnu/services/dns.scm | 12 ++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index eecc0aec52c..fd6a0176348 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -35172,9 +35172,14 @@ DNS Services @item @code{package} (default: @var{dnsmasq}) Package object of the dnsmasq server. -@item @code{provision} (default: @code{'(dnsmasq)}) -A list of symbols for the Shepherd service corresponding to this dnsmasq -configuration. +@item @code{shepherd-provision} (default: @code{'(dnsmasq)}) +@itemx @code{shepherd-requirement} (default: @code{'(user-processes networking)}) +This option can be used to provide a list of Shepherd service names +(symbols) provided by this service. You might want to change the default +value if you intend to run several @command{dnsmasq} instances. + +Likewise, @code{shepherd-requirement} is a list of Shepherd service names +(symbols) that this service will depend on. @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index 05291eb65d9..9276504ffd0 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -742,8 +742,10 @@ (define-record-type* <dnsmasq-configuration> dnsmasq-configuration? (package dnsmasq-configuration-package (default dnsmasq)) ;file-like - (provision dnsmasq-provision - (default '(dnsmasq))) + (shepherd-provision dnsmasq-configuration-shepherd-provision + (default '(dnsmasq))) + (shepherd-requirement dnsmasq-configuration-shepherd-requirement + (default '(user-processes networking))) (no-hosts? dnsmasq-configuration-no-hosts? (default #f)) ;boolean (port dnsmasq-configuration-port @@ -802,6 +804,8 @@ (define-record-type* <dnsmasq-configuration> (define (dnsmasq-shepherd-service config) (match-record config <dnsmasq-configuration> (package + shepherd-provision + shepherd-requirement no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -815,8 +819,8 @@ (define (dnsmasq-shepherd-service config) tftp-lowercase? tftp-port-range tftp-root tftp-unique-root extra-options) (shepherd-service - (provision (dnsmasq-provision config)) - (requirement '(user-processes networking)) + (provision shepherd-provision) + (requirement shepherd-requirement) (documentation "Run the dnsmasq DNS server.") (start #~(make-forkexec-constructor (list -- 2.48.1
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 10:29:04 GMT) Full text and rfc822 format available.Message #11 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH 2/3] services: dnsmasq: Provide pid-file, conf-file and conf-dir configuration fields. Date: Sun, 23 Mar 2025 11:27:51 +0100
* doc/guix.texi: Document it. * gnu/services/dns.scm: Export all record accessors. * gnu/services/dns.scm (<dnsmasq-configuration>)[pid-file]: New field. * gnu/services/dns.scm (<dnsmasq-configuration>)[conf-file]: New field. * gnu/services/dns.scm (<dnsmasq-configuration>)[conf-dir]: New field. * gnu/services/dns.scm (<dnsmasq-configuration>)[extra-options]: Move it to the end of the definition, because it is a last resort. * gnu/services/dns.scm (dnsmasq-shepherd-service): Use newly-created fields. --- doc/guix.texi | 14 ++++ gnu/services/dns.scm | 162 +++++++++++++++++++++++++++---------------- 2 files changed, 117 insertions(+), 59 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index fd6a0176348..a6996e30358 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -35181,6 +35181,9 @@ DNS Services Likewise, @code{shepherd-requirement} is a list of Shepherd service names (symbols) that this service will depend on. +@item @code{pid-file} (default: @code{"/run/dnsmasq.pid"}) +Specify an alternate path for dnsmasq to record its process-id in. + @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. @@ -35301,6 +35304,17 @@ DNS Services resolving MAC addresses is only possible if the client is in the local network or obtained a DHCP lease from dnsmasq. +@item @code{conf-file} (default: @code{'()}) +Specify a configuration file or multiple. The given value should be a list of +string paths to the configuration files. File-like objects are also supported. + +@item @code{conf-dir} (default: @code{#f}) +Read all the files in the given directory as configuration +files. @command{dnsmasq} also supports extensions for the field, but +here it is not implemented. It is more convenient to make +@code{computed-file} directory in the store and use that. Files are +loaded in alphabetical order of filename. + @item @code{extra-options} (default: @code{'()}) This option provides an ``escape hatch'' for the user to provide arbitrary command-line arguments to @command{dnsmasq} as a list of strings. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index 9276504ffd0..6e2ec7c2067 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -54,6 +54,38 @@ (define-module (gnu services dns) dnsmasq-service-type dnsmasq-configuration + dnsmasq-configuration-package + dnsmasq-configuration-shepherd-provision + dnsmasq-configuration-shepherd-requirement + dnsmasq-configuration-pid-file + dnsmasq-configuration-no-hosts? + dnsmasq-configuration-port + dnsmasq-configuration-local-service? + dnsmasq-configuration-listen-address + dnsmasq-configuration-resolv-file + dnsmasq-configuration-no-resolv? + dnsmasq-configuration-forward-private-reverse-lookup? + dnsmasq-configuration-query-servers-in-order? + dnsmasq-configuration-servers + dnsmasq-configuration-servers-file + dnsmasq-configuration-addresses + dnsmasq-configuration-cache-size + dnsmasq-configuration-negative-cache? + dnsmasq-configuration-cpe-id + dnsmasq-configuration-tftp-enable? + dnsmasq-configuration-tftp-no-fail? + dnsmasq-configuration-tftp-single-port? + dnsmasq-tftp-secure? + dnsmasq-tftp-max + dnsmasq-tftp-mtu + dnsmasq-tftp-no-blocksize? + dnsmasq-tftp-lowercase? + dnsmasq-tftp-port-range + dnsmasq-tftp-root + dnsmasq-tftp-unique-root + dnsmasq-configuration-conf-file + dnsmasq-configuration-conf-dir + dnsmasq-configuration-extra-options unbound-service-type unbound-configuration @@ -740,72 +772,77 @@ (define knot-resolver-service-type (define-record-type* <dnsmasq-configuration> dnsmasq-configuration make-dnsmasq-configuration dnsmasq-configuration? - (package dnsmasq-configuration-package - (default dnsmasq)) ;file-like + (package dnsmasq-configuration-package + (default dnsmasq)) ;file-like (shepherd-provision dnsmasq-configuration-shepherd-provision (default '(dnsmasq))) (shepherd-requirement dnsmasq-configuration-shepherd-requirement (default '(user-processes networking))) - (no-hosts? dnsmasq-configuration-no-hosts? - (default #f)) ;boolean - (port dnsmasq-configuration-port - (default 53)) ;integer - (local-service? dnsmasq-configuration-local-service? - (default #t)) ;boolean - (listen-addresses dnsmasq-configuration-listen-address - (default '())) ;list of string - (extra-options dnsmasq-configuration-extra-options - (default '())) ;list of string - (resolv-file dnsmasq-configuration-resolv-file - (default "/etc/resolv.conf")) ;string - (no-resolv? dnsmasq-configuration-no-resolv? - (default #f)) ;boolean + (pid-file dnsmasq-configuration-pid-file + (default "/run/dnsmasq.pid")) ;string + (no-hosts? dnsmasq-configuration-no-hosts? + (default #f)) ;boolean + (port dnsmasq-configuration-port + (default 53)) ;integer + (local-service? dnsmasq-configuration-local-service? + (default #t)) ;boolean + (listen-addresses dnsmasq-configuration-listen-address + (default '())) ;list of string + (resolv-file dnsmasq-configuration-resolv-file + (default "/etc/resolv.conf")) ;string + (no-resolv? dnsmasq-configuration-no-resolv? + (default #f)) ;boolean (forward-private-reverse-lookup? - dnsmasq-configuration-forward-private-reverse-lookup? - (default #t)) ;boolean - (query-servers-in-order? - dnsmasq-configuration-query-servers-in-order? - (default #f)) ;boolean - (servers dnsmasq-configuration-servers - (default '())) ;list of string - (servers-file dnsmasq-configuration-servers-file - (default #f)) ;string|file-like - (addresses dnsmasq-configuration-addresses - (default '())) ;list of string - (cache-size dnsmasq-configuration-cache-size - (default 150)) ;integer - (negative-cache? dnsmasq-configuration-negative-cache? - (default #t)) ;boolean - (cpe-id dnsmasq-configuration-cpe-id - (default #f)) ;string - (tftp-enable? dnsmasq-configuration-tftp-enable? - (default #f)) ;boolean - (tftp-no-fail? dnsmasq-configuration-tftp-no-fail? - (default #f)) ;boolean - (tftp-single-port? dnsmasq-configuration-tftp-single-port? - (default #f)) ;boolean - (tftp-secure? dnsmasq-tftp-secure? - (default #f)) ;boolean - (tftp-max dnsmasq-tftp-max - (default #f)) ;integer - (tftp-mtu dnsmasq-tftp-mtu - (default #f)) ;integer - (tftp-no-blocksize? dnsmasq-tftp-no-blocksize? - (default #f)) ;boolean - (tftp-lowercase? dnsmasq-tftp-lowercase? - (default #f)) ;boolean - (tftp-port-range dnsmasq-tftp-port-range - (default #f)) ;string - (tftp-root dnsmasq-tftp-root - (default "/var/empty,lo")) ;string - (tftp-unique-root dnsmasq-tftp-unique-root - (default #f))) ;"" or "ip" or "mac" - + dnsmasq-configuration-forward-private-reverse-lookup? + (default #t)) ;boolean + (query-servers-in-order? dnsmasq-configuration-query-servers-in-order? + (default #f)) ;boolean + (servers dnsmasq-configuration-servers + (default '())) ;list of string + (servers-file dnsmasq-configuration-servers-file + (default #f)) ;string|file-like + (addresses dnsmasq-configuration-addresses + (default '())) ;list of string + (cache-size dnsmasq-configuration-cache-size + (default 150)) ;integer + (negative-cache? dnsmasq-configuration-negative-cache? + (default #t)) ;boolean + (cpe-id dnsmasq-configuration-cpe-id + (default #f)) ;string + (tftp-enable? dnsmasq-configuration-tftp-enable? + (default #f)) ;boolean + (tftp-no-fail? dnsmasq-configuration-tftp-no-fail? + (default #f)) ;boolean + (tftp-single-port? dnsmasq-configuration-tftp-single-port? + (default #f)) ;boolean + (tftp-secure? dnsmasq-tftp-secure? + (default #f)) ;boolean + (tftp-max dnsmasq-tftp-max + (default #f)) ;integer + (tftp-mtu dnsmasq-tftp-mtu + (default #f)) ;integer + (tftp-no-blocksize? dnsmasq-tftp-no-blocksize? + (default #f)) ;boolean + (tftp-lowercase? dnsmasq-tftp-lowercase? + (default #f)) ;boolean + (tftp-port-range dnsmasq-tftp-port-range + (default #f)) ;string + (tftp-root dnsmasq-tftp-root + (default "/var/empty,lo")) ;string + (tftp-unique-root dnsmasq-tftp-unique-root + (default #f)) ;"" or "ip" or "mac" + (conf-file dnsmasq-configuration-conf-file + (default '())) ;list of string|file-like + (conf-dir dnsmasq-configuration-conf-dir + (default #f)) ;string|file-like + (extra-options dnsmasq-configuration-extra-options + (default '()))) (define (dnsmasq-shepherd-service config) (match-record config <dnsmasq-configuration> (package shepherd-provision shepherd-requirement + pid-file no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -817,7 +854,8 @@ (define (dnsmasq-shepherd-service config) tftp-single-port? tftp-secure? tftp-max tftp-mtu tftp-no-blocksize? tftp-lowercase? tftp-port-range - tftp-root tftp-unique-root extra-options) + tftp-root tftp-unique-root + conf-file conf-dir extra-options) (shepherd-service (provision shepherd-provision) (requirement shepherd-requirement) @@ -826,7 +864,7 @@ (define (dnsmasq-shepherd-service config) (list #$(file-append package "/sbin/dnsmasq") "--keep-in-foreground" - "--pid-file=/run/dnsmasq.pid" + (string-append "--pid-file=" #$pid-file) #$@(if no-hosts? '("--no-hosts") '()) @@ -897,8 +935,14 @@ (define (dnsmasq-shepherd-service config) (format #f "--tftp-unique-root=~a" tftp-unique-root) (format #f "--tftp-unique-root"))) '()) + #$@(map (lambda (conf-file) + #~(string-append "--conf-file=" #$conf-file)) + conf-file) + #$@(if conf-dir + (list #~(string-append "--conf-dir=" #$conf-dir)) + '()) #$@extra-options) - #:pid-file "/run/dnsmasq.pid")) + #:pid-file #$pid-file)) (stop #~(make-kill-destructor))))) (define (dnsmasq-activation config) -- 2.48.1
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 10:29:05 GMT) Full text and rfc822 format available.Message #14 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH 3/3] services: dnsmasq: Provide stats and reload actions. Date: Sun, 23 Mar 2025 11:27:52 +0100
* 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 <dnsmasq-configuration> () + (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 <dnsmasq-configuration> () + (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 -- 2.48.1
guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 10:51:09 GMT) Full text and rfc822 format available.Message #17 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: 45mg <45mg.writes <at> gmail.com> To: Alexey Abramov <levenson <at> mmer.org>, 77204 <at> debbugs.gnu.org Cc: Ludovic Courtès <ludo <at> gnu.org>, Maxim Cournoyer <maxim.cournoyer <at> gmail.com> Subject: Re: [bug#77204] [PATCH 1/3] services: dnsmasq: Provide shepherd-provision and shepherd-requirement fields. Date: Sun, 23 Mar 2025 10:50:47 +0000
Hi, Alexey Abramov via Guix-patches via <guix-patches <at> gnu.org> writes: > * gnu/services/dns.scm (<dnsmasq-configuration>)[provision]: Rename the field to > [shepherd-provision] for consistency with other services. If this is accepted, you'll probably need to add an entry to etc/news.scm, since it's a breaking change. You'll also need to update the Guix Cookbook. Specifically, the recent commit da090138028894c6b00c21730aa3a02cda57fb24 uses the existing 'provision' field of `dnsmasq-service-type` in an example. With that said, I think the rename is a sensible change. (Just in case it matters, I was the one who introduced the 'provision' field, as well as that Cookbook example).
guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 12:29:03 GMT) Full text and rfc822 format available.Message #20 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 45mg <45mg.writes <at> gmail.com> Cc: Ludovic Courtès <ludo <at> gnu.org>, Maxim Cournoyer <maxim.cournoyer <at> gmail.com>, 77204 <at> debbugs.gnu.org Subject: Re: [bug#77204] [PATCH 1/3] services: dnsmasq: Provide shepherd-provision and shepherd-requirement fields. Date: Sun, 23 Mar 2025 13:28:29 +0100
[Message part 1 (text/plain, inline)]
Hi, 45mg <45mg.writes <at> gmail.com> writes: > Hi, > > Alexey Abramov via Guix-patches via <guix-patches <at> gnu.org> writes: > >> * gnu/services/dns.scm (<dnsmasq-configuration>)[provision]: Rename the field to >> [shepherd-provision] for consistency with other services. > > If this is accepted, you'll probably need to add an entry to > etc/news.scm, since it's a breaking change. > > You'll also need to update the Guix Cookbook. Specifically, the recent > commit da090138028894c6b00c21730aa3a02cda57fb24 uses the existing > 'provision' field of `dnsmasq-service-type` in an example. Thanks for letting me know. > With that said, I think the rename is a sensible change. (Just in case > it matters, I was the one who introduced the 'provision' field, as well > as that Cookbook example). I see. I guess there are not that many users who overrides provision for dnsmasq at the moment. AFAIK we do want shepherd-provision and shepherd-requirement insead of just provision/requirement. I have this script (see attachements) and run it withing the repo as ./pre-inst-env guix repl guix-services-info.scm --8<---------------cut here---------------start------------->8--- (<log-rotation-configuration> (provision requirement)) (<mympd-configuration> (shepherd-requirement)) (<mpd-configuration> (shepherd-requirement)) (<restic-backup-job> (requirement)) (<agetty-configuration> (shepherd-requirement)) (<mingetty-configuration> (shepherd-requirement)) (<static-networking> (provision requirement)) (<dnsmasq-configuration> (provision)) (<oci-container-configuration> (provision requirement)) (<live-service> (provision requirement)) (<opensmtpd-configuration> (shepherd-requirement)) (<connman-configuration> (shepherd-requirement)) (<network-manager-configuration> (shepherd-requirement)) (<wpa-supplicant-configuration> (requirement)) (<dhcp-client-configuration> (shepherd-requirement shepherd-provision)) (<system-log-configuration> (provision requirement)) (<shepherd-service> (provision requirement)) (<shepherd-configuration> (shepherd)) (<wireguard-configuration> (shepherd-requirement)) (<nginx-configuration> (shepherd-requirement)) (<slim-configuration> (shepherd)) --8<---------------cut here---------------end--------------->8--- I will add the change for the cookbook no problem. Regarding the news, I am not sure if I can do this, because it requires 'commit'. -- Alexey
[guix-services-info.scm (application/octet-stream, attachment)]
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 13:04:04 GMT) Full text and rfc822 format available.Message #23 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v2 0/3] dnsmasq service changes Date: Sun, 23 Mar 2025 14:00:51 +0100
The difference between v1 and v2 is a small change to the guix-cookbook where I change provision to shepherd-provision field. Alexey Abramov (3): services: dnsmasq: Provide shepherd-provision and shepherd-requirement fields. services: dnsmasq: Provide pid-file, conf-file and conf-dir configuration fields. services: dnsmasq: Provide stats and reload actions. doc/guix-cookbook.texi | 4 +- doc/guix.texi | 35 ++++++- gnu/services/dns.scm | 196 ++++++++++++++++++++++++++------------- gnu/tests/networking.scm | 98 ++++++++++++++++++++ 4 files changed, 265 insertions(+), 68 deletions(-) base-commit: 4ea012fc6ddcb32574fbd4a854b11808c34fbca8 -- 2.48.1
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 13:05:03 GMT) Full text and rfc822 format available.Message #26 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v2 1/3] services: dnsmasq: Provide shepherd-provision and shepherd-requirement fields. Date: Sun, 23 Mar 2025 14:00:52 +0100
* doc/guix.texi: Document the change. * gnu/services/dns.scm (<dnsmasq-configuration>)[provision]: Rename the field to [shepherd-provision] for consistency with other services. * gnu/services/dns.scm (<dnsmasq-configuration>)[shepherd-requirement]: New field. * gnu/services/dns.scm (dnsmasq-shepherd-service): Use newly-created fields. * doc/guix-cookbook.texi (Custom NAT-based network for libvirt): Rename `provision' field record to shepherd-provision. --- doc/guix-cookbook.texi | 4 ++-- doc/guix.texi | 11 ++++++++--- gnu/services/dns.scm | 12 ++++++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi index fe4cac79c3a..d4832b9bb40 100644 --- a/doc/guix-cookbook.texi +++ b/doc/guix-cookbook.texi @@ -4031,8 +4031,8 @@ Custom NAT-based network for libvirt (service dnsmasq-service-type (dnsmasq-configuration ;; You can have multiple instances of `dnsmasq-service-type` as long - ;; as each one has a different provision. - (provision '(dnsmasq-virbr0)) + ;; as each one has a different shepherd-provision. + (shepherd-provision '(dnsmasq-virbr0)) (extra-options (list ;; Only bind to the virtual bridge. This ;; avoids conflicts with other running diff --git a/doc/guix.texi b/doc/guix.texi index bcb1f9d9cf8..90fa6779657 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -35067,9 +35067,14 @@ DNS Services @item @code{package} (default: @var{dnsmasq}) Package object of the dnsmasq server. -@item @code{provision} (default: @code{'(dnsmasq)}) -A list of symbols for the Shepherd service corresponding to this dnsmasq -configuration. +@item @code{shepherd-provision} (default: @code{'(dnsmasq)}) +@itemx @code{shepherd-requirement} (default: @code{'(user-processes networking)}) +This option can be used to provide a list of Shepherd service names +(symbols) provided by this service. You might want to change the default +value if you intend to run several @command{dnsmasq} instances. + +Likewise, @code{shepherd-requirement} is a list of Shepherd service names +(symbols) that this service will depend on. @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index 05291eb65d9..9276504ffd0 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -742,8 +742,10 @@ (define-record-type* <dnsmasq-configuration> dnsmasq-configuration? (package dnsmasq-configuration-package (default dnsmasq)) ;file-like - (provision dnsmasq-provision - (default '(dnsmasq))) + (shepherd-provision dnsmasq-configuration-shepherd-provision + (default '(dnsmasq))) + (shepherd-requirement dnsmasq-configuration-shepherd-requirement + (default '(user-processes networking))) (no-hosts? dnsmasq-configuration-no-hosts? (default #f)) ;boolean (port dnsmasq-configuration-port @@ -802,6 +804,8 @@ (define-record-type* <dnsmasq-configuration> (define (dnsmasq-shepherd-service config) (match-record config <dnsmasq-configuration> (package + shepherd-provision + shepherd-requirement no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -815,8 +819,8 @@ (define (dnsmasq-shepherd-service config) tftp-lowercase? tftp-port-range tftp-root tftp-unique-root extra-options) (shepherd-service - (provision (dnsmasq-provision config)) - (requirement '(user-processes networking)) + (provision shepherd-provision) + (requirement shepherd-requirement) (documentation "Run the dnsmasq DNS server.") (start #~(make-forkexec-constructor (list -- 2.48.1
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 13:05:04 GMT) Full text and rfc822 format available.Message #29 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v2 2/3] services: dnsmasq: Provide pid-file, conf-file and conf-dir configuration fields. Date: Sun, 23 Mar 2025 14:00:53 +0100
* doc/guix.texi: Document it. * gnu/services/dns.scm: Export all record accessors. * gnu/services/dns.scm (<dnsmasq-configuration>)[pid-file]: New field. * gnu/services/dns.scm (<dnsmasq-configuration>)[conf-file]: New field. * gnu/services/dns.scm (<dnsmasq-configuration>)[conf-dir]: New field. * gnu/services/dns.scm (<dnsmasq-configuration>)[extra-options]: Move it to the end of the definition, because it is a last resort. * gnu/services/dns.scm (dnsmasq-shepherd-service): Use newly-created fields. --- doc/guix.texi | 14 ++++ gnu/services/dns.scm | 162 +++++++++++++++++++++++++++---------------- 2 files changed, 117 insertions(+), 59 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 90fa6779657..1bbd1824a87 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -35076,6 +35076,9 @@ DNS Services Likewise, @code{shepherd-requirement} is a list of Shepherd service names (symbols) that this service will depend on. +@item @code{pid-file} (default: @code{"/run/dnsmasq.pid"}) +Specify an alternate path for dnsmasq to record its process-id in. + @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. @@ -35196,6 +35199,17 @@ DNS Services resolving MAC addresses is only possible if the client is in the local network or obtained a DHCP lease from dnsmasq. +@item @code{conf-file} (default: @code{'()}) +Specify a configuration file or multiple. The given value should be a list of +string paths to the configuration files. File-like objects are also supported. + +@item @code{conf-dir} (default: @code{#f}) +Read all the files in the given directory as configuration +files. @command{dnsmasq} also supports extensions for the field, but +here it is not implemented. It is more convenient to make +@code{computed-file} directory in the store and use that. Files are +loaded in alphabetical order of filename. + @item @code{extra-options} (default: @code{'()}) This option provides an ``escape hatch'' for the user to provide arbitrary command-line arguments to @command{dnsmasq} as a list of strings. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index 9276504ffd0..6e2ec7c2067 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -54,6 +54,38 @@ (define-module (gnu services dns) dnsmasq-service-type dnsmasq-configuration + dnsmasq-configuration-package + dnsmasq-configuration-shepherd-provision + dnsmasq-configuration-shepherd-requirement + dnsmasq-configuration-pid-file + dnsmasq-configuration-no-hosts? + dnsmasq-configuration-port + dnsmasq-configuration-local-service? + dnsmasq-configuration-listen-address + dnsmasq-configuration-resolv-file + dnsmasq-configuration-no-resolv? + dnsmasq-configuration-forward-private-reverse-lookup? + dnsmasq-configuration-query-servers-in-order? + dnsmasq-configuration-servers + dnsmasq-configuration-servers-file + dnsmasq-configuration-addresses + dnsmasq-configuration-cache-size + dnsmasq-configuration-negative-cache? + dnsmasq-configuration-cpe-id + dnsmasq-configuration-tftp-enable? + dnsmasq-configuration-tftp-no-fail? + dnsmasq-configuration-tftp-single-port? + dnsmasq-tftp-secure? + dnsmasq-tftp-max + dnsmasq-tftp-mtu + dnsmasq-tftp-no-blocksize? + dnsmasq-tftp-lowercase? + dnsmasq-tftp-port-range + dnsmasq-tftp-root + dnsmasq-tftp-unique-root + dnsmasq-configuration-conf-file + dnsmasq-configuration-conf-dir + dnsmasq-configuration-extra-options unbound-service-type unbound-configuration @@ -740,72 +772,77 @@ (define knot-resolver-service-type (define-record-type* <dnsmasq-configuration> dnsmasq-configuration make-dnsmasq-configuration dnsmasq-configuration? - (package dnsmasq-configuration-package - (default dnsmasq)) ;file-like + (package dnsmasq-configuration-package + (default dnsmasq)) ;file-like (shepherd-provision dnsmasq-configuration-shepherd-provision (default '(dnsmasq))) (shepherd-requirement dnsmasq-configuration-shepherd-requirement (default '(user-processes networking))) - (no-hosts? dnsmasq-configuration-no-hosts? - (default #f)) ;boolean - (port dnsmasq-configuration-port - (default 53)) ;integer - (local-service? dnsmasq-configuration-local-service? - (default #t)) ;boolean - (listen-addresses dnsmasq-configuration-listen-address - (default '())) ;list of string - (extra-options dnsmasq-configuration-extra-options - (default '())) ;list of string - (resolv-file dnsmasq-configuration-resolv-file - (default "/etc/resolv.conf")) ;string - (no-resolv? dnsmasq-configuration-no-resolv? - (default #f)) ;boolean + (pid-file dnsmasq-configuration-pid-file + (default "/run/dnsmasq.pid")) ;string + (no-hosts? dnsmasq-configuration-no-hosts? + (default #f)) ;boolean + (port dnsmasq-configuration-port + (default 53)) ;integer + (local-service? dnsmasq-configuration-local-service? + (default #t)) ;boolean + (listen-addresses dnsmasq-configuration-listen-address + (default '())) ;list of string + (resolv-file dnsmasq-configuration-resolv-file + (default "/etc/resolv.conf")) ;string + (no-resolv? dnsmasq-configuration-no-resolv? + (default #f)) ;boolean (forward-private-reverse-lookup? - dnsmasq-configuration-forward-private-reverse-lookup? - (default #t)) ;boolean - (query-servers-in-order? - dnsmasq-configuration-query-servers-in-order? - (default #f)) ;boolean - (servers dnsmasq-configuration-servers - (default '())) ;list of string - (servers-file dnsmasq-configuration-servers-file - (default #f)) ;string|file-like - (addresses dnsmasq-configuration-addresses - (default '())) ;list of string - (cache-size dnsmasq-configuration-cache-size - (default 150)) ;integer - (negative-cache? dnsmasq-configuration-negative-cache? - (default #t)) ;boolean - (cpe-id dnsmasq-configuration-cpe-id - (default #f)) ;string - (tftp-enable? dnsmasq-configuration-tftp-enable? - (default #f)) ;boolean - (tftp-no-fail? dnsmasq-configuration-tftp-no-fail? - (default #f)) ;boolean - (tftp-single-port? dnsmasq-configuration-tftp-single-port? - (default #f)) ;boolean - (tftp-secure? dnsmasq-tftp-secure? - (default #f)) ;boolean - (tftp-max dnsmasq-tftp-max - (default #f)) ;integer - (tftp-mtu dnsmasq-tftp-mtu - (default #f)) ;integer - (tftp-no-blocksize? dnsmasq-tftp-no-blocksize? - (default #f)) ;boolean - (tftp-lowercase? dnsmasq-tftp-lowercase? - (default #f)) ;boolean - (tftp-port-range dnsmasq-tftp-port-range - (default #f)) ;string - (tftp-root dnsmasq-tftp-root - (default "/var/empty,lo")) ;string - (tftp-unique-root dnsmasq-tftp-unique-root - (default #f))) ;"" or "ip" or "mac" - + dnsmasq-configuration-forward-private-reverse-lookup? + (default #t)) ;boolean + (query-servers-in-order? dnsmasq-configuration-query-servers-in-order? + (default #f)) ;boolean + (servers dnsmasq-configuration-servers + (default '())) ;list of string + (servers-file dnsmasq-configuration-servers-file + (default #f)) ;string|file-like + (addresses dnsmasq-configuration-addresses + (default '())) ;list of string + (cache-size dnsmasq-configuration-cache-size + (default 150)) ;integer + (negative-cache? dnsmasq-configuration-negative-cache? + (default #t)) ;boolean + (cpe-id dnsmasq-configuration-cpe-id + (default #f)) ;string + (tftp-enable? dnsmasq-configuration-tftp-enable? + (default #f)) ;boolean + (tftp-no-fail? dnsmasq-configuration-tftp-no-fail? + (default #f)) ;boolean + (tftp-single-port? dnsmasq-configuration-tftp-single-port? + (default #f)) ;boolean + (tftp-secure? dnsmasq-tftp-secure? + (default #f)) ;boolean + (tftp-max dnsmasq-tftp-max + (default #f)) ;integer + (tftp-mtu dnsmasq-tftp-mtu + (default #f)) ;integer + (tftp-no-blocksize? dnsmasq-tftp-no-blocksize? + (default #f)) ;boolean + (tftp-lowercase? dnsmasq-tftp-lowercase? + (default #f)) ;boolean + (tftp-port-range dnsmasq-tftp-port-range + (default #f)) ;string + (tftp-root dnsmasq-tftp-root + (default "/var/empty,lo")) ;string + (tftp-unique-root dnsmasq-tftp-unique-root + (default #f)) ;"" or "ip" or "mac" + (conf-file dnsmasq-configuration-conf-file + (default '())) ;list of string|file-like + (conf-dir dnsmasq-configuration-conf-dir + (default #f)) ;string|file-like + (extra-options dnsmasq-configuration-extra-options + (default '()))) (define (dnsmasq-shepherd-service config) (match-record config <dnsmasq-configuration> (package shepherd-provision shepherd-requirement + pid-file no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -817,7 +854,8 @@ (define (dnsmasq-shepherd-service config) tftp-single-port? tftp-secure? tftp-max tftp-mtu tftp-no-blocksize? tftp-lowercase? tftp-port-range - tftp-root tftp-unique-root extra-options) + tftp-root tftp-unique-root + conf-file conf-dir extra-options) (shepherd-service (provision shepherd-provision) (requirement shepherd-requirement) @@ -826,7 +864,7 @@ (define (dnsmasq-shepherd-service config) (list #$(file-append package "/sbin/dnsmasq") "--keep-in-foreground" - "--pid-file=/run/dnsmasq.pid" + (string-append "--pid-file=" #$pid-file) #$@(if no-hosts? '("--no-hosts") '()) @@ -897,8 +935,14 @@ (define (dnsmasq-shepherd-service config) (format #f "--tftp-unique-root=~a" tftp-unique-root) (format #f "--tftp-unique-root"))) '()) + #$@(map (lambda (conf-file) + #~(string-append "--conf-file=" #$conf-file)) + conf-file) + #$@(if conf-dir + (list #~(string-append "--conf-dir=" #$conf-dir)) + '()) #$@extra-options) - #:pid-file "/run/dnsmasq.pid")) + #:pid-file #$pid-file)) (stop #~(make-kill-destructor))))) (define (dnsmasq-activation config) -- 2.48.1
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 13:05:07 GMT) Full text and rfc822 format available.Message #32 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v2 3/3] services: dnsmasq: Provide stats and reload actions. Date: Sun, 23 Mar 2025 14:00:54 +0100
* 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 1bbd1824a87..816a9ed57d0 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -35060,6 +35060,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 <dnsmasq-configuration> () + (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 <dnsmasq-configuration> () + (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 -- 2.48.1
guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Sun, 23 Mar 2025 13:06:05 GMT) Full text and rfc822 format available.Message #35 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com> To: Alexey Abramov <levenson <at> mmer.org> Cc: Ludovic Courtès <ludo <at> gnu.org>, 45mg <45mg.writes <at> gmail.com>, 77204 <at> debbugs.gnu.org Subject: Re: [bug#77204] [PATCH 1/3] services: dnsmasq: Provide shepherd-provision and shepherd-requirement fields. Date: Sun, 23 Mar 2025 22:04:59 +0900
Hi, Alexey Abramov <levenson <at> mmer.org> writes: > Hi, > 45mg <45mg.writes <at> gmail.com> writes: > >> Hi, >> >> Alexey Abramov via Guix-patches via <guix-patches <at> gnu.org> writes: >> >>> * gnu/services/dns.scm (<dnsmasq-configuration>)[provision]: Rename the field to >>> [shepherd-provision] for consistency with other services. >> >> If this is accepted, you'll probably need to add an entry to >> etc/news.scm, since it's a breaking change. Instead of a news item, I'd add a deprecated alias for the old field, so that it remains usable but warns. There should be various examples in the code. -- Thanks, Maxim
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Mon, 24 Mar 2025 06:58:01 GMT) Full text and rfc822 format available.Message #38 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v3 0/3] dnsmasq service changes Date: Mon, 24 Mar 2025 07:48:42 +0100
This is a v3 of series patches. The difference from v2 is that I resurrect the `provision' field but marked it as deprecated. As a test provision can be defined withing the current test and warning message will appear. No source location unfortunately. I am curious why there is no deprecated field property in guix record? We do i18n though and it is not in (guix record). Alexey Abramov (3): services: dnsmasq: Add shepherd-provision and shepherd-requirement fields. services: dnsmasq: Add pid-file, conf-file and conf-dir configuration fields. services: dnsmasq: Add stats and reload shepherd actions. doc/guix-cookbook.texi | 4 +- doc/guix.texi | 35 ++++++- gnu/services/dns.scm | 203 +++++++++++++++++++++++++++------------ gnu/tests/networking.scm | 98 +++++++++++++++++++ 4 files changed, 275 insertions(+), 65 deletions(-) base-commit: 4ea012fc6ddcb32574fbd4a854b11808c34fbca8 -- 2.48.1
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Mon, 24 Mar 2025 06:58:02 GMT) Full text and rfc822 format available.Message #41 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v3 1/3] services: dnsmasq: Add shepherd-provision and shepherd-requirement fields. Date: Mon, 24 Mar 2025 07:48:43 +0100
* gnu/services/dns.scm (<dnsmasq-configuration>)[provision]: Mark as deprecated with a warning. Set default to #f. * gnu/services/dns.scm (<dnsmasq-configuration>)[shepherd-provision]: Add new field for consistency with other services. * gnu/services/dns.scm (<dnsmasq-configuration>)[shepherd-requirement]: Add new field. * gnu/services/dns.scm (dnsmasq-shepherd-service): Use the new fields. * doc/guix.texi: Document these changes. * doc/guix-cookbook.texi (Custom NAT-based network for libvirt): Update example to use shepherd-provision instead of provision. --- doc/guix-cookbook.texi | 4 ++-- doc/guix.texi | 11 ++++++++--- gnu/services/dns.scm | 24 ++++++++++++++++++++---- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi index fe4cac79c3a..d4832b9bb40 100644 --- a/doc/guix-cookbook.texi +++ b/doc/guix-cookbook.texi @@ -4031,8 +4031,8 @@ Custom NAT-based network for libvirt (service dnsmasq-service-type (dnsmasq-configuration ;; You can have multiple instances of `dnsmasq-service-type` as long - ;; as each one has a different provision. - (provision '(dnsmasq-virbr0)) + ;; as each one has a different shepherd-provision. + (shepherd-provision '(dnsmasq-virbr0)) (extra-options (list ;; Only bind to the virtual bridge. This ;; avoids conflicts with other running diff --git a/doc/guix.texi b/doc/guix.texi index bcb1f9d9cf8..90fa6779657 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -35067,9 +35067,14 @@ DNS Services @item @code{package} (default: @var{dnsmasq}) Package object of the dnsmasq server. -@item @code{provision} (default: @code{'(dnsmasq)}) -A list of symbols for the Shepherd service corresponding to this dnsmasq -configuration. +@item @code{shepherd-provision} (default: @code{'(dnsmasq)}) +@itemx @code{shepherd-requirement} (default: @code{'(user-processes networking)}) +This option can be used to provide a list of Shepherd service names +(symbols) provided by this service. You might want to change the default +value if you intend to run several @command{dnsmasq} instances. + +Likewise, @code{shepherd-requirement} is a list of Shepherd service names +(symbols) that this service will depend on. @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index 05291eb65d9..f617f26891d 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -27,6 +27,7 @@ (define-module (gnu services dns) #:use-module (gnu system shadow) #:use-module (gnu packages admin) #:use-module (gnu packages dns) + #:use-module (guix deprecation) #:use-module (guix packages) #:use-module (guix records) #:use-module (guix gexp) @@ -742,8 +743,13 @@ (define-record-type* <dnsmasq-configuration> dnsmasq-configuration? (package dnsmasq-configuration-package (default dnsmasq)) ;file-like - (provision dnsmasq-provision - (default '(dnsmasq))) + (provision dnsmasq-configuration-provision ; deprecated + (default #f) + (sanitize warn-deprecated-dnsmasq-configuration-provision)) + (shepherd-provision dnsmasq-configuration-shepherd-provision + (default '(dnsmasq))) + (shepherd-requirement dnsmasq-configuration-shepherd-requirement + (default '(user-processes networking))) (no-hosts? dnsmasq-configuration-no-hosts? (default #f)) ;boolean (port dnsmasq-configuration-port @@ -799,9 +805,19 @@ (define-record-type* <dnsmasq-configuration> (tftp-unique-root dnsmasq-tftp-unique-root (default #f))) ;"" or "ip" or "mac" +(define (warn-deprecated-dnsmasq-configuration-provision value) + (when (pair? value) + (warn-about-deprecation + 'provision #f + #:replacement 'shepherd-provision)) + value) + (define (dnsmasq-shepherd-service config) (match-record config <dnsmasq-configuration> (package + provision + shepherd-provision + shepherd-requirement no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -815,8 +831,8 @@ (define (dnsmasq-shepherd-service config) tftp-lowercase? tftp-port-range tftp-root tftp-unique-root extra-options) (shepherd-service - (provision (dnsmasq-provision config)) - (requirement '(user-processes networking)) + (provision (or provision shepherd-provision)) + (requirement shepherd-requirement) (documentation "Run the dnsmasq DNS server.") (start #~(make-forkexec-constructor (list -- 2.48.1
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Mon, 24 Mar 2025 06:58:02 GMT) Full text and rfc822 format available.Message #44 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v3 2/3] services: dnsmasq: Add pid-file, conf-file and conf-dir configuration fields. Date: Mon, 24 Mar 2025 07:48:44 +0100
* gnu/services/dns.scm (<dnsmasq-configuration>)[pid-file]: New field to specify alternate path for dnsmasq PID. * gnu/services/dns.scm (<dnsmasq-configuration>)[conf-file]: New field to specify one or more configuration files. * gnu/services/dns.scm (<dnsmasq-configuration>)[conf-dir]: New field to read configuration files from a directory. * gnu/services/dns.scm (<dnsmasq-configuration>)[extra-options]: Move to the end of the definition as a last resort option. * gnu/services/dns.scm (dnsmasq-shepherd-service): Use the new fields instead of hardcoded values. * gnu/services/dns.scm: Export all record accessors. * doc/guix.texi: Document the new configuration options. --- doc/guix.texi | 14 ++++ gnu/services/dns.scm | 157 ++++++++++++++++++++++++++++--------------- 2 files changed, 115 insertions(+), 56 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 90fa6779657..1bbd1824a87 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -35076,6 +35076,9 @@ DNS Services Likewise, @code{shepherd-requirement} is a list of Shepherd service names (symbols) that this service will depend on. +@item @code{pid-file} (default: @code{"/run/dnsmasq.pid"}) +Specify an alternate path for dnsmasq to record its process-id in. + @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. @@ -35196,6 +35199,17 @@ DNS Services resolving MAC addresses is only possible if the client is in the local network or obtained a DHCP lease from dnsmasq. +@item @code{conf-file} (default: @code{'()}) +Specify a configuration file or multiple. The given value should be a list of +string paths to the configuration files. File-like objects are also supported. + +@item @code{conf-dir} (default: @code{#f}) +Read all the files in the given directory as configuration +files. @command{dnsmasq} also supports extensions for the field, but +here it is not implemented. It is more convenient to make +@code{computed-file} directory in the store and use that. Files are +loaded in alphabetical order of filename. + @item @code{extra-options} (default: @code{'()}) This option provides an ``escape hatch'' for the user to provide arbitrary command-line arguments to @command{dnsmasq} as a list of strings. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index f617f26891d..210fef4ece2 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -55,6 +55,38 @@ (define-module (gnu services dns) dnsmasq-service-type dnsmasq-configuration + dnsmasq-configuration-package + dnsmasq-configuration-shepherd-provision + dnsmasq-configuration-shepherd-requirement + dnsmasq-configuration-pid-file + dnsmasq-configuration-no-hosts? + dnsmasq-configuration-port + dnsmasq-configuration-local-service? + dnsmasq-configuration-listen-address + dnsmasq-configuration-resolv-file + dnsmasq-configuration-no-resolv? + dnsmasq-configuration-forward-private-reverse-lookup? + dnsmasq-configuration-query-servers-in-order? + dnsmasq-configuration-servers + dnsmasq-configuration-servers-file + dnsmasq-configuration-addresses + dnsmasq-configuration-cache-size + dnsmasq-configuration-negative-cache? + dnsmasq-configuration-cpe-id + dnsmasq-configuration-tftp-enable? + dnsmasq-configuration-tftp-no-fail? + dnsmasq-configuration-tftp-single-port? + dnsmasq-tftp-secure? + dnsmasq-tftp-max + dnsmasq-tftp-mtu + dnsmasq-tftp-no-blocksize? + dnsmasq-tftp-lowercase? + dnsmasq-tftp-port-range + dnsmasq-tftp-root + dnsmasq-tftp-unique-root + dnsmasq-configuration-conf-file + dnsmasq-configuration-conf-dir + dnsmasq-configuration-extra-options unbound-service-type unbound-configuration @@ -750,60 +782,65 @@ (define-record-type* <dnsmasq-configuration> (default '(dnsmasq))) (shepherd-requirement dnsmasq-configuration-shepherd-requirement (default '(user-processes networking))) - (no-hosts? dnsmasq-configuration-no-hosts? - (default #f)) ;boolean - (port dnsmasq-configuration-port - (default 53)) ;integer - (local-service? dnsmasq-configuration-local-service? - (default #t)) ;boolean - (listen-addresses dnsmasq-configuration-listen-address - (default '())) ;list of string - (extra-options dnsmasq-configuration-extra-options - (default '())) ;list of string - (resolv-file dnsmasq-configuration-resolv-file - (default "/etc/resolv.conf")) ;string - (no-resolv? dnsmasq-configuration-no-resolv? - (default #f)) ;boolean + (pid-file dnsmasq-configuration-pid-file + (default "/run/dnsmasq.pid")) ;string + (no-hosts? dnsmasq-configuration-no-hosts? + (default #f)) ;boolean + (port dnsmasq-configuration-port + (default 53)) ;integer + (local-service? dnsmasq-configuration-local-service? + (default #t)) ;boolean + (listen-addresses dnsmasq-configuration-listen-address + (default '())) ;list of string + (resolv-file dnsmasq-configuration-resolv-file + (default "/etc/resolv.conf")) ;string + (no-resolv? dnsmasq-configuration-no-resolv? + (default #f)) ;boolean (forward-private-reverse-lookup? - dnsmasq-configuration-forward-private-reverse-lookup? - (default #t)) ;boolean - (query-servers-in-order? - dnsmasq-configuration-query-servers-in-order? - (default #f)) ;boolean - (servers dnsmasq-configuration-servers - (default '())) ;list of string - (servers-file dnsmasq-configuration-servers-file - (default #f)) ;string|file-like - (addresses dnsmasq-configuration-addresses - (default '())) ;list of string - (cache-size dnsmasq-configuration-cache-size - (default 150)) ;integer - (negative-cache? dnsmasq-configuration-negative-cache? - (default #t)) ;boolean - (cpe-id dnsmasq-configuration-cpe-id - (default #f)) ;string - (tftp-enable? dnsmasq-configuration-tftp-enable? - (default #f)) ;boolean - (tftp-no-fail? dnsmasq-configuration-tftp-no-fail? - (default #f)) ;boolean - (tftp-single-port? dnsmasq-configuration-tftp-single-port? - (default #f)) ;boolean - (tftp-secure? dnsmasq-tftp-secure? - (default #f)) ;boolean - (tftp-max dnsmasq-tftp-max - (default #f)) ;integer - (tftp-mtu dnsmasq-tftp-mtu - (default #f)) ;integer - (tftp-no-blocksize? dnsmasq-tftp-no-blocksize? - (default #f)) ;boolean - (tftp-lowercase? dnsmasq-tftp-lowercase? - (default #f)) ;boolean - (tftp-port-range dnsmasq-tftp-port-range - (default #f)) ;string - (tftp-root dnsmasq-tftp-root - (default "/var/empty,lo")) ;string - (tftp-unique-root dnsmasq-tftp-unique-root - (default #f))) ;"" or "ip" or "mac" + dnsmasq-configuration-forward-private-reverse-lookup? + (default #t)) ;boolean + (query-servers-in-order? dnsmasq-configuration-query-servers-in-order? + (default #f)) ;boolean + (servers dnsmasq-configuration-servers + (default '())) ;list of string + (servers-file dnsmasq-configuration-servers-file + (default #f)) ;string|file-like + (addresses dnsmasq-configuration-addresses + (default '())) ;list of string + (cache-size dnsmasq-configuration-cache-size + (default 150)) ;integer + (negative-cache? dnsmasq-configuration-negative-cache? + (default #t)) ;boolean + (cpe-id dnsmasq-configuration-cpe-id + (default #f)) ;string + (tftp-enable? dnsmasq-configuration-tftp-enable? + (default #f)) ;boolean + (tftp-no-fail? dnsmasq-configuration-tftp-no-fail? + (default #f)) ;boolean + (tftp-single-port? dnsmasq-configuration-tftp-single-port? + (default #f)) ;boolean + (tftp-secure? dnsmasq-tftp-secure? + (default #f)) ;boolean + (tftp-max dnsmasq-tftp-max + (default #f)) ;integer + (tftp-mtu dnsmasq-tftp-mtu + (default #f)) ;integer + (tftp-no-blocksize? dnsmasq-tftp-no-blocksize? + (default #f)) ;boolean + (tftp-lowercase? dnsmasq-tftp-lowercase? + (default #f)) ;boolean + (tftp-port-range dnsmasq-tftp-port-range + (default #f)) ;string + (tftp-root dnsmasq-tftp-root + (default "/var/empty,lo")) ;string + (tftp-unique-root dnsmasq-tftp-unique-root + (default #f)) ;"" or "ip" or "mac" + (conf-file dnsmasq-configuration-conf-file + (default '())) ;list of string|file-like + (conf-dir dnsmasq-configuration-conf-dir + (default #f)) ;string|file-like + (extra-options dnsmasq-configuration-extra-options + (default '()))) (define (warn-deprecated-dnsmasq-configuration-provision value) (when (pair? value) @@ -818,6 +855,7 @@ (define (dnsmasq-shepherd-service config) provision shepherd-provision shepherd-requirement + pid-file no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -829,7 +867,8 @@ (define (dnsmasq-shepherd-service config) tftp-single-port? tftp-secure? tftp-max tftp-mtu tftp-no-blocksize? tftp-lowercase? tftp-port-range - tftp-root tftp-unique-root extra-options) + tftp-root tftp-unique-root + conf-file conf-dir extra-options) (shepherd-service (provision (or provision shepherd-provision)) (requirement shepherd-requirement) @@ -838,7 +877,7 @@ (define (dnsmasq-shepherd-service config) (list #$(file-append package "/sbin/dnsmasq") "--keep-in-foreground" - "--pid-file=/run/dnsmasq.pid" + (string-append "--pid-file=" #$pid-file) #$@(if no-hosts? '("--no-hosts") '()) @@ -909,8 +948,14 @@ (define (dnsmasq-shepherd-service config) (format #f "--tftp-unique-root=~a" tftp-unique-root) (format #f "--tftp-unique-root"))) '()) + #$@(map (lambda (conf-file) + #~(string-append "--conf-file=" #$conf-file)) + conf-file) + #$@(if conf-dir + (list #~(string-append "--conf-dir=" #$conf-dir)) + '()) #$@extra-options) - #:pid-file "/run/dnsmasq.pid")) + #:pid-file #$pid-file)) (stop #~(make-kill-destructor))))) (define (dnsmasq-activation config) -- 2.48.1
ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Mon, 24 Mar 2025 06:58:03 GMT) Full text and rfc822 format available.Message #47 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v3 3/3] services: dnsmasq: Add stats and reload shepherd actions. Date: Mon, 24 Mar 2025 07:48:45 +0100
* gnu/services/dns.scm (dnsmasq-service-reload-action): New function to implement SIGHUP handling for reloading configurations. * gnu/services/dns.scm (dnsmasq-service-stats-action): New function to implement SIGUSR1 handling for dumping statistics. * gnu/services/dns.scm (dnsmasq-shepherd-service): Use the new actions. * doc/guix.texi: Document the new actions with examples. * gnu/tests/networking.scm (%test-dnsmasq): Add tests to verify the functionality of the new actions. --- 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 1bbd1824a87..816a9ed57d0 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -35060,6 +35060,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 210fef4ece2..f96d6dbb158 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -873,6 +873,8 @@ (define (dnsmasq-shepherd-service config) (provision (or 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") @@ -964,6 +966,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 <dnsmasq-configuration> () + (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 <dnsmasq-configuration> () + (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 -- 2.48.1
guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Tue, 22 Apr 2025 05:31:03 GMT) Full text and rfc822 format available.Message #50 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com> To: Alexey Abramov <levenson <at> mmer.org> Cc: Ludovic Courtès <ludo <at> gnu.org>, 77204 <at> debbugs.gnu.org Subject: Re: [bug#77204] [PATCH v3 1/3] services: dnsmasq: Add shepherd-provision and shepherd-requirement fields. Date: Tue, 22 Apr 2025 14:30:18 +0900
Hi Alexey, Alexey Abramov <levenson <at> mmer.org> writes: > * gnu/services/dns.scm (<dnsmasq-configuration>)[provision]: Mark as > deprecated with a warning. Set default to #f. > * gnu/services/dns.scm (<dnsmasq-configuration>)[shepherd-provision]: > Add new field for consistency with other services. > * gnu/services/dns.scm (<dnsmasq-configuration>)[shepherd-requirement]: > Add new field. > * gnu/services/dns.scm (dnsmasq-shepherd-service): Use the new fields. > * doc/guix.texi: Document these changes. > * doc/guix-cookbook.texi (Custom NAT-based network for libvirt): > Update example to use shepherd-provision instead of provision. Same file names in changelog should only appear once. See (info "(standards) Style of Change Logs") (that's a manual part of our 'gnu-standards' package) for more guidance, or 'git log' for examples. > --- > doc/guix-cookbook.texi | 4 ++-- > doc/guix.texi | 11 ++++++++--- > gnu/services/dns.scm | 24 ++++++++++++++++++++---- > 3 files changed, 30 insertions(+), 9 deletions(-) > > diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi > index fe4cac79c3a..d4832b9bb40 100644 > --- a/doc/guix-cookbook.texi > +++ b/doc/guix-cookbook.texi > @@ -4031,8 +4031,8 @@ Custom NAT-based network for libvirt > (service dnsmasq-service-type > (dnsmasq-configuration > ;; You can have multiple instances of `dnsmasq-service-type` as long > - ;; as each one has a different provision. > - (provision '(dnsmasq-virbr0)) > + ;; as each one has a different shepherd-provision. > + (shepherd-provision '(dnsmasq-virbr0)) > (extra-options (list > ;; Only bind to the virtual bridge. This > ;; avoids conflicts with other running Looks reasonable; it does seem like 'shepherd-provision' and 'shepherd-requirement' are the prevalent and preferable names to distinguish them from other configuration options. > diff --git a/doc/guix.texi b/doc/guix.texi > index bcb1f9d9cf8..90fa6779657 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -35067,9 +35067,14 @@ DNS Services > @item @code{package} (default: @var{dnsmasq}) > Package object of the dnsmasq server. > > -@item @code{provision} (default: @code{'(dnsmasq)}) > -A list of symbols for the Shepherd service corresponding to this dnsmasq > -configuration. > +@item @code{shepherd-provision} (default: @code{'(dnsmasq)}) > +@itemx @code{shepherd-requirement} (default: @code{'(user-processes networking)}) > +This option can be used to provide a list of Shepherd service names > +(symbols) provided by this service. You might want to change the default ^ Use double space to separate sentences in the Guix sources (whether in doc or comments, etc); see (info "(standards) Comments"). > +value if you intend to run several @command{dnsmasq} instances. > + > +Likewise, @code{shepherd-requirement} is a list of Shepherd service names > +(symbols) that this service will depend on. > > @item @code{no-hosts?} (default: @code{#f}) > When true, don't read the hostnames in /etc/hosts. > diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm > index 05291eb65d9..f617f26891d 100644 > --- a/gnu/services/dns.scm > +++ b/gnu/services/dns.scm > @@ -27,6 +27,7 @@ (define-module (gnu services dns) > #:use-module (gnu system shadow) > #:use-module (gnu packages admin) > #:use-module (gnu packages dns) > + #:use-module (guix deprecation) > #:use-module (guix packages) > #:use-module (guix records) > #:use-module (guix gexp) > @@ -742,8 +743,13 @@ (define-record-type* <dnsmasq-configuration> > dnsmasq-configuration? > (package dnsmasq-configuration-package > (default dnsmasq)) ;file-like > - (provision dnsmasq-provision > - (default '(dnsmasq))) > + (provision dnsmasq-configuration-provision ; deprecated > + (default #f) > + (sanitize warn-deprecated-dnsmasq-configuration-provision)) > + (shepherd-provision dnsmasq-configuration-shepherd-provision > + (default '(dnsmasq))) > + (shepherd-requirement dnsmasq-configuration-shepherd-requirement > + (default '(user-processes networking))) Since we're busting our 80 columns max width coding style here, I'd refrain from indenting the right hand side as a block. You may need to reformat lines (break them) so that it fits under 80 chars too. > (no-hosts? dnsmasq-configuration-no-hosts? > (default #f)) ;boolean > (port dnsmasq-configuration-port > @@ -799,9 +805,19 @@ (define-record-type* <dnsmasq-configuration> > (tftp-unique-root dnsmasq-tftp-unique-root > (default #f))) ;"" or "ip" or "mac" > > +(define (warn-deprecated-dnsmasq-configuration-provision value) > + (when (pair? value) > + (warn-about-deprecation > + 'provision #f > + #:replacement 'shepherd-provision)) > + value) > + Yeah, I think that's the best we can do currently with deprecation for guix record fields. It'd be nice to add deprecation support builtin and have source info, maybe. > (define (dnsmasq-shepherd-service config) > (match-record config <dnsmasq-configuration> > (package > + provision > + shepherd-provision > + shepherd-requirement > no-hosts? > port local-service? listen-addresses > resolv-file no-resolv? > @@ -815,8 +831,8 @@ (define (dnsmasq-shepherd-service config) > tftp-lowercase? tftp-port-range > tftp-root tftp-unique-root extra-options) > (shepherd-service > - (provision (dnsmasq-provision config)) > - (requirement '(user-processes networking)) > + (provision (or provision shepherd-provision)) > + (requirement shepherd-requirement) > (documentation "Run the dnsmasq DNS server.") > (start #~(make-forkexec-constructor > (list Other than these nitpicks, it LGTM. I'm not done reviewing 2 and 3, but after I do so, could you please send a v2 with the above adjusted? -- Thanks, Maxim
guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Tue, 22 Apr 2025 05:36:03 GMT) Full text and rfc822 format available.Message #53 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com> To: Alexey Abramov <levenson <at> mmer.org> Cc: Ludovic Courtès <ludo <at> gnu.org>, 77204 <at> debbugs.gnu.org Subject: Re: [bug#77204] [PATCH v3 2/3] services: dnsmasq: Add pid-file, conf-file and conf-dir configuration fields. Date: Tue, 22 Apr 2025 14:35:30 +0900
Hi, Alexey Abramov <levenson <at> mmer.org> writes: > * gnu/services/dns.scm (<dnsmasq-configuration>)[pid-file]: New field to > specify alternate path for dnsmasq PID. > * gnu/services/dns.scm (<dnsmasq-configuration>)[conf-file]: New field to > specify one or more configuration files. > * gnu/services/dns.scm (<dnsmasq-configuration>)[conf-dir]: New field to > read configuration files from a directory. > * gnu/services/dns.scm (<dnsmasq-configuration>)[extra-options]: Move > to the end of the definition as a last resort option. > * gnu/services/dns.scm (dnsmasq-shepherd-service): Use the new fields > instead of hardcoded values. > * gnu/services/dns.scm: Export all record accessors. > * doc/guix.texi: Document the new configuration options. As mentioned earlier, file names should only appear once. > --- > doc/guix.texi | 14 ++++ > gnu/services/dns.scm | 157 ++++++++++++++++++++++++++++--------------- > 2 files changed, 115 insertions(+), 56 deletions(-) > > diff --git a/doc/guix.texi b/doc/guix.texi > index 90fa6779657..1bbd1824a87 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -35076,6 +35076,9 @@ DNS Services > Likewise, @code{shepherd-requirement} is a list of Shepherd service names > (symbols) that this service will depend on. > > +@item @code{pid-file} (default: @code{"/run/dnsmasq.pid"}) > +Specify an alternate path for dnsmasq to record its process-id in. > + > @item @code{no-hosts?} (default: @code{#f}) > When true, don't read the hostnames in /etc/hosts. > > @@ -35196,6 +35199,17 @@ DNS Services > resolving MAC addresses is only possible if the client is in the local > network or obtained a DHCP lease from dnsmasq. > > +@item @code{conf-file} (default: @code{'()}) > +Specify a configuration file or multiple. The given value should be a list of > +string paths to the configuration files. File-like objects are also supported. > + > +@item @code{conf-dir} (default: @code{#f}) > +Read all the files in the given directory as configuration > +files. @command{dnsmasq} also supports extensions for the field, but > +here it is not implemented. It is more convenient to make > +@code{computed-file} directory in the store and use that. Files are > +loaded in alphabetical order of filename. > + > @item @code{extra-options} (default: @code{'()}) > This option provides an ``escape hatch'' for the user to provide arbitrary > command-line arguments to @command{dnsmasq} as a list of strings. > diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm > index f617f26891d..210fef4ece2 100644 > --- a/gnu/services/dns.scm > +++ b/gnu/services/dns.scm > @@ -55,6 +55,38 @@ (define-module (gnu services dns) > > dnsmasq-service-type > dnsmasq-configuration > + dnsmasq-configuration-package > + dnsmasq-configuration-shepherd-provision > + dnsmasq-configuration-shepherd-requirement > + dnsmasq-configuration-pid-file > + dnsmasq-configuration-no-hosts? > + dnsmasq-configuration-port > + dnsmasq-configuration-local-service? > + dnsmasq-configuration-listen-address > + dnsmasq-configuration-resolv-file > + dnsmasq-configuration-no-resolv? > + dnsmasq-configuration-forward-private-reverse-lookup? > + dnsmasq-configuration-query-servers-in-order? > + dnsmasq-configuration-servers > + dnsmasq-configuration-servers-file > + dnsmasq-configuration-addresses > + dnsmasq-configuration-cache-size > + dnsmasq-configuration-negative-cache? > + dnsmasq-configuration-cpe-id > + dnsmasq-configuration-tftp-enable? > + dnsmasq-configuration-tftp-no-fail? > + dnsmasq-configuration-tftp-single-port? > + dnsmasq-tftp-secure? > + dnsmasq-tftp-max > + dnsmasq-tftp-mtu > + dnsmasq-tftp-no-blocksize? > + dnsmasq-tftp-lowercase? > + dnsmasq-tftp-port-range > + dnsmasq-tftp-root > + dnsmasq-tftp-unique-root > + dnsmasq-configuration-conf-file > + dnsmasq-configuration-conf-dir > + dnsmasq-configuration-extra-options > > unbound-service-type > unbound-configuration > @@ -750,60 +782,65 @@ (define-record-type* <dnsmasq-configuration> > (default '(dnsmasq))) > (shepherd-requirement dnsmasq-configuration-shepherd-requirement > (default '(user-processes networking))) > - (no-hosts? dnsmasq-configuration-no-hosts? > - (default #f)) ;boolean > - (port dnsmasq-configuration-port > - (default 53)) ;integer > - (local-service? dnsmasq-configuration-local-service? > - (default #t)) ;boolean > - (listen-addresses dnsmasq-configuration-listen-address > - (default '())) ;list of string > - (extra-options dnsmasq-configuration-extra-options > - (default '())) ;list of string > - (resolv-file dnsmasq-configuration-resolv-file > - (default "/etc/resolv.conf")) ;string > - (no-resolv? dnsmasq-configuration-no-resolv? > - (default #f)) ;boolean > + (pid-file dnsmasq-configuration-pid-file > + (default "/run/dnsmasq.pid")) ;string > + (no-hosts? dnsmasq-configuration-no-hosts? > + (default #f)) ;boolean > + (port dnsmasq-configuration-port > + (default 53)) ;integer > + (local-service? dnsmasq-configuration-local-service? > + (default #t)) ;boolean > + (listen-addresses dnsmasq-configuration-listen-address > + (default '())) ;list of string > + (resolv-file dnsmasq-configuration-resolv-file > + (default "/etc/resolv.conf")) ;string > + (no-resolv? dnsmasq-configuration-no-resolv? > + (default #f)) ;boolean > (forward-private-reverse-lookup? > - dnsmasq-configuration-forward-private-reverse-lookup? > - (default #t)) ;boolean > - (query-servers-in-order? > - dnsmasq-configuration-query-servers-in-order? > - (default #f)) ;boolean > - (servers dnsmasq-configuration-servers > - (default '())) ;list of string > - (servers-file dnsmasq-configuration-servers-file > - (default #f)) ;string|file-like > - (addresses dnsmasq-configuration-addresses > - (default '())) ;list of string > - (cache-size dnsmasq-configuration-cache-size > - (default 150)) ;integer > - (negative-cache? dnsmasq-configuration-negative-cache? > - (default #t)) ;boolean > - (cpe-id dnsmasq-configuration-cpe-id > - (default #f)) ;string > - (tftp-enable? dnsmasq-configuration-tftp-enable? > - (default #f)) ;boolean > - (tftp-no-fail? dnsmasq-configuration-tftp-no-fail? > - (default #f)) ;boolean > - (tftp-single-port? dnsmasq-configuration-tftp-single-port? > - (default #f)) ;boolean > - (tftp-secure? dnsmasq-tftp-secure? > - (default #f)) ;boolean > - (tftp-max dnsmasq-tftp-max > - (default #f)) ;integer > - (tftp-mtu dnsmasq-tftp-mtu > - (default #f)) ;integer > - (tftp-no-blocksize? dnsmasq-tftp-no-blocksize? > - (default #f)) ;boolean > - (tftp-lowercase? dnsmasq-tftp-lowercase? > - (default #f)) ;boolean > - (tftp-port-range dnsmasq-tftp-port-range > - (default #f)) ;string > - (tftp-root dnsmasq-tftp-root > - (default "/var/empty,lo")) ;string > - (tftp-unique-root dnsmasq-tftp-unique-root > - (default #f))) ;"" or "ip" or "mac" > + dnsmasq-configuration-forward-private-reverse-lookup? > + (default #t)) ;boolean > + (query-servers-in-order? dnsmasq-configuration-query-servers-in-order? > + (default #f)) ;boolean > + (servers dnsmasq-configuration-servers > + (default '())) ;list of string > + (servers-file dnsmasq-configuration-servers-file > + (default #f)) ;string|file-like > + (addresses dnsmasq-configuration-addresses > + (default '())) ;list of string > + (cache-size dnsmasq-configuration-cache-size > + (default 150)) ;integer > + (negative-cache? dnsmasq-configuration-negative-cache? > + (default #t)) ;boolean > + (cpe-id dnsmasq-configuration-cpe-id > + (default #f)) ;string > + (tftp-enable? dnsmasq-configuration-tftp-enable? > + (default #f)) ;boolean > + (tftp-no-fail? dnsmasq-configuration-tftp-no-fail? > + (default #f)) ;boolean > + (tftp-single-port? dnsmasq-configuration-tftp-single-port? > + (default #f)) ;boolean > + (tftp-secure? dnsmasq-tftp-secure? > + (default #f)) ;boolean > + (tftp-max dnsmasq-tftp-max > + (default #f)) ;integer > + (tftp-mtu dnsmasq-tftp-mtu > + (default #f)) ;integer > + (tftp-no-blocksize? dnsmasq-tftp-no-blocksize? > + (default #f)) ;boolean > + (tftp-lowercase? dnsmasq-tftp-lowercase? > + (default #f)) ;boolean > + (tftp-port-range dnsmasq-tftp-port-range > + (default #f)) ;string > + (tftp-root dnsmasq-tftp-root > + (default "/var/empty,lo")) ;string > + (tftp-unique-root dnsmasq-tftp-unique-root > + (default #f)) ;"" or "ip" or "mac" > + (conf-file dnsmasq-configuration-conf-file > + (default '())) ;list of string|file-like > + (conf-dir dnsmasq-configuration-conf-dir > + (default #f)) ;string|file-like > + (extra-options dnsmasq-configuration-extra-options > + (default '()))) Please refrain from adjusting the indentation like this; it makes reviewing difficult and here also breaks our max width of 80 columns. > (define (warn-deprecated-dnsmasq-configuration-provision value) > (when (pair? value) > @@ -818,6 +855,7 @@ (define (dnsmasq-shepherd-service config) > provision > shepherd-provision > shepherd-requirement > + pid-file > no-hosts? > port local-service? listen-addresses > resolv-file no-resolv? > @@ -829,7 +867,8 @@ (define (dnsmasq-shepherd-service config) > tftp-single-port? tftp-secure? > tftp-max tftp-mtu tftp-no-blocksize? > tftp-lowercase? tftp-port-range > - tftp-root tftp-unique-root extra-options) > + tftp-root tftp-unique-root > + conf-file conf-dir extra-options) > (shepherd-service > (provision (or provision shepherd-provision)) > (requirement shepherd-requirement) > @@ -838,7 +877,7 @@ (define (dnsmasq-shepherd-service config) > (list > #$(file-append package "/sbin/dnsmasq") > "--keep-in-foreground" > - "--pid-file=/run/dnsmasq.pid" > + (string-append "--pid-file=" #$pid-file) > #$@(if no-hosts? > '("--no-hosts") > '()) > @@ -909,8 +948,14 @@ (define (dnsmasq-shepherd-service config) > (format #f "--tftp-unique-root=~a" tftp-unique-root) > (format #f "--tftp-unique-root"))) > '()) > + #$@(map (lambda (conf-file) > + #~(string-append "--conf-file=" #$conf-file)) > + conf-file) > + #$@(if conf-dir > + (list #~(string-append "--conf-dir=" #$conf-dir)) > + '()) > #$@extra-options) > - #:pid-file "/run/dnsmasq.pid")) > + #:pid-file #$pid-file)) > (stop #~(make-kill-destructor))))) Other than that, it looks like a good change! Thank you. -- Thanks, Maxim
guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Tue, 22 Apr 2025 06:21:01 GMT) Full text and rfc822 format available.Message #56 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com> To: Alexey Abramov <levenson <at> mmer.org> Cc: Ludovic Courtès <ludo <at> gnu.org>, 77204 <at> debbugs.gnu.org Subject: Re: [bug#77204] [PATCH v3 3/3] services: dnsmasq: Add stats and reload shepherd actions. Date: Tue, 22 Apr 2025 15:20:10 +0900
Hi again, Alexey Abramov <levenson <at> mmer.org> writes: > * gnu/services/dns.scm (dnsmasq-service-reload-action): New function to > implement SIGHUP handling for reloading configurations. > * gnu/services/dns.scm (dnsmasq-service-stats-action): New function to > implement SIGUSR1 handling for dumping statistics. > * gnu/services/dns.scm (dnsmasq-shepherd-service): Use the new actions. > * doc/guix.texi: Document the new actions with examples. > * gnu/tests/networking.scm (%test-dnsmasq): Add tests to verify the > functionality of the new actions. Looks nice! Same comment as earlier: file names should appear once. > --- > 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 1bbd1824a87..816a9ed57d0 100644 > --- a/doc/guix.texi > +++ b/doc/guix.texi > @@ -35060,6 +35060,16 @@ DNS Services > @end lisp > @end defvar The newly added dnsmasq-serice-type should be nested into the existing 'defvar' for it. > +@code{dnsmasq-service-type} also provides few helpful actions which are Then, I'd just write: Two actions are provided: > +@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}. s/is usually// (is it configurable to be elsewhere -- I don't think so?) > + > @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 210fef4ece2..f96d6dbb158 100644 > --- a/gnu/services/dns.scm > +++ b/gnu/services/dns.scm > @@ -873,6 +873,8 @@ (define (dnsmasq-shepherd-service config) > (provision (or 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") > @@ -964,6 +966,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 <dnsmasq-configuration> () > + (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.") s/re-load/reload/ s/re-read/reload/ Please mind maximum 80 columns coding style; I believe this is also to be formatted as Texinfo so you could use @file{/etc/hosts} and @file{/etc/ethers} for example, and @option for each listed options. Instead of emphasising with full caps, you can use @emph{not}. > + (procedure #~(lambda (running) > + (let ((pid (process-id running))) > + (kill pid SIGHUP))))))) > + > +(define (dnsmasq-service-stats-action config) > + (match-record config <dnsmasq-configuration> () > + (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))) Interesting! > + (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)) That looks like a useful series. Could you please send a v4, integrating my requested changes? -- Thanks, Maxim
gabriel <at> erlikon.ch, ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Thu, 08 May 2025 17:51:02 GMT) Full text and rfc822 format available.Message #59 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v4 0/3] dnsmasq service changes Date: Thu, 8 May 2025 19:47:40 +0200
Thank you, Maxim, for your thorough review. With v4 I did address all your suggestions (I hope I didn't miss anything ;)). I had an impression that `M-q' would do a proper formating of sentences, but apparently `sentence-end-double-space' is a hint to just break lines. Am i missing something? Regarding the commit messages, I kinda used to go to diff in magit and press `C' on a hunk and it does add things to the commit message. I did check git log and see people use different ways like (), [] and <>. Seems like a more personal stuff, but I would like to know more... With these v4 series: - I moved documentation of actions to the manual and not in the action procedures themselves. herd doc prints texi markups as is. - I removed indentation of fields. Alexey Abramov (3): services: dnsmasq: Add shepherd-provision and shepherd-requirement fields. services: dnsmasq: Add pid-file, conf-file and conf-dir configuration fields. services: dnsmasq: Add stats and reload shepherd actions. doc/guix-cookbook.texi | 4 +- doc/guix.texi | 78 +++++++++++++++++++++++++++-- gnu/services/dns.scm | 104 +++++++++++++++++++++++++++++++++++---- gnu/tests/networking.scm | 98 ++++++++++++++++++++++++++++++++++++ 4 files changed, 269 insertions(+), 15 deletions(-) base-commit: ac2d792aae241f5233ee3fdfa29cd3dbaeb9338c -- 2.49.0
gabriel <at> erlikon.ch, ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Thu, 08 May 2025 17:51:02 GMT) Full text and rfc822 format available.Message #62 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v4 1/3] services: dnsmasq: Add shepherd-provision and shepherd-requirement fields. Date: Thu, 8 May 2025 19:47:41 +0200
* gnu/services/dns.scm (<dnsmasq-configuration>)[provision]: Mark filed as deprecated with a warning. Set default to #f. [shepherd-provision]: Add new field for consistency with other services. [shepherd-requirement]: Add new field. (dnsmasq-shepherd-service): Use them * doc/guix.texi: Document these changes. * doc/guix-cookbook.texi (Custom NAT-based network for libvirt): Update example to use 'shepherd-provision' instead of 'provision'. --- doc/guix-cookbook.texi | 4 ++-- doc/guix.texi | 11 ++++++++--- gnu/services/dns.scm | 24 ++++++++++++++++++++---- 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/doc/guix-cookbook.texi b/doc/guix-cookbook.texi index fb58866d404..3ebe661a078 100644 --- a/doc/guix-cookbook.texi +++ b/doc/guix-cookbook.texi @@ -4018,8 +4018,8 @@ Custom NAT-based network for libvirt (service dnsmasq-service-type (dnsmasq-configuration ;; You can have multiple instances of `dnsmasq-service-type` as long - ;; as each one has a different provision. - (provision '(dnsmasq-virbr0)) + ;; as each one has a different shepherd-provision. + (shepherd-provision '(dnsmasq-virbr0)) (extra-options (list ;; Only bind to the virtual bridge. This ;; avoids conflicts with other running diff --git a/doc/guix.texi b/doc/guix.texi index 889eab2ab35..279bbda9ac4 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36086,9 +36086,14 @@ DNS Services @item @code{package} (default: @var{dnsmasq}) Package object of the dnsmasq server. -@item @code{provision} (default: @code{'(dnsmasq)}) -A list of symbols for the Shepherd service corresponding to this dnsmasq -configuration. +@item @code{shepherd-provision} (default: @code{'(dnsmasq)}) +@itemx @code{shepherd-requirement} (default: @code{'(user-processes networking)}) +This option can be used to provide a list of Shepherd service names +(symbols) provided by this service. You might want to change the default +value if you intend to run several @command{dnsmasq} instances. + +Likewise, @code{shepherd-requirement} is a list of Shepherd service names +(symbols) that this service will depend on. @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index 05291eb65d9..fd849d08e89 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -27,6 +27,7 @@ (define-module (gnu services dns) #:use-module (gnu system shadow) #:use-module (gnu packages admin) #:use-module (gnu packages dns) + #:use-module (guix deprecation) #:use-module (guix packages) #:use-module (guix records) #:use-module (guix gexp) @@ -742,8 +743,13 @@ (define-record-type* <dnsmasq-configuration> dnsmasq-configuration? (package dnsmasq-configuration-package (default dnsmasq)) ;file-like - (provision dnsmasq-provision - (default '(dnsmasq))) + (provision dnsmasq-configuration-provision ; deprecated + (default #f) + (sanitize warn-deprecated-dnsmasq-configuration-provision)) + (shepherd-provision dnsmasq-configuration-shepherd-provision + (default '(dnsmasq))) + (shepherd-requirement dnsmasq-configuration-shepherd-requirement + (default '(user-processes networking))) (no-hosts? dnsmasq-configuration-no-hosts? (default #f)) ;boolean (port dnsmasq-configuration-port @@ -799,9 +805,19 @@ (define-record-type* <dnsmasq-configuration> (tftp-unique-root dnsmasq-tftp-unique-root (default #f))) ;"" or "ip" or "mac" +(define (warn-deprecated-dnsmasq-configuration-provision value) + (when (pair? value) + (warn-about-deprecation + 'provision #f + #:replacement 'shepherd-provision)) + value) + (define (dnsmasq-shepherd-service config) (match-record config <dnsmasq-configuration> (package + provision + shepherd-provision + shepherd-requirement no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -815,8 +831,8 @@ (define (dnsmasq-shepherd-service config) tftp-lowercase? tftp-port-range tftp-root tftp-unique-root extra-options) (shepherd-service - (provision (dnsmasq-provision config)) - (requirement '(user-processes networking)) + (provision (or provision shepherd-provision)) + (requirement shepherd-requirement) (documentation "Run the dnsmasq DNS server.") (start #~(make-forkexec-constructor (list -- 2.49.0
gabriel <at> erlikon.ch, ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Thu, 08 May 2025 17:51:03 GMT) Full text and rfc822 format available.Message #65 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v4 2/3] services: dnsmasq: Add pid-file, conf-file and conf-dir configuration fields. Date: Thu, 8 May 2025 19:47:42 +0200
* gnu/services/dns.scm (<dnsmasq-configuration>)[pid-file]: New field to specify alternate path for dnsmasq PID. [conf-file]: New field to specify one or more configuration files. [conf-dir]: New field to read configuration files from a directory. [extra-options]: Move to the end of the definition as a last resort option. (dnsmasq-shepherd-service): Use new fields instead of hardcoded values. * gnu/services/dns.scm: Export all record accessors. * doc/guix.texi: Document new configuration options. --- doc/guix.texi | 15 ++++++++++++ gnu/services/dns.scm | 58 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 67 insertions(+), 6 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 279bbda9ac4..ec096643eaa 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36095,6 +36095,9 @@ DNS Services Likewise, @code{shepherd-requirement} is a list of Shepherd service names (symbols) that this service will depend on. +@item @code{pid-file} (default: @code{"/run/dnsmasq.pid"}) +Specify an alternate path for dnsmasq to record its process-id in. + @item @code{no-hosts?} (default: @code{#f}) When true, don't read the hostnames in /etc/hosts. @@ -36215,6 +36218,18 @@ DNS Services resolving MAC addresses is only possible if the client is in the local network or obtained a DHCP lease from dnsmasq. +@item @code{conf-file} (default: @code{'()}) +Specify a configuration file or multiple. The given value should be a +list of string paths to the configuration files. File-like objects are +also supported. + +@item @code{conf-dir} (default: @code{#f}) +Read all the files in the given directory as configuration files. +@command{dnsmasq} also supports extensions for the field, but here it is +not implemented. It is more convenient to make @code{computed-file} +directory in the store and use that. Files are loaded in alphabetical +order of filename. + @item @code{extra-options} (default: @code{'()}) This option provides an ``escape hatch'' for the user to provide arbitrary command-line arguments to @command{dnsmasq} as a list of strings. diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index fd849d08e89..d55ee3e4fcb 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -55,6 +55,38 @@ (define-module (gnu services dns) dnsmasq-service-type dnsmasq-configuration + dnsmasq-configuration-package + dnsmasq-configuration-shepherd-provision + dnsmasq-configuration-shepherd-requirement + dnsmasq-configuration-pid-file + dnsmasq-configuration-no-hosts? + dnsmasq-configuration-port + dnsmasq-configuration-local-service? + dnsmasq-configuration-listen-address + dnsmasq-configuration-resolv-file + dnsmasq-configuration-no-resolv? + dnsmasq-configuration-forward-private-reverse-lookup? + dnsmasq-configuration-query-servers-in-order? + dnsmasq-configuration-servers + dnsmasq-configuration-servers-file + dnsmasq-configuration-addresses + dnsmasq-configuration-cache-size + dnsmasq-configuration-negative-cache? + dnsmasq-configuration-cpe-id + dnsmasq-configuration-tftp-enable? + dnsmasq-configuration-tftp-no-fail? + dnsmasq-configuration-tftp-single-port? + dnsmasq-tftp-secure? + dnsmasq-tftp-max + dnsmasq-tftp-mtu + dnsmasq-tftp-no-blocksize? + dnsmasq-tftp-lowercase? + dnsmasq-tftp-port-range + dnsmasq-tftp-root + dnsmasq-tftp-unique-root + dnsmasq-configuration-conf-file + dnsmasq-configuration-conf-dir + dnsmasq-configuration-extra-options unbound-service-type unbound-configuration @@ -752,14 +784,14 @@ (define-record-type* <dnsmasq-configuration> (default '(user-processes networking))) (no-hosts? dnsmasq-configuration-no-hosts? (default #f)) ;boolean + (pid-file dnsmasq-configuration-pid-file + (default "/run/dnsmasq.pid")) ;string (port dnsmasq-configuration-port (default 53)) ;integer (local-service? dnsmasq-configuration-local-service? (default #t)) ;boolean (listen-addresses dnsmasq-configuration-listen-address (default '())) ;list of string - (extra-options dnsmasq-configuration-extra-options - (default '())) ;list of string (resolv-file dnsmasq-configuration-resolv-file (default "/etc/resolv.conf")) ;string (no-resolv? dnsmasq-configuration-no-resolv? @@ -803,7 +835,13 @@ (define-record-type* <dnsmasq-configuration> (tftp-root dnsmasq-tftp-root (default "/var/empty,lo")) ;string (tftp-unique-root dnsmasq-tftp-unique-root - (default #f))) ;"" or "ip" or "mac" + (default #f)) ;"" or "ip" or "mac" + (conf-file dnsmasq-configuration-conf-file + (default '())) ;list of string|file-like + (conf-dir dnsmasq-configuration-conf-dir + (default #f)) ;string|file-like + (extra-options dnsmasq-configuration-extra-options + (default '()))) ;list of string (define (warn-deprecated-dnsmasq-configuration-provision value) (when (pair? value) @@ -818,6 +856,7 @@ (define (dnsmasq-shepherd-service config) provision shepherd-provision shepherd-requirement + pid-file no-hosts? port local-service? listen-addresses resolv-file no-resolv? @@ -829,7 +868,8 @@ (define (dnsmasq-shepherd-service config) tftp-single-port? tftp-secure? tftp-max tftp-mtu tftp-no-blocksize? tftp-lowercase? tftp-port-range - tftp-root tftp-unique-root extra-options) + tftp-root tftp-unique-root + conf-file conf-dir extra-options) (shepherd-service (provision (or provision shepherd-provision)) (requirement shepherd-requirement) @@ -838,7 +878,7 @@ (define (dnsmasq-shepherd-service config) (list #$(file-append package "/sbin/dnsmasq") "--keep-in-foreground" - "--pid-file=/run/dnsmasq.pid" + (string-append "--pid-file=" #$pid-file) #$@(if no-hosts? '("--no-hosts") '()) @@ -909,8 +949,14 @@ (define (dnsmasq-shepherd-service config) (format #f "--tftp-unique-root=~a" tftp-unique-root) (format #f "--tftp-unique-root"))) '()) + #$@(map (lambda (conf-file) + #~(string-append "--conf-file=" #$conf-file)) + conf-file) + #$@(if conf-dir + (list #~(string-append "--conf-dir=" #$conf-dir)) + '()) #$@extra-options) - #:pid-file "/run/dnsmasq.pid")) + #:pid-file #$pid-file)) (stop #~(make-kill-destructor))))) (define (dnsmasq-activation config) -- 2.49.0
gabriel <at> erlikon.ch, ludo <at> gnu.org, maxim.cournoyer <at> gmail.com, guix-patches <at> gnu.org
:bug#77204
; Package guix-patches
.
(Thu, 08 May 2025 17:51:03 GMT) Full text and rfc822 format available.Message #68 received at 77204 <at> debbugs.gnu.org (full text, mbox):
From: Alexey Abramov <levenson <at> mmer.org> To: 77204 <at> debbugs.gnu.org Subject: [PATCH v4 3/3] services: dnsmasq: Add stats and reload shepherd actions. Date: Thu, 8 May 2025 19:47:43 +0200
* gnu/services/dns.scm (dnsmasq-service-reload-action): New function. Implements SIGHUP handling for reloading configurations. (dnsmasq-service-stats-action): New function. Implements SIGUSR1 handling for dumping statistics. (dnsmasq-shepherd-service): Use new actions. * doc/guix.texi: Document new actions with examples. * gnu/tests/networking.scm (%test-dnsmasq): Add tests to verify the functionality of new actions. --- doc/guix.texi | 52 +++++++++++++++++++++ gnu/services/dns.scm | 22 +++++++++ gnu/tests/networking.scm | 98 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+) diff --git a/doc/guix.texi b/doc/guix.texi index ec096643eaa..fa34eb4a8bc 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -36077,6 +36077,58 @@ DNS Services (no-resolv? #t) (servers '("192.168.1.1")))) @end lisp + +@code{dnsmasq-service-type} provides two actions: + +@table @code +@item reload +Send a @code{SIGHUP} signal to @command{dnsmasq} to clear cache and +reload hosts files which triggers the following actions: + +@itemize @bullet +@item +Clears the DNS cache +@item +Reloads @file{/etc/hosts} and @file{/etc/ethers} +@item +Reloads files specified by @option{--dhcp-hostsfile}, @option{--dhcp-hostsdir}, +@option{--dhcp-optsfile}, @option{--dhcp-optsdir}, @option{--addn-hosts}, +or @option{--hostsdir} +@item +Executes DHCP lease change scripts for all existing leases +@item +Rereads @file{/etc/resolv.conf} (only if @option{--no-poll} is configured) +@end itemize + +@emph{Note:} The @code{SIGHUP} signal does not trigger a reread of the main +configuration file. + +Example usage: +@example +herd reload dnsmasq +@end example + +@item stats +When @command{dnsmasq} receives a @code{SIGUSR1} signal, it writes +statistics to the system log including: + +@itemize @bullet +@item +Cache size and number of evicted entries +@item +Cache hits, misses, and authoritative queries answered +@item +For each upstream server: queries sent and errors received +@item +TCP connection fork statistics +@end itemize + +Example usage: +@example +herd stats dnsmasq +@end example +@end table + @end defvar @deftp {Data Type} dnsmasq-configuration diff --git a/gnu/services/dns.scm b/gnu/services/dns.scm index d55ee3e4fcb..9a9b78d877b 100644 --- a/gnu/services/dns.scm +++ b/gnu/services/dns.scm @@ -874,6 +874,8 @@ (define (dnsmasq-shepherd-service config) (provision (or 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") @@ -965,6 +967,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 <dnsmasq-configuration> () + (shepherd-action + (name 'reload) + (documentation "Send a @code{SIGHUP} signal to @command{dnsmasq} to clear +cache and reload hosts files.") + (procedure #~(lambda (running) + (let ((pid (process-id running))) + (kill pid SIGHUP))))))) + +(define (dnsmasq-service-stats-action config) + (match-record config <dnsmasq-configuration> () + (shepherd-action + (name 'stats) + (documentation "Send a @code{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 -- 2.49.0
Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
:Alexey Abramov <levenson <at> mmer.org>
:Message #73 received at 77204-done <at> debbugs.gnu.org (full text, mbox):
From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com> To: Alexey Abramov <levenson <at> mmer.org> Cc: 77204-done <at> debbugs.gnu.org, Ludovic Courtès <ludo <at> gnu.org>, Gabriel Wicki <gabriel <at> erlikon.ch> Subject: Re: [bug#77204] [PATCH v4 0/3] dnsmasq service changes Date: Fri, 16 May 2025 22:04:05 +0900
Hi Alexey! Alexey Abramov <levenson <at> mmer.org> writes: > Thank you, Maxim, for your thorough review. With v4 I did address all > your suggestions (I hope I didn't miss anything ;)). Thank you! > I had an impression that `M-q' would do a proper formating of > sentences, but apparently `sentence-end-double-space' is a hint to > just break lines. Am i missing something? That's what it does for me. I do use paredit-mode, which rebinds this to paredit-reindent-defun. > Regarding the commit messages, I kinda used to go to diff in magit and > press `C' on a hunk and it does add things to the commit message. I > did check git log and see people use different ways like (), [] and > <>. Seems like a more personal stuff, but I would like to know > more... You are right that there are various preferences/dialect in use. [ ] are documented as for conditional changes, but we use that in Guix to denote record's fields. (info "(standards) Style of Change Logs") has more examples about it. Some people like to preserve the hierarchy of things, e.g. --8<---------------cut here---------------start------------->8--- [arguments] <#:phases>: Add X phases. --8<---------------cut here---------------end--------------->8--- Some others prefer to flatten things a bit: --8<---------------cut here---------------start------------->8--- [phases] {patch-commands}: New phase. --8<---------------cut here---------------end--------------->8--- Both are acceptable in my opinion, as long as it is unambiguous. > With these v4 series: > > - I moved documentation of actions to the manual and not in the action > procedures themselves. herd doc prints texi markups as is. > > - I removed indentation of fields. Sounds good. I've done a few light touch ups/rewording in the change logs/documentation, such as: > Alexey Abramov (3): > services: dnsmasq: Add shepherd-provision and shepherd-requirement > fields. > services: dnsmasq: Add pid-file, conf-file and conf-dir configuration > fields. --8<---------------cut here---------------start------------->8--- modified doc/guix.texi @@ -36305,16 +36305,14 @@ DNS Services network or obtained a DHCP lease from dnsmasq. @item @code{conf-file} (default: @code{'()}) -Specify a configuration file or multiple. The given value should be a -list of string paths to the configuration files. File-like objects are -also supported. +File names of configuration files to use. Strings and file-like objects +are accepted. @item @code{conf-dir} (default: @code{#f}) Read all the files in the given directory as configuration files. -@command{dnsmasq} also supports extensions for the field, but here it is -not implemented. It is more convenient to make @code{computed-file} -directory in the store and use that. Files are loaded in alphabetical -order of filename. +Support for @command{dnsmasq} field extensions is not implemented; users +can use @code{computed-file} to build a directory of files instead. The +configuration files are loaded in alphabetical order of file name. @item @code{extra-options} (default: @code{'()}) This option provides an ``escape hatch'' for the user to provide arbitrary --8<---------------cut here---------------end--------------->8--- > services: dnsmasq: Add stats and reload shepherd actions. --8<---------------cut here---------------start------------->8--- modified doc/guix.texi @@ -36121,21 +36121,24 @@ DNS Services @itemize @bullet @item -Clears the DNS cache +Clear the DNS cache @item -Reloads @file{/etc/hosts} and @file{/etc/ethers} +Reload @file{/etc/hosts} and @file{/etc/ethers} @item -Reloads files specified by @option{--dhcp-hostsfile}, @option{--dhcp-hostsdir}, +Reload files specified by @option{--dhcp-hostsfile}, @option{--dhcp-hostsdir}, @option{--dhcp-optsfile}, @option{--dhcp-optsdir}, @option{--addn-hosts}, or @option{--hostsdir} @item -Executes DHCP lease change scripts for all existing leases +Execute DHCP lease change scripts for all existing leases @item -Rereads @file{/etc/resolv.conf} (only if @option{--no-poll} is configured) +Reread @file{/etc/resolv.conf} (only if @option{--no-poll} is +configured). @end itemize -@emph{Note:} The @code{SIGHUP} signal does not trigger a reread of the main +@quotation Note +The @code{SIGHUP} signal does not trigger a reload of the main configuration file. +@end quotation Example usage: @example @@ -36154,7 +36157,7 @@ DNS Services @item For each upstream server: queries sent and errors received @item -TCP connection fork statistics +TCP connection fork statistics. @end itemize Example usage: modified gnu/tests/networking.scm @@ -680,7 +680,7 @@ (define %test-dhcpd ;;; -;;; dnsmasq tests +;;; dnsmasq tests. ;;; --8<---------------cut here---------------end--------------->8--- And pushed! Thank you! -- Maxim
Debbugs Internal Request <help-debbugs <at> gnu.org>
to internal_control <at> debbugs.gnu.org
.
(Sat, 14 Jun 2025 11:24:05 GMT) Full text and rfc822 format available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.