From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 8MBJHkqsj2YBWQEAe85BDQ:P1 (envelope-from ) for ; Thu, 11 Jul 2024 09:56:26 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id 8MBJHkqsj2YBWQEAe85BDQ (envelope-from ) for ; Thu, 11 Jul 2024 11:56:26 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=gnu.org header.s=fencepost-gnu-org header.b="WIwMB/kM"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1720691786; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=KgF/dkZ3D1b3ogSqRuqToZiNnoTY9mTYEbk7gbKsuMo=; b=o3jK7XREq0I653zupkuieecURDAz2YSCNlS8+RGBhk79KsI1oc9RSImY9fFr91E3xSMPFc EDflmvU9+RMVvl7ikJBirO7tnyWUYF4AAbfcb6OGvlidU1YBs51skTUMRal05FRDKFbG0d mdoWHyszA7wmM0MxVY/1B+rTgkd1/DM4THuGAMeuMezmpMu7cgmR4L0QBN8IpcBTTfswZL lZWzuLNwUW/L6yTUk67n+6AN0jLmR+Oc5lnELnasE5kOH0545Bu09LFaIHOZ3Ik1wJbBRh jurGQJ2AkgdmkDB4nbY8ZJJaCe1lHta6BJmzA0/4y+ngXIHLR3oc+74Ta7mUxw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1720691786; a=rsa-sha256; cv=none; b=W4CzMVidqBWA1mGU+Af6K+ukeIgiX8UwQ0/3lh2Llpxe8Mwr4D1Yk4CJZXe5Z0tjR2pw/w oNZ7iKXuT692+ZUkZnkcdLn+qb1vxSprQ6fJESfTUu3u4cA9W6K4CAh4GHiVHHm7P1bPCy yX6IP4bgZ0SUXJDpc9EXardqF6Nn3i7kS5xIc5Bu0qYtwhCh6HmGH0N7NkdmIUqs0D+7G3 R2uFQ9UjPuJH5aMmbA19OkfQNN46fOIySPR4onXTto0QjUqaffMhNA5ArSQ38u2NX+RD0z PoBSSLOVxVKyh+ZmdGPvIF4U998maGU9Gv5rb3L7tq4ISsBusi8w9PUo09qhQQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=pass header.d=gnu.org header.s=fencepost-gnu-org header.b="WIwMB/kM"; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-devel-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-devel-bounces+larch=yhetil.org@gnu.org" Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5B77335F6D for ; Thu, 11 Jul 2024 11:56:26 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sRqWe-0002u6-Cy; Thu, 11 Jul 2024 05:55:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRqWU-0002J2-Ka for guix-devel@gnu.org; Thu, 11 Jul 2024 05:55:37 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sRqWU-00078b-6D for guix-devel@gnu.org; Thu, 11 Jul 2024 05:55:34 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:References:In-Reply-To:Subject:To: From; bh=KgF/dkZ3D1b3ogSqRuqToZiNnoTY9mTYEbk7gbKsuMo=; b=WIwMB/kM9yNuCq11BbhE FmzjHZG8Cq7DbuEna6KWCLWDqDcJSvumOmCp85sR35d0PgZsfJDOvIPsu2KAAF/TLk90XNssrZdXj /i0+k8pxk7AtagUx+pPR21BYb41fFsJM5g59PXHt93ztXqFB9jLTg2ApjfRtkzzw+Kf3Nad11Ytl8 /ax0i19xmXh6URc/9vkhvsYkgImZRnhF1SDDQ3YXW7g0K6dUUg5+3FSpgQ5GjQ3HRcwwQy5+Ow+nL onlFJOWIb6rLW51X4OguHn8YAy8hs8cZwalk5Eh/65tNi6HT6mTP0L4y3JfA3qb9bYPfcmGu7wC71 xmbMpt0Prcyxlw==; From: =?utf-8?Q?Ludovic_Court=C3=A8s?= To: guix-devel@gnu.org Subject: Re: How to invoke shepherd action from shepherd action? In-Reply-To: (Tomas Volf's message of "Fri, 5 Jul 2024 17:24:08 +0200") References: X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: Quartidi 24 Messidor an 232 de la =?utf-8?Q?R=C3=A9v?= =?utf-8?Q?olution=2C?= jour de =?utf-8?Q?l'Orcan=C3=A8te?= 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: Thu, 11 Jul 2024 11:55:27 +0200 Message-ID: <87ed802qy8.fsf@gnu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: guix-devel-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Queue-Id: 5B77335F6D X-Migadu-Scanner: mx12.migadu.com X-Migadu-Spam-Score: -10.15 X-Spam-Score: -10.15 X-TUID: RbJXrkA/zDH1 Hi, Tomas Volf <~@wolfsden.cz> skribis: > I am currently in the process of writing a new service, and I have run in= to bit > of a wall. I need to invoke shepherd action after my one-shot service fi= nishes. > > The code (relevant bits) for my service is pretty simple: > > (define (acme-client-shepherd-services config) > (let* ((config-file (serialize-acme-client-configuration config)) > (package (acme-client-configuration-package config)) > (reload-hook (acme-client-configuration-reload-hook config)) > (requirement (acme-client-configuration-requirement config)) > (handles (map acme-client-domain-handle > (acme-client-configuration-domains config)))) > (list > (shepherd-service > (provision '(acme-client-initial)) > (requirement requirement) > (documentation "Invoke right away to provision certificates immedia= tely.") > (one-shot? #t) > (start #~(lambda _ > (let* ((renew-cert #$(renew-cert config)) > (renew-res > (map > (lambda (handle) > (or (renew-cert handle) > (begin (sleep 15) > (renew-cert handle)) > (begin (sleep 15) > (renew-cert handle)))) > '#$handles))) > (when (memq 'change (pk renew-res)) > (pk (#$reload-hook))) > ((@ (srfi srfi-1) every) identity renew-res)))) > (actions (list (shepherd-configuration-action config-file))))))) > > Now the problem is with the `reload-hook'. I tried two approaches (the > following is a snippet from define-configuration/no-serialization for > acme-client-configuration): > > 1. with-shepherd-action > > (reload-hook > (gexp (with-imported-modules '((gnu services herd)) > #~(begin > ((@ (gnu services herd) with-shepherd-action) > 'nginx ('reload) result result)))) > "Hook to invoke after certificate change. The default is to reload ng= inx.") > > This just hangs the shepherd for ever. Even `herd status' no longer work= s. > Only recovery I found was hard reboot. You have to always keep in mind where code is running. =E2=80=98start=E2= =80=99, =E2=80=98stop=E2=80=99, and actions are running within the shepherd, in PID=C2=A01. Conversely, the (gnu services herd) module provides utilities to *connect* to a running shepherd *as a client* (a separate process), very much like what the =E2=80=98herd=E2=80=99 command does. >From shepherd itself, you probably don=E2=80=99t want to connect to shepher= d to perform actions. Instead, you can use the Shepherd=E2=80=99s API: https://www.gnu.org/software/shepherd/manual/html_node/Services.html In this case, perhaps you=E2=80=99ll want to call =E2=80=98perform-service-= action=E2=80=99. (Aside: why did your attempt hang? While overkill, it should be fine to connect to shepherd from within shepherd, right? The problem here is that =E2=80=98with-shepherd-action=E2=80=99 creates a socket *without* O_NO= NBLOCK. Thus, the entire shepherd process is blocked when trying to read from that socket.) I hope this helps! Let me know if you think of ways to improve documentation in this area. Ludo=E2=80=99.