guix-devel
[Top][All Lists]
Advanced

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

Should Guix Home daemonize Shepherd?


From: Kevin Boulain
Subject: Should Guix Home daemonize Shepherd?
Date: Sun, 6 Mar 2022 19:47:23 +0100

Hello,

I did a quick search in the tracker and the mailing list archives but
couldn't find a similar topic, apologies if this was already
discussed.

I was playing with Guix Home and I'm a bit surprised by how user
services are managed, especially the Shepherd itself.

Let's say I start from a clean state (I ran 'guix home reconfigure'
and rebooted the Guix machine) and I login via SSH:

$ ssh host
[...]
Service root has been started.
WARNING: Use of `load' in declarative module (#{ g56}#).  Add
#:declarative? #f to your define-module invocation.
Starting services...
Service example has been started.
$ exit

On the first login, the user's Shepherd is started and my 'example'
service is run. So far so good.

Now I login again:

$ ssh host
[...]
Starting services...
Service example has been started.
$ exit

The service is restarted again, meaning Shepherd and all the services
were killed when I logged out the first time. Is that expected?

Now, it's even weirder if I open two connections or more:

1$ ssh host
[...]
Starting services...
Service example has been started.
1$ # Don't exit this shell just yet.

2$ ssh host
2$ # Notice how the services weren't started again, I believe
$XDG_RUNTIME_DIR/on-first-login-executed is working as expected.

1$ exit # Now I logout from my first session.
2$ ps waux | grep $service # Nothing! The service has been killed
because I logged out from the first session.

Now, as long as the second session is kept open, the services won't be
restarted automatically, even if I open a third session. I need to
close all existing sessions and login again for the services to be
started.

Finally, I'm not sure Shepherd should share the terminal, it leads to
unfortunate situations like this (in addition to writing messages to
stdout like "Respawning $service", garbling any other process'
output):

$ ssh host
[...]
Starting services...
Service example has been started.
$ ^C # A single ^C will kill Shepherd, so I assume it wasn't properly
put in the background.
Exiting shepherd...
Service example has been stopped.
$ # I lost all my services :(

So, should the Shephered be daemonized when
$XDG_RUNTIME_DIR/on-first-login-executed is set?
I believe it would be a lot less surprising to users, unless the goal
was to prevent any lingering session in the first place.

---

For the record, I'm reproducing the above examples with this configuration:

;; guix home --dry-run reconfigure example.scm

(define-module (example)
  #:use-module (guix gexp)
  #:use-module (gnu home)
  #:use-module (gnu home services)
  #:use-module (gnu home services shepherd)
  #:use-module (gnu services)
  #:use-module (gnu packages base))

(define (example-shepherd-service _)
  (list
   (shepherd-service
    (documentation "Example service.")
    (provision '(example))
    (start #~(make-forkexec-constructor
              (list #$(file-append coreutils "/bin/sleep") "60")
              #:log-file (string-append (getenv "XDG_LOG_HOME")
"/example.log")))
    (stop #~(make-kill-destructor)))))

(define example-service-type
  (service-type
   (name 'example)
   (extensions
    (list
     (service-extension home-shepherd-service-type example-shepherd-service)))
   (default-value #nil)
   (description "Example service")))

(home-environment
 (services
  (list (service example-service-type))))



reply via email to

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