From debbugs-submit-bounces@debbugs.gnu.org Sat Nov 10 17:20:03 2018 Received: (at 33265) by debbugs.gnu.org; 10 Nov 2018 22:20:03 +0000 Received: from localhost ([127.0.0.1]:45128 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gLbbn-0005NX-0U for submit@debbugs.gnu.org; Sat, 10 Nov 2018 17:20:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60803) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gLbbl-0005Mx-F5 for 33265@debbugs.gnu.org; Sat, 10 Nov 2018 17:20:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLbbf-0006m3-BS for 33265@debbugs.gnu.org; Sat, 10 Nov 2018 17:19:56 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=disabled version=3.3.2 Received: from fencepost.gnu.org ([2001:4830:134:3::e]:36900) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLbbf-0006ls-7C; Sat, 10 Nov 2018 17:19:55 -0500 Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=34640 helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1gLbbe-0007di-Vi; Sat, 10 Nov 2018 17:19:55 -0500 From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) To: Danny Milosavljevic Subject: Re: [bug#33265] [WIP RFC v4] services: Add file system monitoring service. References: <20181105035122.4359-1-dannym@scratchpost.org> <20181105094109.21915-1-dannym@scratchpost.org> X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 20 Brumaire an 227 de la =?utf-8?Q?R=C3=A9volution?= X-PGP-Key-ID: 0x090B11993D9AEBB5 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 3CE4 6455 8A84 FDC6 9DB4 0CFB 090B 1199 3D9A EBB5 X-OS: x86_64-pc-linux-gnu Date: Sat, 10 Nov 2018 23:19:53 +0100 In-Reply-To: <20181105094109.21915-1-dannym@scratchpost.org> (Danny Milosavljevic's message of "Mon, 5 Nov 2018 10:41:09 +0100") Message-ID: <87a7mgwp6e.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: 33265 Cc: 33265@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -6.0 (------) Hello! Danny Milosavljevic skribis: > * gnu/services/monitoring.scm (file-system-monitoring-configuration): New > variable. > (file-system-monitoring-entry): New variable. > (file-system-monitoring-service-type): New variable. > * gnu/tests/monitoring.scm (%test-file-system-monitoring): New variable. > * doc/guix.texi (File System Monitoring Service): New subsubsection. Nice! Should we call it =E2=80=98fswatch-monitoring-service=E2=80=99, sinc= e there may be other tools to achieve similar results? > +@cindex file system monitoring > +@subsubheading File System Monitoring Service > + > +The @code{(gnu services monitoring)} module provides a shepherd service = to s/shepherd/Shepherd/ > +@defvr {Scheme Variable} file-system-monitoring-service-type > +The service type for @command{fswatch}, which provides the file system > +monitoring capability. Perhaps add a @uref to the fswatch home page. > +@example > +(service file-system-monitoring-service-type > + (file-system-monitoring-configuration > + (monitored-files '("/foo/bar")) > + (handlers '((lambda args > + (display "UH OH\n")))))) It would seem more natural to me for =E2=80=98handlers=E2=80=99 to be singu= lar, =E2=80=98handler=E2=80=99. Also I=E2=80=99d use a gexp there (though in th= is particular example it doesn=E2=80=99t make any difference): (file-system-monitoring-configuration (monitored-files '("/foo/bar")) (handler #~(lambda (file whatever) (format #t "~a modified!~%" file)))) > + (start #~(let ((handlers > + (list #$@(map file-system-monitoring-entry-ha= ndler > + monitored-files)))) > + (lambda () > + (sleep 1) > + (for-each (lambda (handler) > + (handler)) > + handlers) > + (fork+exec-command > + `(#$(file-append package "/bin/fswatch") > + "--one-event" > + "-l" "1" ; latency: 1 s > + ; "-d" > + "--" > + #$@(if monitored-files > + (map file-system-monitoring-entry-file= -name > + monitored-files) > + '("/does_not_exist"))))))) The =E2=80=98sleep=E2=80=99 call looks suspicious. :-) IIUC, the service stops (and is respawned) every time an even occurs, is that right? Can=E2=80=99t we instead remove =E2=80=98--one-event=E2=80=99 and pass fswa= tch a script to run? In that case, we=E2=80=99d pass it something along these lines: #$(scheme-file "event-handler.scm" #~(for-each (lambda (handler) =E2=80=A6) =E2=80=A6)) WDYT? > +(define file-system-monitoring-service-type > + (service-type (name 'monitor-file-system) > + (extensions > + (list (service-extension shepherd-root-service-type > + file-system-monitoring-shepher= d-services))) > + (compose concatenate) > + (extend (lambda (config monitored-entries) > + (let ((monitored-files > + (map file-system-monitoring-entry-file-= name > + monitored-entries)) > + (handlers > + (map file-system-monitoring-entry-handl= er > + monitored-entries))) So here if we changes =E2=80=98handlers=E2=80=99 to =E2=80=98handler=E2=80= =99, we could do: (apply compose (map file-system-monitoring-entry-handler entries)) Thanks, Ludo=E2=80=99.