help-guix
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Staging Scheme code to run as one-shot service


From: Owen T. Heisler
Subject: Re: Staging Scheme code to run as one-shot service
Date: Mon, 4 Mar 2024 21:07:42 -0600

Hi Felix,

On 3/4/24 10:08, Felix Lechner wrote:
On Sat, Mar 02 2024, Owen T. Heisler wrote:

    (start #~(lambda ()
               #$(say-hello)))

My code works when I place it directly into the 'start' G-exp. [1]

By comparison, I think you have two lambdas (with quoting and
unquoting). I would try something like this:

     (start #~(let ((port (open-pipe* OPEN_WRITE "logger" "-plocal0.alert")))
                (display "========say-hello========\n" port)
                (close-pipe port)))

[1] 
https://codeberg.org/lechner/juix/src/commit/fe8cac5165bfbe290413cedd36a492109e29e38b/juix/deploy/cachefilesd.scm#L158

Thanks for the suggestion. I tried that, but it doesn't work either. Instead I now get this error during boot before the login prompt (note, auto-start is false):

/run/current-system/profile/bin/logger: cannot connect: No such file or directory

It appears to me that the code isn't adequately staged. I assume the code in #~(begin) is being executed (rather than staged) when Shepherd starts. That's why I added the other lambda. (Perhaps the linked service declaration your link [1] above would create the cache directory even if auto-start was set to false; that's just a guess though.)

This is what I tried:

```scm
;; Run with `$(guix system vm input.scm --no-graphic)`
(use-modules (gnu)
             (gnu services shepherd)
             (ice-9 popen))
(use-service-modules networking)
(use-package-modules bootloaders)
(define say-hello-service
  (simple-service 'say-hello-service shepherd-root-service-type
                  (list (shepherd-service (auto-start? #f)
                                        (documentation "Say hello.")
                                        (one-shot? #t)
                                        (provision '(say-hello-service))
                                        (respawn? #f)
                                        (start
               #~(begin
                   (let ((port (open-pipe*
                                OPEN_WRITE
                                "/run/current-system/profile/bin/logger"
                                "-plocal0.alert")))
                     (display "========say-hello========\n" port)
                     (close-pipe port))))))))
(operating-system
  (bootloader (bootloader-configuration
                (bootloader grub-bootloader)
                (targets '("/dev/vda"))
                (terminal-inputs '(console serial))
                (terminal-outputs '(console serial))
                (timeout 1)))
  (file-systems (cons (file-system
                        (mount-point "/")
                        (device "/dev/vda1")
                        (type "ext4")) %base-file-systems))
  (host-name "test-guix-vm")
  (kernel-arguments (cons "console=ttyS0" %default-kernel-arguments))
  (services
   (append (list say-hello-service) %base-services)))
```

Thanks,
Owen



reply via email to

[Prev in Thread] Current Thread [Next in Thread]