unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Kevin Boulain <kevinboulain@gmail.com>
To: guix-devel@gnu.org
Subject: Re: Should Guix Home daemonize Shepherd?
Date: Sat, 12 Mar 2022 18:49:21 +0100	[thread overview]
Message-ID: <CABaj1X_coHxvcvMOwZXPYazsfrN3aXs793QUio2VquUrYKEOHA@mail.gmail.com> (raw)
In-Reply-To: <CABaj1X9Bi8-CKH9yU53C__AYB4tKsgkshfuW+FTZz37LO9h2zQ@mail.gmail.com>

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

So, I've done some digging and I'm coming back with two findings :)

First, Guix Home correctly tells the user Shepherd to daemonize itself
via an 'action'
(https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/home/services/shepherd.scm#n64)
but, from my understanding, the daemonization process is missing at
least a setsid call
(https://git.savannah.gnu.org/cgit/shepherd.git/tree/modules/shepherd/service.scm#n1421),
see the attached 'shepherd-setsid.patch'. This fixes the Shepherd
dying when exiting the SSH session or the Shepherd catching the ^C.
I guess it should also close std{in,out,err} like it's done for the
regular services
(https://git.savannah.gnu.org/cgit/shepherd.git/tree/modules/shepherd/service.scm#n806)
but this answers a part of my initial post.

Second, elogind (it's required by Guix Home to get the XDG_*
environment variables and also part of %desktop-services) will remove
/run/user/$uid when the session ends. It's standard, but the problem
is that Guix Home's 'on-first-login-executed' is located there,
alongside 'shepherd/socket' and probably the other user daemon's
sockets. This easily results in duplicate services being rerun when
the old ones haven't been killed because 'KillUserProcesses' is set to
'no' by default
(https://git.savannah.gnu.org/cgit/guix.git/tree/gnu/services/desktop.scm#n937).
I don't think it's a bad idea to set KillUserProcesses=no (I remember
that when this was first introduced a lot of users complained, see for
example https://github.com/tmux/tmux/issues/428) but now we're in an
awkward position unless Guix Home users move everything out of
XDG_RUNTIME_DIR (for example, tmux's socket is in /tmp).

Thoughts? I must admit, I'm not sure how to address the elogind issue,
XDG_RUNTIME_DIR is ingrained in a lot of places (even in the Shepherd
https://git.savannah.gnu.org/cgit/shepherd.git/tree/modules/shepherd/support.scm#n284)
and asking users to override socket flags (and others) for all the
services they run (if at all possible) sounds a bit counterintuitive.
Or am I missing something obvious?

[-- Attachment #2: shepherd-setsid.patch --]
[-- Type: application/octet-stream, Size: 909 bytes --]

Detach from the controlling terminal when daemonizing

https://lists.gnu.org/archive/html/guix-devel/2022-03/msg00040.html

diff --git c/modules/shepherd/service.scm w/modules/shepherd/service.scm
index ad8608b..62f97bc 100644
--- c/modules/shepherd/service.scm
+++ w/modules/shepherd/service.scm
@@ -1420,8 +1420,12 @@ we want to receive these signals."
           (else
            (if (zero? (primitive-fork))
                (begin
-                 (catch-system-error (prctl PR_SET_CHILD_SUBREAPER 1))
-                 #t)
+                 (setsid)
+                 (if (zero? (primitive-fork))
+                     (begin
+                       (catch-system-error (prctl PR_SET_CHILD_SUBREAPER 1))
+                       #t)
+                     (primitive-exit 0)))
                (primitive-exit 0))))))
      (persistency
       "Save the current state of running and non-running services.

  reply	other threads:[~2022-03-12 17:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-06 18:47 Should Guix Home daemonize Shepherd? Kevin Boulain
2022-03-12 17:49 ` Kevin Boulain [this message]
2022-05-06  8:07   ` Andrew Tropin
2022-05-15 13:20   ` Ludovic Courtès
2022-05-15 18:39     ` Kevin Boulain

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=CABaj1X_coHxvcvMOwZXPYazsfrN3aXs793QUio2VquUrYKEOHA@mail.gmail.com \
    --to=kevinboulain@gmail.com \
    --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).