[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: |
Tue, 5 Mar 2024 19:32:31 -0600 |
On 3/4/24 21:07, Owen T. Heisler wrote:
> On 3/4/24 10:08, Felix Lechner wrote:
>> 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.
Apparently I failed to follow your example properly and had an extra
`#~(begin` in there. I have a minimal example now that does work,
including with the G-expression defined separately.
As I wrote in another message, I also got a boot script
(non-Shepherd) service working (with the help of a hint from Florian)
but I need to use a regular Shepherd service so I can declare a
dependency on another service (in this case, syslogd).
Here is the working example:
```scm
;; $(guix system vm input.scm --no-graphic)
(use-modules (gnu)
(gnu services shepherd)
(ice-9 popen))
(use-service-modules networking)
(use-package-modules admin bootloaders)
(define say-hello-gexp
#~(begin
(let ((port (open-pipe* OPEN_WRITE
#$(file-append inetutils "/bin/logger")
"-plocal0.alert"))
;; Use random string to counter syslog deduplication
(rand_str (number->string (random 100))))
(display (string-append "====say-hello" rand_str "====\n") port)
(close-pipe port))))
(define say-hello-service
(simple-service 'say-hello-service shepherd-root-service-type
(list (shepherd-service (auto-start? #t)
(documentation "Say hello.")
(one-shot? #t)
(provision '(say-hello-service))
(requirement '(syslogd))
(respawn? #f)
(start #~(lambda _
#$say-hello-gexp))))))
(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)))
;; # herd start say-hello-service
```
Thanks,
Owen