From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gLbeY-0002fU-3L for guix-patches@gnu.org; Sat, 10 Nov 2018 17:22:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gLbcm-0008SA-74 for guix-patches@gnu.org; Sat, 10 Nov 2018 17:21:06 -0500 Received: from debbugs.gnu.org ([208.118.235.43]:40870) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gLbck-0008QI-MV for guix-patches@gnu.org; Sat, 10 Nov 2018 17:21:03 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1gLbck-0005PU-C8 for guix-patches@gnu.org; Sat, 10 Nov 2018 17:21:02 -0500 Subject: [bug#33265] [WIP RFC v4] services: Add file system monitoring service. Resent-Message-ID: From: ludo@gnu.org (Ludovic =?UTF-8?Q?Court=C3=A8s?=) References: <20181105035122.4359-1-dannym@scratchpost.org> <20181105094109.21915-1-dannym@scratchpost.org> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+kyle=kyleam.com@gnu.org Sender: "Guix-patches" To: Danny Milosavljevic Cc: 33265@debbugs.gnu.org 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.