unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Tomas Volf <~@wolfsden.cz>
To: guix-devel@gnu.org
Subject: How to invoke shepherd action from shepherd action?
Date: Fri, 5 Jul 2024 17:24:08 +0200	[thread overview]
Message-ID: <ZogQGD295M23M8Wn@ws> (raw)

[-- Attachment #1: Type: text/plain, Size: 2982 bytes --]

Hello,

I am currently in the process of writing a new service, and I have run into bit
of a wall.  I need to invoke shepherd action after my one-shot service finishes.

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 immediately.")
      (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 nginx.")

This just hangs the shepherd for ever.  Even `herd status' no longer works.
Only recovery I found was hard reboot.

2. invoke

  (reload-hook
   (gexp (with-imported-modules '((guix build utils))
           #~((@ (guix build utils) invoke)
              ;; There probably is more elegant way to get the current shepherd.
              #$(file-append (shepherd-configuration-shepherd
                              (shepherd-configuration))
                             "/bin/herd") "reload" "nginx")))

This does work, but the round-trip via separate binary (and the way to figure it
out) is hardly elegant.

Could someone advice me on how the typical pattern for this should look?
Preferably while staying inside Guile (so no invoke).

Thanks and have a nice day,
Tomas Volf

--
There are only two hard things in Computer Science:
cache invalidation, naming things and off-by-one errors.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

             reply	other threads:[~2024-07-05 15:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-05 15:24 Tomas Volf [this message]
2024-07-11  9:55 ` How to invoke shepherd action from shepherd action? Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZogQGD295M23M8Wn@ws \
    --to=~@wolfsden.cz \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).