GNU bug report logs - #33265
[WIP RFC] services: Add file system monitor service.

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: guix-patches; Reported by: Danny Milosavljevic <dannym@HIDDEN>; dated Mon, 5 Nov 2018 03:19:02 UTC; Maintainer for guix-patches is guix-patches@HIDDEN.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 11 Nov 2018 12:30:59 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Nov 11 07:30:59 2018
Received: from localhost ([127.0.0.1]:45369 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gLotH-0003YH-IA
	for submit <at> debbugs.gnu.org; Sun, 11 Nov 2018 07:30:59 -0500
Received: from dd26836.kasserver.com ([85.13.145.193]:40602)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dannym@HIDDEN>) id 1gLotG-0003WZ-9b
 for 33265 <at> debbugs.gnu.org; Sun, 11 Nov 2018 07:30:58 -0500
Received: from localhost (178.112.134.117.wireless.dyn.drei.com
 [178.112.134.117])
 by dd26836.kasserver.com (Postfix) with ESMTPSA id 9D82C3366D15;
 Sun, 11 Nov 2018 13:30:56 +0100 (CET)
Date: Sun, 11 Nov 2018 13:30:52 +0100
From: Danny Milosavljevic <dannym@HIDDEN>
To: ludo@HIDDEN (Ludovic =?ISO-8859-1?Q?Court=E8s?=)
Subject: Re: [bug#33265] [WIP RFC v4] services: Add file system monitoring
 service.
Message-ID: <20181111133052.4c4dfbe4@HIDDEN>
In-Reply-To: <87wopjua86.fsf@HIDDEN>
References: <20181105035122.4359-1-dannym@HIDDEN>
 <20181105094109.21915-1-dannym@HIDDEN>
 <87a7mgwp6e.fsf@HIDDEN> <20181111011218.00265d2f@HIDDEN>
 <87wopjua86.fsf@HIDDEN>
X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-unknown-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha256;
 boundary="Sig_/RtPw24zf5Tk_XV7vchc5CgP"; protocol="application/pgp-signature"
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 33265
Cc: 33265 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

--Sig_/RtPw24zf5Tk_XV7vchc5CgP
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi Ludo,

On Sun, 11 Nov 2018 12:25:45 +0100
ludo@HIDDEN (Ludovic Court=C3=A8s) wrote:

> > registered - see the "/does_not_exist" workaround) rapid fswatch invoca=
tions
> > would waste (potentially enormous amounts of) cpu time and would
> > forkbomb fswatch, shepherd and/or worse things.  On the other hand, usi=
ng
> > fswatch like we do now causes us to lose events.  But so does starting =
fswatch
> > later than the clients.  And most fswatch backends (for example the Lin=
ux one)
> > can lose events anyway (since the kernel buffer is limited - Linux will=
 then
> > drop events).  That's why it always calls the handlers when restarting =
- just
> > in case. =20
>=20
> Uh, not very confidence-inspiring.  ;-)

Yeah well, file change notification is surprisingly crappy - especially when
you want it to *always* work.  On the other hand typical UNIX :)

> OK that works, but I=E2=80=99m not very comfortable with the approach: no=
rmally
> respawns indicate that the service failed unexpectedly, so here we=E2=80=
=99re
> really abusing the mechanism IMO.

I agree.  In the end it would be nicer to get the pipe thing to work or
better yet to have libfswatch bindings or better yet use direvent, aha.

> Another option would be to use Direvent, which supports this and more,

Aha, that looks as if it's intended exactly for this use case!  Nice!

I'll try that one next.

> or maybe =E2=80=98inotifywatch=E2=80=99 from inotify-tools though it seem=
s to be quite
> similar to fswatch feature-wise.

inotifywatch is Linux-specific.  If we want Guix to support the Hurd, BSD,
Windows then it shouldn't be using Linux-specific things.  Also, it uses
the same stuff as fswatch under the hood so it has the same limitations.

--Sig_/RtPw24zf5Tk_XV7vchc5CgP
Content-Type: application/pgp-signature
Content-Description: OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlvoIPwACgkQ5xo1VCww
uqX9vAf8C5cMYvz7JuLNPZF/0swUq1xgGuoBWdRyXDSreNEZ6elMrndI0D/Dahn0
7uTqZQcgNV25kWJ3fjMMCEFW1/ft66Lo08hACuxqWVPKr8VVM+XTPO4enr+SmYcM
WbwXl0CYJYNOe+NZHNJvrvmSZWaXhcEbawL70EPJfPXTJrxRFcrpo8w1qhFjR5Kg
bvF+6VTzcsqzkc05zV7XfLHqlOUvaEBhIYT39AbFychwv0yCY5F0BaGBX8JweXo9
cFRSK7xk3wiKpLMPEL0LYsufJBvcEOkEfg072fUZ7emO/GS7bWF+Ap/3hgP8HcLu
h1h4gjxbiRi6+7RH5Qx4zkQqd6C3tA==
=BGCc
-----END PGP SIGNATURE-----

--Sig_/RtPw24zf5Tk_XV7vchc5CgP--




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 11 Nov 2018 11:26:03 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Nov 11 06:26:03 2018
Received: from localhost ([127.0.0.1]:45340 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gLnsR-0001Db-2F
	for submit <at> debbugs.gnu.org; Sun, 11 Nov 2018 06:26:03 -0500
Received: from eggs.gnu.org ([208.118.235.92]:45140)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ludo@HIDDEN>) id 1gLnsP-0001D7-40
 for 33265 <at> debbugs.gnu.org; Sun, 11 Nov 2018 06:26:01 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <ludo@HIDDEN>) id 1gLnsG-0001jT-A5
 for 33265 <at> debbugs.gnu.org; Sun, 11 Nov 2018 06:25:54 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_05 autolearn=disabled
 version=3.3.2
Received: from fencepost.gnu.org ([2001:4830:134:3::e]:45794)
 by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from <ludo@HIDDEN>)
 id 1gLnsF-0001hs-Oh; Sun, 11 Nov 2018 06:25:52 -0500
Received: from [2a01:e0a:1d:7270:af76:b9b:ca24:c465] (port=59694 helo=ribbon)
 by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256)
 (Exim 4.82) (envelope-from <ludo@HIDDEN>)
 id 1gLnsA-0002G2-Kt; Sun, 11 Nov 2018 06:25:49 -0500
From: ludo@HIDDEN (Ludovic =?utf-8?Q?Court=C3=A8s?=)
To: Danny Milosavljevic <dannym@HIDDEN>
Subject: Re: [bug#33265] [WIP RFC v4] services: Add file system monitoring
 service.
References: <20181105035122.4359-1-dannym@HIDDEN>
 <20181105094109.21915-1-dannym@HIDDEN>
 <87a7mgwp6e.fsf@HIDDEN> <20181111011218.00265d2f@HIDDEN>
X-URL: http://www.fdn.fr/~lcourtes/
X-Revolutionary-Date: 21 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: Sun, 11 Nov 2018 12:25:45 +0100
In-Reply-To: <20181111011218.00265d2f@HIDDEN> (Danny Milosavljevic's
 message of "Sun, 11 Nov 2018 01:12:18 +0100")
Message-ID: <87wopjua86.fsf@HIDDEN>
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 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -6.0 (------)

Hello!

Danny Milosavljevic <dannym@HIDDEN> skribis:

> On Sat, 10 Nov 2018 23:19:53 +0100
> ludo@HIDDEN (Ludovic Court=C3=A8s) wrote:
>
>> Nice!  Should we call it =E2=80=98fswatch-monitoring-service=E2=80=99, s=
ince there may
>> be other tools to achieve similar results?
>
> Its use is mostly to allow other Guix services to extend it in order to
> do stuff on file change (for example restarting a service; starting the
> user shepherd - the latter is what caused me to write this).
>
> I was very much tempted to call it "fswatch-monitoring-service", but that=
's
> really an implementation detail - what it does is provide file change
> notification services to other Guix services.
>
> It's not meant to be a generic fswatch service.  I've not known fswatch
> before writing this service - so it's pretty likely that there are tons
> more features an fswatch user could want to use which the service doesn't
> provide.  Also, fswatch isn't really meant to be used as a daemon AFAIK,
> so we are not providing fswatch to the user in the way it's supposed to be
> used by him.

OK, that makes sense.

>> The =E2=80=98sleep=E2=80=99 call looks suspicious.  :-)
>
> Pretty suspicious :)
>
> Right now, the service has only a very narrow usecase where rapid
> notifications is not something one wants.  On the contrary, both rapid
> notifications and (in a pathological case where a watch couldn't be
> registered - see the "/does_not_exist" workaround) rapid fswatch invocati=
ons
> would waste (potentially enormous amounts of) cpu time and would
> forkbomb fswatch, shepherd and/or worse things.  On the other hand, using
> fswatch like we do now causes us to lose events.  But so does starting fs=
watch
> later than the clients.  And most fswatch backends (for example the Linux=
 one)
> can lose events anyway (since the kernel buffer is limited - Linux will t=
hen
> drop events).  That's why it always calls the handlers when restarting - =
just
> in case.

Uh, not very confidence-inspiring.  ;-)

>> IIUC, the service stops (and is respawned) every time an even[t] occurs,=
 is
>> that right?
>
> Yes.  It's very simple :)

OK that works, but I=E2=80=99m not very comfortable with the approach: norm=
ally
respawns indicate that the service failed unexpectedly, so here we=E2=80=99=
re
really abusing the mechanism IMO.

>> Can=E2=80=99t we instead remove =E2=80=98--one-event=E2=80=99 and pass f=
swatch a script to run?
>
> Not to my knowledge.  It would be nice...

Another option would be to use Direvent, which supports this and more,
or maybe =E2=80=98inotifywatch=E2=80=99 from inotify-tools though it seems =
to be quite
similar to fswatch feature-wise.

WDYT?

Ludo=E2=80=99.




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 11 Nov 2018 00:16:03 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 10 19:16:03 2018
Received: from localhost ([127.0.0.1]:45190 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gLdQ3-0001op-JO
	for submit <at> debbugs.gnu.org; Sat, 10 Nov 2018 19:16:03 -0500
Received: from dd26836.kasserver.com ([85.13.145.193]:37498)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dannym@HIDDEN>) id 1gLdQ2-0001oK-5r
 for 33265 <at> debbugs.gnu.org; Sat, 10 Nov 2018 19:16:02 -0500
Received: from localhost (178.112.134.117.wireless.dyn.drei.com
 [178.112.134.117])
 by dd26836.kasserver.com (Postfix) with ESMTPSA id 4311B3362362;
 Sun, 11 Nov 2018 01:16:01 +0100 (CET)
Date: Sun, 11 Nov 2018 01:15:59 +0100
From: Danny Milosavljevic <dannym@HIDDEN>
To: =?ISO-8859-1?Q?Cl=E9ment?= Lassieur <clement@HIDDEN>
Subject: Re: [bug#33265] [WIP RFC] services: Add file system monitor service.
Message-ID: <20181111011559.37e42901@HIDDEN>
In-Reply-To: <87pnvjn9xb.fsf@HIDDEN>
References: <20181105031833.7917-1-dannym@HIDDEN>
 <87pnvjn9xb.fsf@HIDDEN>
X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-unknown-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha256;
 boundary="Sig_/vQkYw61syGxTSO3YBaDUmQz"; protocol="application/pgp-signature"
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 33265
Cc: 33265 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

--Sig_/vQkYw61syGxTSO3YBaDUmQz
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi Cl=C3=A9ment,

On Mon, 05 Nov 2018 10:36:00 +0100
Cl=C3=A9ment Lassieur <clement@HIDDEN> wrote:

> Danny Milosavljevic <dannym@HIDDEN> writes:
>=20
> > +          (test-assert "file system monitor running"
> > +            (marionette-eval
> > +             '(begin
> > +                (use-modules (gnu services herd))
> > +                (match (start-service 'monitor-file-system)
> > +                  (#f #f)
> > +                  (('service response-parts ...)
> > +                   (match (assq-ref response-parts 'running)
> > +                     ((pid) (number? pid))))))
> > +             marionette)) =20
>=20
> How is that better than:

It's not!  Replaced.  Thanks.

--Sig_/vQkYw61syGxTSO3YBaDUmQz
Content-Type: application/pgp-signature
Content-Description: OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlvndL8ACgkQ5xo1VCww
uqVx8Af/RxpQwVycvnTG9LzunqYLLDYQtyMMHYxnCxGB1tU2bkhmWnVZALgVMTqb
ZTkqYVwgkwS/TJYUxzO84Mp85RX+QxA2jquRP51yHrE4r7pw1kMXoLiWYz4EwJDs
C8Q5SdfxsfZo05+NROJiZpwIEsXFJuyawdOKujECu83HyBhJI0FL/+aGvNgNTPL8
EMUiSCp1A9QyMn9tlXIpyspF6TWr3eAcn2bQHwRnUeA1Zev1V6TRm0VGZ2q1Jdt7
DUafBAxWsJk0DziR3ehigc74Gll/hfBc40oaY6dAl//KjF0GAyTz1XXxpMsk/bZb
RUmyIL/y9sDhr276vCluIs8bqOnGZw==
=KR8+
-----END PGP SIGNATURE-----

--Sig_/vQkYw61syGxTSO3YBaDUmQz--




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 11 Nov 2018 00:13:54 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 10 19:13:54 2018
Received: from localhost ([127.0.0.1]:45182 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gLdNy-0001kQ-0V
	for submit <at> debbugs.gnu.org; Sat, 10 Nov 2018 19:13:54 -0500
Received: from dd26836.kasserver.com ([85.13.145.193]:37352)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dannym@HIDDEN>) id 1gLdNw-0001kI-KG
 for 33265 <at> debbugs.gnu.org; Sat, 10 Nov 2018 19:13:52 -0500
Received: from localhost (178.112.134.117.wireless.dyn.drei.com
 [178.112.134.117])
 by dd26836.kasserver.com (Postfix) with ESMTPSA id A45B43362362;
 Sun, 11 Nov 2018 01:13:51 +0100 (CET)
Date: Sun, 11 Nov 2018 01:13:50 +0100
From: Danny Milosavljevic <dannym@HIDDEN>
To: ludo@HIDDEN (Ludovic =?ISO-8859-1?Q?Court=E8s?=)
Subject: Re: [bug#33265] [WIP RFC v4] services: Add file system monitoring
 service.
Message-ID: <20181111011350.4b6960a7@HIDDEN>
In-Reply-To: <20181111011218.00265d2f@HIDDEN>
References: <20181105035122.4359-1-dannym@HIDDEN>
 <20181105094109.21915-1-dannym@HIDDEN>
 <87a7mgwp6e.fsf@HIDDEN> <20181111011218.00265d2f@HIDDEN>
X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-unknown-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha256;
 boundary="Sig_/m_FLDS47S7GLYxI/bXC.5hh"; protocol="application/pgp-signature"
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 33265
Cc: 33265 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

--Sig_/m_FLDS47S7GLYxI/bXC.5hh
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: quoted-printable

> drop events).  That's why it always calls the handlers when restarting - =
just
> in case.

That's why *WE* always calls the handlers when restarting - just in case.

--Sig_/m_FLDS47S7GLYxI/bXC.5hh
Content-Type: application/pgp-signature
Content-Description: OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlvndD4ACgkQ5xo1VCww
uqXKXQf+KutvLzmQwfWDx2gEdq5z5GGzvBrhss3Hi2LCavQAVqadbYSD8wPhY31/
8K0PkUGlCYVshrFe9Eb38zBuSQNbEs80V5PJMxIPhGz/QK68YcqtH5+MYMhNFYvb
d9JsWl0fXpUI9jPPqQUvZBY+1ieZWNRXPtp5snG4AHFdb8B6NELkcoEhUa4/sGBr
A7d7ndwHjUvJsqZBOXfDkNgOtfqJDOUyRU46H0EqvfnWF6B/B9fyVlGptKWyiX+U
EWpX3W5kmCRxIjUzvsZyi3I/nw54YsQOFLKEP/KKv3Y9+ls55MjGtSj9uvTFttxq
+GgiInUs0Ms6/L/BRDP0IyGf7OG/mA==
=/4fA
-----END PGP SIGNATURE-----

--Sig_/m_FLDS47S7GLYxI/bXC.5hh--




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 11 Nov 2018 00:12:27 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 10 19:12:27 2018
Received: from localhost ([127.0.0.1]:45176 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gLdMY-0001iD-5D
	for submit <at> debbugs.gnu.org; Sat, 10 Nov 2018 19:12:27 -0500
Received: from dd26836.kasserver.com ([85.13.145.193]:37248)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dannym@HIDDEN>) id 1gLdMW-0001i3-Gj
 for 33265 <at> debbugs.gnu.org; Sat, 10 Nov 2018 19:12:25 -0500
Received: from localhost (178.112.134.117.wireless.dyn.drei.com
 [178.112.134.117])
 by dd26836.kasserver.com (Postfix) with ESMTPSA id DA30233600C4;
 Sun, 11 Nov 2018 01:12:22 +0100 (CET)
Date: Sun, 11 Nov 2018 01:12:18 +0100
From: Danny Milosavljevic <dannym@HIDDEN>
To: ludo@HIDDEN (Ludovic =?ISO-8859-1?Q?Court=E8s?=)
Subject: Re: [bug#33265] [WIP RFC v4] services: Add file system monitoring
 service.
Message-ID: <20181111011218.00265d2f@HIDDEN>
In-Reply-To: <87a7mgwp6e.fsf@HIDDEN>
References: <20181105035122.4359-1-dannym@HIDDEN>
 <20181105094109.21915-1-dannym@HIDDEN>
 <87a7mgwp6e.fsf@HIDDEN>
X-Mailer: Claws Mail 3.17.1 (GTK+ 2.24.32; x86_64-unknown-linux-gnu)
MIME-Version: 1.0
Content-Type: multipart/signed; micalg=pgp-sha256;
 boundary="Sig_/Lm4kdR_+F8Dvvd+1pNpGWLJ"; protocol="application/pgp-signature"
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 33265
Cc: 33265 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

--Sig_/Lm4kdR_+F8Dvvd+1pNpGWLJ
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable

Hi Ludo!

On Sat, 10 Nov 2018 23:19:53 +0100
ludo@HIDDEN (Ludovic Court=C3=A8s) wrote:

> Nice!  Should we call it =E2=80=98fswatch-monitoring-service=E2=80=99, si=
nce there may
> be other tools to achieve similar results?

Its use is mostly to allow other Guix services to extend it in order to
do stuff on file change (for example restarting a service; starting the
user shepherd - the latter is what caused me to write this).

I was very much tempted to call it "fswatch-monitoring-service", but that's
really an implementation detail - what it does is provide file change
notification services to other Guix services.

It's not meant to be a generic fswatch service.  I've not known fswatch
before writing this service - so it's pretty likely that there are tons
more features an fswatch user could want to use which the service doesn't
provide.  Also, fswatch isn't really meant to be used as a daemon AFAIK,
so we are not providing fswatch to the user in the way it's supposed to be
used by him.

> The =E2=80=98sleep=E2=80=99 call looks suspicious.  :-)

Pretty suspicious :)

Right now, the service has only a very narrow usecase where rapid
notifications is not something one wants.  On the contrary, both rapid
notifications and (in a pathological case where a watch couldn't be
registered - see the "/does_not_exist" workaround) rapid fswatch invocations
would waste (potentially enormous amounts of) cpu time and would
forkbomb fswatch, shepherd and/or worse things.  On the other hand, using
fswatch like we do now causes us to lose events.  But so does starting fswa=
tch
later than the clients.  And most fswatch backends (for example the Linux o=
ne)
can lose events anyway (since the kernel buffer is limited - Linux will then
drop events).  That's why it always calls the handlers when restarting - ju=
st
in case.

> IIUC, the service stops (and is respawned) every time an even[t] occurs, =
is
> that right?

Yes.  It's very simple :)

> Can=E2=80=99t we instead remove =E2=80=98--one-event=E2=80=99 and pass fs=
watch a script to run?

Not to my knowledge.  It would be nice...

What the stuff here does is it waits for events to accumulate in the time
given by "-l" (that is called a "batch" in fswatch).

The first such batch which contains at least one event will cause fswatch
to exit.
Otherwise fswatch will continue waiting (blocking) until the above happens.

It's an explicitly supported way to use fswatch (because it's very resilien=
t).

The service collects all the files from the system into one fswatch
invocation - it's very much supposed to be a tripwire and not something
regularily used.  It also collects all the handlers (regardless of monitored
file) into one handler to be called.

> In that case, we=E2=80=99d pass it something along these lines:
>=20
>   #$(scheme-file "event-handler.scm"
>                  #~(for-each (lambda (handler) =E2=80=A6) =E2=80=A6))
>=20
> WDYT?

I'd like to, but it doesn't support it.

What would be possible is to pipe something at the end (i.e. use open-pipe)=
, but
I've had bad experiences with pipes buffering too much in the past and I'd =
rather
not hang the entire thing by some stupid buffering or parsing problem.

That said, we could try in a future version (after some serious testing).
But I think that trying to use pipes for us to be remote-controlled by
fswatch it will not work correctly if fswatch doesn't exit.

It would work with a pty, but that's kinda... convoluted.  Also, forkpty is=
 not
available in Guile.

There's libfswatch but no Guile bindings yet.  Would be cool to have those
because fswatch is cross platform (and it has C bindings).

> > +(define file-system-monitoring-service-type
> > +  (service-type (name 'monitor-file-system)
> > +                (extensions
> > +                 (list (service-extension shepherd-root-service-type
> > +                                          file-system-monitoring-sheph=
erd-services)))
> > +                (compose concatenate)
> > +                (extend (lambda (config monitored-entries)
> > +                          (let ((monitored-files
> > +                                 (map file-system-monitoring-entry-fil=
e-name
> > +                                      monitored-entries))
> > +                                (handlers
> > +                                 (map file-system-monitoring-entry-han=
dler
> > +                                      monitored-entries))) =20
>=20
> So here if we changes =E2=80=98handlers=E2=80=99 to =E2=80=98handler=E2=
=80=99, we could do:
>=20
>   (apply compose (map file-system-monitoring-entry-handler entries))

All good points!

--Sig_/Lm4kdR_+F8Dvvd+1pNpGWLJ
Content-Type: application/pgp-signature
Content-Description: OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlvnc+IACgkQ5xo1VCww
uqU+qwf/d4DuoZUrTye4TESNL4AuXngUktkQZLQzW2TzIw1a3fsz28fHyIM4AEqY
4RhV09s44RTvtDtpM5Pt7MBfXpZvCgSUhyXD1kd82vq3GPiFRM61yTN6PdEgIkM5
UemzReYEq03NxF3g1hGC5tsxZ/9SctiFyqpQySAQnR/RWsz4ZnkUgYX9eyvLhIwv
Kosxg06JVqTLuBnSyjasPxCTZKKOrmpGZfbZfSgwKL5Y1XaJXSTmJdT/HPOdksm4
GHeZMzy7j+sa8yz1P6Bg1rnBU4RX5sT2IvvuuSQv2XNd5Yk0H2bSZQ/H9XV3hx4J
e07KxHak+RvmRf4Ik1OrydIiqQR/1Q==
=ov4y
-----END PGP SIGNATURE-----

--Sig_/Lm4kdR_+F8Dvvd+1pNpGWLJ--




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 10 Nov 2018 22:20:03 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sat Nov 10 17:20:03 2018
Received: from localhost ([127.0.0.1]:45128 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gLbbn-0005NX-0U
	for submit <at> 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 <ludo@HIDDEN>) id 1gLbbl-0005Mx-F5
 for 33265 <at> 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 <ludo@HIDDEN>) id 1gLbbf-0006m3-BS
 for 33265 <at> 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 <ludo@HIDDEN>)
 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 <ludo@HIDDEN>)
 id 1gLbbe-0007di-Vi; Sat, 10 Nov 2018 17:19:55 -0500
From: ludo@HIDDEN (Ludovic =?utf-8?Q?Court=C3=A8s?=)
To: Danny Milosavljevic <dannym@HIDDEN>
Subject: Re: [bug#33265] [WIP RFC v4] services: Add file system monitoring
 service.
References: <20181105035122.4359-1-dannym@HIDDEN>
 <20181105094109.21915-1-dannym@HIDDEN>
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@HIDDEN> (Danny
 Milosavljevic's message of "Mon, 5 Nov 2018 10:41:09 +0100")
Message-ID: <87a7mgwp6e.fsf@HIDDEN>
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 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -6.0 (------)

Hello!

Danny Milosavljevic <dannym@HIDDEN> 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.




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 5 Nov 2018 09:41:20 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Nov 05 04:41:20 2018
Received: from localhost ([127.0.0.1]:34612 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gJbNn-0001Oy-UB
	for submit <at> debbugs.gnu.org; Mon, 05 Nov 2018 04:41:20 -0500
Received: from dd26836.kasserver.com ([85.13.145.193]:49804)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dannym@HIDDEN>) id 1gJbNm-0001Oq-6t
 for 33265 <at> debbugs.gnu.org; Mon, 05 Nov 2018 04:41:19 -0500
Received: from dayas.3.home (178.112.174.42.wireless.dyn.drei.com
 [178.112.174.42])
 by dd26836.kasserver.com (Postfix) with ESMTPSA id E16E9336072E;
 Mon,  5 Nov 2018 10:41:15 +0100 (CET)
From: Danny Milosavljevic <dannym@HIDDEN>
To: 33265 <at> debbugs.gnu.org
Subject: [WIP RFC v4] services: Add file system monitoring service.
Date: Mon,  5 Nov 2018 10:41:09 +0100
Message-Id: <20181105094109.21915-1-dannym@HIDDEN>
X-Mailer: git-send-email 2.19.0
In-Reply-To: <20181105035122.4359-1-dannym@HIDDEN>
References: <20181105035122.4359-1-dannym@HIDDEN>
MIME-Version: 1.0
Tags: patch
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 33265
Cc: Danny Milosavljevic <dannym@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

* 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.
---
 doc/guix.texi               | 37 ++++++++++++++
 gnu/services/monitoring.scm | 79 +++++++++++++++++++++++++++++-
 gnu/tests/monitoring.scm    | 97 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 211 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 3b7fa50d8..8997a0915 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21496,6 +21496,43 @@ The following is an example @code{dicod-service} configuration.
                     %dicod-database:gcide))))
 @end example
 
+@cindex file system monitoring
+@subsubheading File System Monitoring Service
+
+The @code{(gnu services monitoring)} module provides a shepherd service to
+monitor file system changes and call a handler procedure on changes.
+
+@defvr {Scheme Variable} file-system-monitoring-service-type
+The service type for @command{fswatch}, which provides the file system
+monitoring capability.
+
+@example
+(service file-system-monitoring-service-type
+ (file-system-monitoring-configuration
+   (monitored-files '("/foo/bar"))
+   (handlers '((lambda args
+                 (display "UH OH\n"))))))
+@end example
+@end defvr
+
+@deftp {Data Type} file-system-monitoring-configuration
+The data type representing the configuration of the file-system-monitoring
+service.
+
+@table @asis
+@item @code{package}
+Package containing the actual file system monitor (fswatch).
+
+@item @code{monitored-files}
+List of files to be monitored.
+
+@item @code{handlers}
+List of thunks which will be called once the file system monitor noticed
+changes in the monitored files.
+
+@end table
+@end deftp
+
 @node Setuid Programs
 @subsection Setuid Programs
 
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index aa3b63a0e..a717175c0 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -26,10 +26,14 @@
   #:use-module (guix gexp)
   #:use-module (guix records)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
   #:export (darkstat-configuration
             prometheus-node-exporter-configuration
             darkstat-service-type
-            prometheus-node-exporter-service-type))
+            prometheus-node-exporter-service-type
+            file-system-monitoring-configuration
+            file-system-monitoring-entry
+            file-system-monitoring-service-type))
 
 
 ;;;
@@ -125,3 +129,76 @@ prometheus.")
     (list (service-extension
            shepherd-root-service-type
            (compose list prometheus-node-exporter-shepherd-service))))))
+
+
+;;;
+;;; File System Monitoring
+;;;
+
+(define-record-type* <file-system-monitoring-entry>
+  file-system-monitoring-entry make-file-system-monitoring-entry
+  file-system-monitoring-entry?
+  (file-name file-system-monitoring-entry-file-name)
+  (handler file-system-monitoring-entry-handler))
+
+(define-record-type* <file-system-monitoring-configuration>
+  file-system-monitoring-configuration
+  make-file-system-monitoring-configuration
+  file-system-monitoring-configuration?
+  (package file-system-monitoring-configuration-package
+           (default fswatch))
+  (monitored-files file-system-monitoring-configuration-monitored-files
+                   (default '()))) ; list of <file-system-monitoring-entry>.
+
+(define file-system-monitoring-shepherd-services
+  (match-lambda
+   (($ <file-system-monitoring-configuration> package monitored-files)
+    (list (shepherd-service
+           (provision '(file-system-monitoring))
+           (documentation "File System Monitor")
+           (requirement '(file-systems))
+           (start #~(let ((handlers
+                           (list #$@(map file-system-monitoring-entry-handler
+                                         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")))))))
+            (stop #~(make-kill-destructor))
+            (respawn? #t))))))
+
+(define file-system-monitoring-service-type
+  (service-type (name 'monitor-file-system)
+                (extensions
+                 (list (service-extension shepherd-root-service-type
+                                          file-system-monitoring-shepherd-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-handler
+                                      monitored-entries)))
+                            (match config
+                             (($ <file-system-monitoring-configuration>
+                              package initial-monitored-files)
+                              (file-system-monitoring-configuration
+                               (package package)
+                               (monitored-files (append initial-monitored-files
+                                                        monitored-files))))))))
+                (description
+                 "Call all @dfn{handler}s once something happens with one of
+the files monitored, and on overflow.  Can have false positives.  Will also
+call all @dfn{handlers} on startup.")))
diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm
index 3320a19a7..d2b62374d 100644
--- a/gnu/tests/monitoring.scm
+++ b/gnu/tests/monitoring.scm
@@ -20,10 +20,12 @@
   #:use-module (gnu services)
   #:use-module (gnu services monitoring)
   #:use-module (gnu services networking)
+  ;#:use-module (gnu system)
   #:use-module (gnu system vm)
   #:use-module (gnu tests)
   #:use-module (guix gexp)
-  #:export (%test-prometheus-node-exporter))
+  #:export (%test-prometheus-node-exporter
+            %test-file-system-monitoring))
 
 
 ;;;
@@ -95,3 +97,96 @@
    (description "Connect to a running prometheus-node-exporter server.")
    (value (run-prometheus-node-exporter-server-test
            name %prometheus-node-exporter-os))))
+
+
+;;;
+;;; File System Monitoring.
+;;;
+
+(define* (run-file-system-monitoring-test name test-os)
+  "Run tests in TEST-OS, which has file system monitoring running."
+  (define os
+    (marionette-operating-system
+     test-os
+     #:imported-modules '((gnu services herd))))
+
+  (define vm
+    (virtual-machine
+     (operating-system os)
+     (port-forwardings '())))
+
+  (define test
+    (with-imported-modules '((gnu build marionette))
+      #~(begin
+          (use-modules (srfi srfi-11)
+                       (srfi srfi-64)
+                       (gnu build marionette)
+                       (web client)
+                       (web response))
+
+          (define marionette
+            (make-marionette (list #$vm)))
+
+          (mkdir #$output)
+          (chdir #$output)
+
+          (test-begin #$name)
+
+          (test-assert "file system monitor is running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (match (start-service 'file-system-monitoring)
+                  (#f #f)
+                  (('service response-parts ...)
+                   (match (assq-ref response-parts 'running)
+                     ((pid) (number? pid))))))
+             marionette))
+
+          (test-assert "file system monitor notices file system change"
+            (marionette-eval
+             '(begin
+                ;; Not strictly necessary - but we want to test the actual
+                ;; fswatch invocation and not our own synthetic events, so
+                ;; give fswatch the chance to start up.
+                (sleep 2)
+                (mkdir-p "/tmp/glasshouse")
+                ;; Now we provide a file change.  The monitor should [restart
+                ;; and thus] call all the handlers again.
+                (call-with-output-file "/tmp/glasshouse/notice_me" identity)
+                (and
+                 (let loop ((i 0))
+                   (if (file-exists? "/tmp/glasshouse_noticed")
+                       #t
+                       (if (>= i 10)
+                           #f
+                           (begin
+                             (sleep 1)
+                             (loop (+ i 1))))))
+                 ; assume (file-exists? "/tmp/notice_me")
+                 (>= (stat:mtime (stat "/tmp/glasshouse_noticed"))
+                     (stat:mtime (stat "/tmp/glasshouse/notice_me")))))
+             marionette))
+          (test-end)
+          (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+
+  (gexp->derivation (string-append name "-test") test))
+
+(define %file-system-monitoring-os
+  (simple-operating-system
+   (service file-system-monitoring-service-type
+            (file-system-monitoring-configuration
+             (monitored-files
+              (list
+               (file-system-monitoring-entry
+                (file-name "/tmp/glasshouse")
+                (handler '(lambda _
+                            (call-with-output-file "/tmp/glasshouse_noticed"
+                             identity))))))))))
+
+(define %test-file-system-monitoring
+  (system-test
+   (name "file-system-monitoring")
+   (description "Test file system monitoring event handler.")
+   (value (run-file-system-monitoring-test
+           name %file-system-monitoring-os))))




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 5 Nov 2018 09:36:04 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Nov 05 04:36:04 2018
Received: from localhost ([127.0.0.1]:34603 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gJbIi-0001Ga-1b
	for submit <at> debbugs.gnu.org; Mon, 05 Nov 2018 04:36:04 -0500
Received: from mail.lassieur.org ([83.152.10.219]:42138)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <clement@HIDDEN>) id 1gJbIg-0001Fq-8f
 for 33265 <at> debbugs.gnu.org; Mon, 05 Nov 2018 04:36:02 -0500
Received: from newt (smtp.parrot.biz [62.23.167.188])
 by mail.lassieur.org (OpenSMTPD) with ESMTPSA id 6d554dc1
 (TLSv1.2:ECDHE-RSA-CHACHA20-POLY1305:256:NO); 
 Mon, 5 Nov 2018 09:33:41 +0000 (UTC)
References: <20181105031833.7917-1-dannym@HIDDEN>
User-agent: mu4e 1.0; emacs 26.1
From: =?utf-8?Q?Cl=C3=A9ment?= Lassieur <clement@HIDDEN>
To: Danny Milosavljevic <dannym@HIDDEN>
Subject: Re: [bug#33265] [WIP RFC] services: Add file system monitor service.
In-reply-to: <20181105031833.7917-1-dannym@HIDDEN>
Date: Mon, 05 Nov 2018 10:36:00 +0100
Message-ID: <87pnvjn9xb.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
X-Spam-Score: -0.0 (/)
X-Debbugs-Envelope-To: 33265
Cc: 33265 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.0 (-)

Hi Danny,

I don't have time to do a proper review, but just one comment:

Danny Milosavljevic <dannym@HIDDEN> writes:

> +          (test-assert "file system monitor running"
> +            (marionette-eval
> +             '(begin
> +                (use-modules (gnu services herd))
> +                (match (start-service 'monitor-file-system)
> +                  (#f #f)
> +                  (('service response-parts ...)
> +                   (match (assq-ref response-parts 'running)
> +                     ((pid) (number? pid))))))
> +             marionette))

How is that better than:

    (test-assert "file system monitor running"
      (marionette-eval
       '(begin
         (use-modules (gnu services herd))
         (start-service 'monitor-file-system))
       marionette))

'start-service' should return #f if the service fails to start.

Cheers,
Cl=C3=A9ment




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 5 Nov 2018 09:16:55 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Mon Nov 05 04:16:54 2018
Received: from localhost ([127.0.0.1]:34574 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gJb0A-0000kk-Md
	for submit <at> debbugs.gnu.org; Mon, 05 Nov 2018 04:16:54 -0500
Received: from mx1.riseup.net ([198.252.153.129]:60790)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <swedebugia@HIDDEN>) id 1gJb08-0000kc-Oq
 for 33265 <at> debbugs.gnu.org; Mon, 05 Nov 2018 04:16:53 -0500
Received: from piha.riseup.net (piha-pn.riseup.net [10.0.1.163])
 (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits))
 (Client CN "*.riseup.net",
 Issuer "COMODO RSA Domain Validation Secure Server CA" (verified OK))
 by mx1.riseup.net (Postfix) with ESMTPS id E37701A04C4;
 Mon,  5 Nov 2018 01:16:51 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak;
 t=1541409411; bh=Utax3m1oLwvJvMz8o0eCPlD4SMJpwQB43rE+4poFNuM=;
 h=Subject:To:References:From:Date:In-Reply-To:From;
 b=lpT9J/XBJgw6d7aWmcOYQFjpibCWTwHgXoc+4bJ16u1mc51Zi6s2HON/YiR0W9h46
 yW0RykGWKPYBvMahtLHrhOLbG8N1lMRkpC3HsdAHy8+QplbTHiY4aoYwpQneiFMX3e
 bZqQoUte/0uC8+gV3W3EWcseXuAf8+GU3ELtSS1o=
X-Riseup-User-ID: C5D06669054DF4F2E8FFE4525623EE24AAA0C2DC4F55F232B68E3A1354658238
Received: from [127.0.0.1] (localhost [127.0.0.1])
 by piha.riseup.net with ESMTPSA id E3F1264904;
 Mon,  5 Nov 2018 01:16:50 -0800 (PST)
Subject: Re: [bug#33265] [WIP RFC v3] services: Add file system monitoring
 service.
To: Danny Milosavljevic <dannym@HIDDEN>, 33265 <at> debbugs.gnu.org
References: <20181105034525.8676-1-dannym@HIDDEN>
 <20181105035122.4359-1-dannym@HIDDEN>
From: swedebugia <swedebugia@HIDDEN>
Message-ID: <1facd4f2-7dad-57f6-cbdd-7726ee5f367d@HIDDEN>
Date: Mon, 5 Nov 2018 10:16:48 +0100
MIME-Version: 1.0
In-Reply-To: <20181105035122.4359-1-dannym@HIDDEN>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Content-Language: en-US
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 33265
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

Hi

On 2018-11-05 04:51, Danny Milosavljevic wrote:
> +(define file-system-monitoring-service-type
> +  (service-type (name 'monitor-file-system)
Is a docstring missing here?

-- 
Cheers
Swedebugia





Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 5 Nov 2018 03:51:47 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Nov 04 22:51:47 2018
Received: from localhost ([127.0.0.1]:34495 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gJVvX-0001Tk-DJ
	for submit <at> debbugs.gnu.org; Sun, 04 Nov 2018 22:51:47 -0500
Received: from dd26836.kasserver.com ([85.13.145.193]:50900)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dannym@HIDDEN>) id 1gJVvV-0001Tc-ES
 for 33265 <at> debbugs.gnu.org; Sun, 04 Nov 2018 22:51:46 -0500
Received: from dayas.3.home (178.112.174.42.wireless.dyn.drei.com
 [178.112.174.42])
 by dd26836.kasserver.com (Postfix) with ESMTPSA id 28EA8336072E;
 Mon,  5 Nov 2018 04:51:44 +0100 (CET)
From: Danny Milosavljevic <dannym@HIDDEN>
To: 33265 <at> debbugs.gnu.org
Subject: [WIP RFC v3] services: Add file system monitoring service.
Date: Mon,  5 Nov 2018 04:51:22 +0100
Message-Id: <20181105035122.4359-1-dannym@HIDDEN>
X-Mailer: git-send-email 2.19.0
In-Reply-To: <20181105034525.8676-1-dannym@HIDDEN>
References: <20181105034525.8676-1-dannym@HIDDEN>
MIME-Version: 1.0
Tags: patch
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 33265
Cc: Danny Milosavljevic <dannym@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

* 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.
---
 doc/guix.texi               | 37 +++++++++++++++
 gnu/services/monitoring.scm | 77 +++++++++++++++++++++++++++++-
 gnu/tests/monitoring.scm    | 93 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 205 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 3b7fa50d8..8997a0915 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21496,6 +21496,43 @@ The following is an example @code{dicod-service} configuration.
                     %dicod-database:gcide))))
 @end example
 
+@cindex file system monitoring
+@subsubheading File System Monitoring Service
+
+The @code{(gnu services monitoring)} module provides a shepherd service to
+monitor file system changes and call a handler procedure on changes.
+
+@defvr {Scheme Variable} file-system-monitoring-service-type
+The service type for @command{fswatch}, which provides the file system
+monitoring capability.
+
+@example
+(service file-system-monitoring-service-type
+ (file-system-monitoring-configuration
+   (monitored-files '("/foo/bar"))
+   (handlers '((lambda args
+                 (display "UH OH\n"))))))
+@end example
+@end defvr
+
+@deftp {Data Type} file-system-monitoring-configuration
+The data type representing the configuration of the file-system-monitoring
+service.
+
+@table @asis
+@item @code{package}
+Package containing the actual file system monitor (fswatch).
+
+@item @code{monitored-files}
+List of files to be monitored.
+
+@item @code{handlers}
+List of thunks which will be called once the file system monitor noticed
+changes in the monitored files.
+
+@end table
+@end deftp
+
 @node Setuid Programs
 @subsection Setuid Programs
 
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index aa3b63a0e..c2a0faa88 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -26,10 +26,14 @@
   #:use-module (guix gexp)
   #:use-module (guix records)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
   #:export (darkstat-configuration
             prometheus-node-exporter-configuration
             darkstat-service-type
-            prometheus-node-exporter-service-type))
+            prometheus-node-exporter-service-type
+            file-system-monitoring-configuration
+            file-system-monitoring-entry
+            file-system-monitoring-service-type))
 
 
 ;;;
@@ -125,3 +129,74 @@ prometheus.")
     (list (service-extension
            shepherd-root-service-type
            (compose list prometheus-node-exporter-shepherd-service))))))
+
+
+;;;
+;;; File System Monitoring
+;;;
+
+(define-record-type* <file-system-monitoring-entry>
+  file-system-monitoring-entry make-file-system-monitoring-entry
+  file-system-monitoring-entry?
+  (file-name file-system-monitoring-entry-file-name)
+  (handler file-system-monitoring-entry-handler))
+
+(define-record-type* <file-system-monitoring-configuration>
+  file-system-monitoring-configuration
+  make-file-system-monitoring-configuration
+  file-system-monitoring-configuration?
+  (package file-system-monitoring-configuration-package
+           (default fswatch))
+  (monitored-files file-system-monitoring-configuration-monitored-files
+                   (default '()))
+  ;; Note: These thunks are called in the shepherd environment.
+  (handlers file-system-monitoring-configuration-handlers
+            (default '())))
+
+(define file-system-monitoring-shepherd-services
+  (match-lambda
+   (($ <file-system-monitoring-configuration> package monitored-files handlers)
+    (list (shepherd-service
+           (provision '(file-system-monitoring))
+           (documentation "File System Monitor")
+           (requirement '(file-systems))
+           (start #~(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
+                                monitored-files
+                                '())))))
+            (stop #~(make-kill-destructor))
+            (respawn? #t))))))
+
+(define file-system-monitoring-service-type
+  (service-type (name 'monitor-file-system)
+                (extensions
+                 (list (service-extension shepherd-root-service-type
+                                          file-system-monitoring-shepherd-services)))
+                (compose concatenate)
+                (extend (lambda (config monitored-files-handlers)
+                          (let ((monitored-files
+                                 (map file-system-monitoring-entry-file-name
+                                      monitored-files-handlers))
+                                (handlers
+                                 (map file-system-monitoring-entry-handler
+                                      monitored-files-handlers)))
+                            (match config
+                             (($ <file-system-monitoring-configuration> package initial-monitored-files initial-handlers)
+                              (file-system-monitoring-configuration
+                               (package package)
+                               (monitored-files (append initial-monitored-files monitored-files))
+                               (handlers (append initial-handlers handlers))))))))
+                (description
+                 "Call all @dfn{handlers} once something happens with one of
+the files monitored, and on overflow.  Can have false positives.  Will call
+all @dfn{handlers} on startup.")))
diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm
index 3320a19a7..46364f830 100644
--- a/gnu/tests/monitoring.scm
+++ b/gnu/tests/monitoring.scm
@@ -20,10 +20,12 @@
   #:use-module (gnu services)
   #:use-module (gnu services monitoring)
   #:use-module (gnu services networking)
+  ;#:use-module (gnu system)
   #:use-module (gnu system vm)
   #:use-module (gnu tests)
   #:use-module (guix gexp)
-  #:export (%test-prometheus-node-exporter))
+  #:export (%test-prometheus-node-exporter
+            %test-file-system-monitoring))
 
 
 ;;;
@@ -95,3 +97,92 @@
    (description "Connect to a running prometheus-node-exporter server.")
    (value (run-prometheus-node-exporter-server-test
            name %prometheus-node-exporter-os))))
+
+
+;;;
+;;; File System Monitoring.
+;;;
+
+(define* (run-file-system-monitoring-test name test-os)
+  "Run tests in TEST-OS, which has file system monitoring running."
+  (define os
+    (marionette-operating-system
+     test-os
+     #:imported-modules '((gnu services herd))))
+
+  (define vm
+    (virtual-machine
+     (operating-system os)
+     (port-forwardings '())))
+
+  (define test
+    (with-imported-modules '((gnu build marionette))
+      #~(begin
+          (use-modules (srfi srfi-11)
+                       (srfi srfi-64)
+                       (gnu build marionette)
+                       (web client)
+                       (web response))
+
+          (define marionette
+            (make-marionette (list #$vm)))
+
+          (mkdir #$output)
+          (chdir #$output)
+
+          (test-begin #$name)
+
+          (test-assert "file system monitor running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (match (start-service 'monitor-file-system)
+                  (#f #f)
+                  (('service response-parts ...)
+                   (match (assq-ref response-parts 'running)
+                     ((pid) (number? pid))))))
+             marionette))
+
+          (test-assert "file system monitor notices file system change"
+            (marionette-eval
+             '(begin
+                ;; Not strictly necessary - but we want to test the actual
+                ;; fswatch invocation and not our own synthetic events, so
+                ;; give fswatch the chance to start up.
+                (sleep 2)
+                ;; Now we provide a file change.  The monitor should [restart
+                ;; and thus] call all the handlers again.
+                (call-with-output-file "/tmp/notice_me" identity)
+                (and
+                 (let loop ((i 0))
+                   (if (file-exists? "/tmp/noticed")
+                       #t
+                       (if (>= i 10)
+                           #f
+                           (begin
+                             (sleep 1)
+                             (loop (+ i 1))))))
+                 ; assume (file-exists? "/tmp/notice_me")
+                 (>= (stat:mtime (stat "/tmp/noticed"))
+                     (stat:mtime (stat "/tmp/notice_me")))))
+             marionette))
+          (test-end)
+          (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+
+  (gexp->derivation (string-append name "-test") test))
+
+(define %file-system-monitoring-os
+  (simple-operating-system
+   (service file-system-monitoring-service-type
+            (file-system-monitoring-configuration
+             (monitored-files '("/tmp/notice_me"))
+             (handlers '(lambda args
+                          (call-with-output-file "/tmp/noticed"
+                            identity)))))))
+
+(define %test-file-system-monitoring
+  (system-test
+   (name "file-system-monitoring")
+   (description "Test file system monitoring event handler.")
+   (value (run-file-system-monitoring-test
+           name %file-system-monitoring-os))))




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at 33265 <at> debbugs.gnu.org:


Received: (at 33265) by debbugs.gnu.org; 5 Nov 2018 03:45:34 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Nov 04 22:45:33 2018
Received: from localhost ([127.0.0.1]:34491 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gJVpV-0001LF-Gk
	for submit <at> debbugs.gnu.org; Sun, 04 Nov 2018 22:45:33 -0500
Received: from dd26836.kasserver.com ([85.13.145.193]:50466)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dannym@HIDDEN>) id 1gJVpT-0001L7-7y
 for 33265 <at> debbugs.gnu.org; Sun, 04 Nov 2018 22:45:31 -0500
Received: from dayas.3.home (178.112.174.42.wireless.dyn.drei.com
 [178.112.174.42])
 by dd26836.kasserver.com (Postfix) with ESMTPSA id 5FF293360176;
 Mon,  5 Nov 2018 04:45:29 +0100 (CET)
From: Danny Milosavljevic <dannym@HIDDEN>
To: 33265 <at> debbugs.gnu.org
Subject: [WIP RFC v2] services: Add file system monitor service.
Date: Mon,  5 Nov 2018 04:45:25 +0100
Message-Id: <20181105034525.8676-1-dannym@HIDDEN>
X-Mailer: git-send-email 2.19.0
In-Reply-To: <20181105031833.7917-1-dannym@HIDDEN>
References: <20181105031833.7917-1-dannym@HIDDEN>
MIME-Version: 1.0
Tags: patch
Content-Transfer-Encoding: 8bit
X-Spam-Score: -0.7 (/)
X-Debbugs-Envelope-To: 33265
Cc: Danny Milosavljevic <dannym@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -1.7 (-)

* gnu/services/monitoring.scm (file-system-monitoring-configuration): 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.
---
 doc/guix.texi               | 37 +++++++++++++++
 gnu/services/monitoring.scm | 67 +++++++++++++++++++++++++-
 gnu/tests/monitoring.scm    | 93 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 195 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 3b7fa50d8..8997a0915 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21496,6 +21496,43 @@ The following is an example @code{dicod-service} configuration.
                     %dicod-database:gcide))))
 @end example
 
+@cindex file system monitoring
+@subsubheading File System Monitoring Service
+
+The @code{(gnu services monitoring)} module provides a shepherd service to
+monitor file system changes and call a handler procedure on changes.
+
+@defvr {Scheme Variable} file-system-monitoring-service-type
+The service type for @command{fswatch}, which provides the file system
+monitoring capability.
+
+@example
+(service file-system-monitoring-service-type
+ (file-system-monitoring-configuration
+   (monitored-files '("/foo/bar"))
+   (handlers '((lambda args
+                 (display "UH OH\n"))))))
+@end example
+@end defvr
+
+@deftp {Data Type} file-system-monitoring-configuration
+The data type representing the configuration of the file-system-monitoring
+service.
+
+@table @asis
+@item @code{package}
+Package containing the actual file system monitor (fswatch).
+
+@item @code{monitored-files}
+List of files to be monitored.
+
+@item @code{handlers}
+List of thunks which will be called once the file system monitor noticed
+changes in the monitored files.
+
+@end table
+@end deftp
+
 @node Setuid Programs
 @subsection Setuid Programs
 
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index aa3b63a0e..b4bec5648 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -26,10 +26,13 @@
   #:use-module (guix gexp)
   #:use-module (guix records)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
   #:export (darkstat-configuration
             prometheus-node-exporter-configuration
             darkstat-service-type
-            prometheus-node-exporter-service-type))
+            prometheus-node-exporter-service-type
+            file-system-monitoring-configuration
+            file-system-monitoring-service-type))
 
 
 ;;;
@@ -125,3 +128,65 @@ prometheus.")
     (list (service-extension
            shepherd-root-service-type
            (compose list prometheus-node-exporter-shepherd-service))))))
+
+
+;;;
+;;; File System Monitoring
+;;;
+
+(define-record-type* <file-system-monitoring-configuration>
+  file-system-monitoring-configuration
+  make-file-system-monitoring-configuration
+  file-system-monitoring-configuration?
+  (package file-system-monitoring-configuration-package
+           (default fswatch))
+  (monitored-files file-system-monitoring-configuration-monitored-files
+                   (default '()))
+  ;; Note: These thunks are called in the shepherd environment.
+  (handlers file-system-monitoring-configuration-handlers
+            (default '())))
+
+(define file-system-monitoring-shepherd-services
+  (match-lambda
+   (($ <file-system-monitoring-configuration> package monitored-files handlers)
+    (list (shepherd-service
+           (provision '(file-system-monitoring))
+           (documentation "File System Monitor")
+           (requirement '(file-systems))
+           (start #~(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
+                                monitored-files
+                                '())))))
+            (stop #~(make-kill-destructor))
+            (respawn? #t))))))
+
+(define file-system-monitoring-service-type
+  (service-type (name 'monitor-file-system)
+                (extensions
+                 (list (service-extension shepherd-root-service-type
+                                          file-system-monitoring-shepherd-services)))
+                (compose concatenate)
+                (extend (lambda (config monitored-files-handlers)
+                          (let ((monitored-files (map car monitored-files-handlers))
+                                (handlers (map cdr monitored-files-handlers)))
+                            (match config
+                             (($ <file-system-monitoring-configuration> package initial-monitored-files initial-handlers)
+                              (file-system-monitoring-configuration
+                               (package package)
+                               (monitored-files (append initial-monitored-files monitored-files))
+                               (handlers (append initial-handlers handlers))
+))))))
+                (description
+                 "Call all @dfn{handlers} once something happens with one of
+the files monitored, and on overflow.  Can have false positives.  Will call
+all @dfn{handlers} on startup.")))
diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm
index 3320a19a7..46364f830 100644
--- a/gnu/tests/monitoring.scm
+++ b/gnu/tests/monitoring.scm
@@ -20,10 +20,12 @@
   #:use-module (gnu services)
   #:use-module (gnu services monitoring)
   #:use-module (gnu services networking)
+  ;#:use-module (gnu system)
   #:use-module (gnu system vm)
   #:use-module (gnu tests)
   #:use-module (guix gexp)
-  #:export (%test-prometheus-node-exporter))
+  #:export (%test-prometheus-node-exporter
+            %test-file-system-monitoring))
 
 
 ;;;
@@ -95,3 +97,92 @@
    (description "Connect to a running prometheus-node-exporter server.")
    (value (run-prometheus-node-exporter-server-test
            name %prometheus-node-exporter-os))))
+
+
+;;;
+;;; File System Monitoring.
+;;;
+
+(define* (run-file-system-monitoring-test name test-os)
+  "Run tests in TEST-OS, which has file system monitoring running."
+  (define os
+    (marionette-operating-system
+     test-os
+     #:imported-modules '((gnu services herd))))
+
+  (define vm
+    (virtual-machine
+     (operating-system os)
+     (port-forwardings '())))
+
+  (define test
+    (with-imported-modules '((gnu build marionette))
+      #~(begin
+          (use-modules (srfi srfi-11)
+                       (srfi srfi-64)
+                       (gnu build marionette)
+                       (web client)
+                       (web response))
+
+          (define marionette
+            (make-marionette (list #$vm)))
+
+          (mkdir #$output)
+          (chdir #$output)
+
+          (test-begin #$name)
+
+          (test-assert "file system monitor running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (match (start-service 'monitor-file-system)
+                  (#f #f)
+                  (('service response-parts ...)
+                   (match (assq-ref response-parts 'running)
+                     ((pid) (number? pid))))))
+             marionette))
+
+          (test-assert "file system monitor notices file system change"
+            (marionette-eval
+             '(begin
+                ;; Not strictly necessary - but we want to test the actual
+                ;; fswatch invocation and not our own synthetic events, so
+                ;; give fswatch the chance to start up.
+                (sleep 2)
+                ;; Now we provide a file change.  The monitor should [restart
+                ;; and thus] call all the handlers again.
+                (call-with-output-file "/tmp/notice_me" identity)
+                (and
+                 (let loop ((i 0))
+                   (if (file-exists? "/tmp/noticed")
+                       #t
+                       (if (>= i 10)
+                           #f
+                           (begin
+                             (sleep 1)
+                             (loop (+ i 1))))))
+                 ; assume (file-exists? "/tmp/notice_me")
+                 (>= (stat:mtime (stat "/tmp/noticed"))
+                     (stat:mtime (stat "/tmp/notice_me")))))
+             marionette))
+          (test-end)
+          (exit (= (test-runner-fail-count (test-runner-current)) 0)))))
+
+  (gexp->derivation (string-append name "-test") test))
+
+(define %file-system-monitoring-os
+  (simple-operating-system
+   (service file-system-monitoring-service-type
+            (file-system-monitoring-configuration
+             (monitored-files '("/tmp/notice_me"))
+             (handlers '(lambda args
+                          (call-with-output-file "/tmp/noticed"
+                            identity)))))))
+
+(define %test-file-system-monitoring
+  (system-test
+   (name "file-system-monitoring")
+   (description "Test file system monitoring event handler.")
+   (value (run-file-system-monitoring-test
+           name %file-system-monitoring-os))))




Information forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 5 Nov 2018 03:18:59 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Sun Nov 04 22:18:59 2018
Received: from localhost ([127.0.0.1]:34484 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1gJVPn-0000h1-5G
	for submit <at> debbugs.gnu.org; Sun, 04 Nov 2018 22:18:59 -0500
Received: from eggs.gnu.org ([208.118.235.92]:59823)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <dannym@HIDDEN>) id 1gJVPl-0000go-GH
 for submit <at> debbugs.gnu.org; Sun, 04 Nov 2018 22:18:57 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <dannym@HIDDEN>) id 1gJVPf-00034k-2R
 for submit <at> debbugs.gnu.org; Sun, 04 Nov 2018 22:18:52 -0500
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org
X-Spam-Level: 
X-Spam-Status: No, score=-0.0 required=5.0 tests=BAYES_40 autolearn=disabled
 version=3.3.2
Received: from lists.gnu.org ([2001:4830:134:3::11]:46593)
 by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <dannym@HIDDEN>)
 id 1gJVPe-00034e-Ur
 for submit <at> debbugs.gnu.org; Sun, 04 Nov 2018 22:18:50 -0500
Received: from eggs.gnu.org ([2001:4830:134:3::10]:41194)
 by lists.gnu.org with esmtp (Exim 4.71)
 (envelope-from <dannym@HIDDEN>) id 1gJVPd-0001B6-HJ
 for guix-patches@HIDDEN; Sun, 04 Nov 2018 22:18:50 -0500
Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
 (envelope-from <dannym@HIDDEN>) id 1gJVPZ-00032g-8M
 for guix-patches@HIDDEN; Sun, 04 Nov 2018 22:18:49 -0500
Received: from dd26836.kasserver.com ([85.13.145.193]:46632)
 by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)
 (Exim 4.71) (envelope-from <dannym@HIDDEN>)
 id 1gJVPY-00031i-TZ
 for guix-patches@HIDDEN; Sun, 04 Nov 2018 22:18:45 -0500
Received: from dayas.3.home (178.112.174.42.wireless.dyn.drei.com
 [178.112.174.42])
 by dd26836.kasserver.com (Postfix) with ESMTPSA id 6C18F3360156;
 Mon,  5 Nov 2018 04:18:40 +0100 (CET)
From: Danny Milosavljevic <dannym@HIDDEN>
To: guix-patches@HIDDEN
Subject: [WIP RFC] services: Add file system monitor service.
Date: Mon,  5 Nov 2018 04:18:33 +0100
Message-Id: <20181105031833.7917-1-dannym@HIDDEN>
X-Mailer: git-send-email 2.19.0
MIME-Version: 1.0
Tags: patch
Content-Transfer-Encoding: quoted-printable
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x
X-Received-From: 2001:4830:134:3::11
X-Spam-Score: -5.0 (-----)
X-Debbugs-Envelope-To: submit
Cc: Danny Milosavljevic <dannym@HIDDEN>
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -6.0 (------)

* gnu/services/monitoring.scm (file-system-monitoring-configuration): 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.
---
 doc/guix.texi               | 37 +++++++++++++++
 gnu/services/monitoring.scm | 65 +++++++++++++++++++++++++-
 gnu/tests/monitoring.scm    | 92 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 192 insertions(+), 2 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 3b7fa50d8..8997a0915 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -21496,6 +21496,43 @@ The following is an example @code{dicod-service}=
 configuration.
                     %dicod-database:gcide))))
 @end example
=20
+@cindex file system monitoring
+@subsubheading File System Monitoring Service
+
+The @code{(gnu services monitoring)} module provides a shepherd service =
to
+monitor file system changes and call a handler procedure on changes.
+
+@defvr {Scheme Variable} file-system-monitoring-service-type
+The service type for @command{fswatch}, which provides the file system
+monitoring capability.
+
+@example
+(service file-system-monitoring-service-type
+ (file-system-monitoring-configuration
+   (monitored-files '("/foo/bar"))
+   (handlers '((lambda args
+                 (display "UH OH\n"))))))
+@end example
+@end defvr
+
+@deftp {Data Type} file-system-monitoring-configuration
+The data type representing the configuration of the file-system-monitori=
ng
+service.
+
+@table @asis
+@item @code{package}
+Package containing the actual file system monitor (fswatch).
+
+@item @code{monitored-files}
+List of files to be monitored.
+
+@item @code{handlers}
+List of thunks which will be called once the file system monitor noticed
+changes in the monitored files.
+
+@end table
+@end deftp
+
 @node Setuid Programs
 @subsection Setuid Programs
=20
diff --git a/gnu/services/monitoring.scm b/gnu/services/monitoring.scm
index aa3b63a0e..94320c7d2 100644
--- a/gnu/services/monitoring.scm
+++ b/gnu/services/monitoring.scm
@@ -26,10 +26,13 @@
   #:use-module (guix gexp)
   #:use-module (guix records)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-1)
   #:export (darkstat-configuration
             prometheus-node-exporter-configuration
             darkstat-service-type
-            prometheus-node-exporter-service-type))
+            prometheus-node-exporter-service-type
+            file-system-monitoring-configuration
+            file-system-monitoring-service-type))
=20
 =0C
 ;;;
@@ -125,3 +128,63 @@ prometheus.")
     (list (service-extension
            shepherd-root-service-type
            (compose list prometheus-node-exporter-shepherd-service))))))
+
+=0C
+;;;
+;;; File System Monitoring
+;;;
+
+(define-record-type* <file-system-monitoring-configuration>
+  file-system-monitoring-configuration
+  make-file-system-monitoring-configuration
+  file-system-monitoring-configuration?
+  (package file-system-monitoring-configuration-package
+           (default fswatch))
+  (monitored-files file-system-monitoring-configuration-monitored-files
+                   (default '()))
+  ;; Note: These thunks are called in the shepherd environment.
+  (handlers file-system-monitoring-configuration-handlers
+            (default '())))
+
+(define file-system-monitoring-shepherd-services
+  (match-lambda
+   (($ <file-system-monitoring-configuration> package monitored-files ha=
ndlers)
+    (list (shepherd-service
+           (provision '(file-system-monitoring))
+           (documentation "File System Monitor")
+           (requirement '(file-systems))
+           (start #~(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
+                                monitored-files
+                                '())))))
+            (stop #~(make-kill-destructor))
+            (respawn? #t))))))
+
+(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-files handlers)
+                          (match config
+                           (($ <file-system-monitoring-configuration> pa=
ckage initial-monitored-files initial-handlers)
+                            (file-system-monitoring-configuration
+                             (package package)
+                             (monitored-files (append initial-monitored-=
files monitored-files))
+                             (handlers (append initial-handlers handlers=
))
+)))))
+                (description
+                 "Call all @dfn{handlers} once something happens with on=
e of
+the files monitored, and on overflow.  Can have false positives.  Will c=
all
+all @dfn{handlers} on startup.")))
diff --git a/gnu/tests/monitoring.scm b/gnu/tests/monitoring.scm
index 3320a19a7..95fbc7906 100644
--- a/gnu/tests/monitoring.scm
+++ b/gnu/tests/monitoring.scm
@@ -20,10 +20,12 @@
   #:use-module (gnu services)
   #:use-module (gnu services monitoring)
   #:use-module (gnu services networking)
+  ;#:use-module (gnu system)
   #:use-module (gnu system vm)
   #:use-module (gnu tests)
   #:use-module (guix gexp)
-  #:export (%test-prometheus-node-exporter))
+  #:export (%test-prometheus-node-exporter
+            %test-file-system-monitoring))
=20
 =0C
 ;;;
@@ -95,3 +97,91 @@
    (description "Connect to a running prometheus-node-exporter server.")
    (value (run-prometheus-node-exporter-server-test
            name %prometheus-node-exporter-os))))
+
+=0C
+;;;
+;;; File System Monitoring.
+;;;
+
+(define* (run-file-system-monitoring-test name test-os)
+  "Run tests in TEST-OS, which has file system monitoring running."
+  (define os
+    (marionette-operating-system
+     test-os
+     #:imported-modules '((gnu services herd))))
+
+  (define vm
+    (virtual-machine
+     (operating-system os)))
+
+  (define test
+    (with-imported-modules '((gnu build marionette))
+      #~(begin
+          (use-modules (srfi srfi-11)
+                       (srfi srfi-64)
+                       (gnu build marionette)
+                       (web client)
+                       (web response))
+
+          (define marionette
+            (make-marionette (list #$vm)))
+
+          (mkdir #$output)
+          (chdir #$output)
+
+          (test-begin #$name)
+
+          (test-assert "file system monitor running"
+            (marionette-eval
+             '(begin
+                (use-modules (gnu services herd))
+                (match (start-service 'monitor-file-system)
+                  (#f #f)
+                  (('service response-parts ...)
+                   (match (assq-ref response-parts 'running)
+                     ((pid) (number? pid))))))
+             marionette))
+
+          (test-assert "file system monitor notices file system change"
+            (marionette-eval
+             '(begin
+                ;; Not strictly necessary - but we want to test the actu=
al
+                ;; fswatch invocation and not our own synthetic events, =
so
+                ;; give fswatch the chance to start up.
+                (sleep 2)
+                ;; Now we provide a file change.  The monitor should [re=
start
+                ;; and thus] call all the handlers again.
+                (call-with-output-file "/tmp/notice_me" identity)
+                (and
+                 (let loop ((i 0))
+                   (if (file-exists? "/tmp/noticed")
+                       #t
+                       (if (>=3D i 10)
+                           #f
+                           (begin
+                             (sleep 1)
+                             (loop (+ i 1))))))
+                 ; assume (file-exists? "/tmp/notice_me")
+                 (>=3D (stat:mtime (stat "/tmp/noticed"))
+                     (stat:mtime (stat "/tmp/notice_me")))))
+             marionette))
+          (test-end)
+          (exit (=3D (test-runner-fail-count (test-runner-current)) 0)))=
))
+
+  (gexp->derivation (string-append name "-test") test))
+
+(define %file-system-monitoring-os
+  (simple-operating-system
+   (service file-system-monitoring-service-type
+            (file-system-monitoring-configuration
+             (monitored-files '("/tmp/notice_me"))
+             (handlers '(lambda args
+                          (call-with-output-file "/tmp/noticed"
+                            identity)))))))
+
+(define %test-file-system-monitoring
+  (system-test
+   (name "file system monitoring")
+   (description "Test file system monitoring event handler.")
+   (value (run-file-system-monitoring-test
+           name %file-system-monitoring-os))))




Acknowledgement sent to Danny Milosavljevic <dannym@HIDDEN>:
New bug report received and forwarded. Copy sent to guix-patches@HIDDEN. Full text available.
Report forwarded to guix-patches@HIDDEN:
bug#33265; Package guix-patches. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Sun, 11 Nov 2018 12:30:02 UTC

GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997 nCipher Corporation Ltd, 1994-97 Ian Jackson.