unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: "Owen T. Heisler" <writer@owenh.net>
To: help-guix@gnu.org
Subject: Staging Scheme code to run as one-shot service
Date: Sat, 2 Mar 2024 00:28:53 -0600	[thread overview]
Message-ID: <44391266-8dcb-47fc-a886-b4e9e6e0efbb@owenh.net> (raw)

service where the entire service functionality is in a procedure. =====
Hi! I am trying to declare a simple one-shot operating-system service
where the entire service functionality is in a procedure. Following is
a minimal reproducible example. The error is `In procedure fport_write:
Broken pipe` (see end of message). What is wrong here? I'm new to
Scheme and Guix, and it's not very clear to me yet how code staging and
g-expressions work, so it's probably something quite obvious. Thanks
for looking!

```scm
;; operating-system declaration
(use-modules (gnu)
              (gnu services shepherd)
              (ice-9 popen))
(use-service-modules networking)
(use-package-modules bootloaders)
(define (say-hello)
   #~(let ((port (open-pipe* OPEN_WRITE "logger" "-plocal0.alert")))
       (display "========say-hello========\n" port)
       (close-pipe port)))
(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 #~(lambda ()
                                                      #$(say-hello)))))))
(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)))
```

```sh
# Build system image and run with qemu
cp $(guix system image --image-type=qcow2 in.scm) image.qcow2
chmod u+w image.qcow2
qemu-system-x86_64 -enable-kvm -m 2048 -device virtio-blk,drive=myhd \
     -nographic -drive if=none,file=image.qcow2,id=myhd
```

```console
## Log in as root and attempt to start service
# herd start say-hello-service
Starting service say-hello-service...
Service say-hello-service failed to start.
herd: error: exception caught while executing 'start' on service 'say-hello-service':
In procedure fport_write: Broken pipe
```


             reply	other threads:[~2024-03-03  7:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-02  6:28 Owen T. Heisler [this message]
2024-03-04  8:18 ` Staging Scheme code to run as one-shot service pelzflorian (Florian Pelz)
2024-03-04  8:31 ` pelzflorian (Florian Pelz)
2024-03-05  4:01   ` Owen T. Heisler
2024-03-04 16:08 ` Felix Lechner via
2024-03-05  3:07   ` Owen T. Heisler
2024-03-06  1:32     ` Owen T. Heisler
2024-03-07 18:31       ` Owen T. Heisler

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=44391266-8dcb-47fc-a886-b4e9e6e0efbb@owenh.net \
    --to=writer@owenh.net \
    --cc=help-guix@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.
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).