all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Andrew Tropin <andrew@trop.in>
To: "Ludovic Courtès" <ludo@gnu.org>
Cc: 54545@debbugs.gnu.org
Subject: bug#54545: [Guix Home] ‘shepherd’ started twice?
Date: Tue, 12 Apr 2022 12:27:55 +0300	[thread overview]
Message-ID: <871qy2irc4.fsf@trop.in> (raw)
In-Reply-To: <871qyctxhk.fsf@gnu.org>


[-- Attachment #1.1: Type: text/plain, Size: 896 bytes --]

On 2022-04-04 22:16, Ludovic Courtès wrote:

> Hi,
>
> Andrew Tropin <andrew@trop.in> skribis:
>
>> Activation script tries to load latest shepherd configuration with `herd
>> load root ./path/to/config.scm` and it starts a shepherd process.  Login
>> shell starts the shepherd process as well.  Probably we need to do
>> config reload using on-change service and also not trigger on-change
>> stuff if user isn't logged in.
>
> Makes sense.
>
>> I can think on the proper solution and make a patch with a fix later
>> this week or beginning of the next week.
>
> Awesome, thanks for taking a look!
>
> Ludo’.

Prepared a patch series, which fixes the issues and sligthly adjusts the
way home shepherd reload configuration logic works, now it happens only
if configuration is changed and also it doesn't try to be smart and
start a shepherd if it's not started yet.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: 0001-home-shepherd-Prevent-launching-the-second-instance.patch --]
[-- Type: text/x-patch, Size: 2217 bytes --]

From d2578f8924217451ca20f0b61fd6f9b9d31c930d Mon Sep 17 00:00:00 2001
From: Andrew Tropin <andrew@trop.in>
Date: Tue, 12 Apr 2022 11:30:58 +0300
Subject: [PATCH 1/3] home: shepherd: Prevent launching the second instance.

* gnu/home/services/shepherd.scm: Prevent launching the second instance.
---
 gnu/home/services/shepherd.scm | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm
index 012585fea4..df6bbb30e6 100644
--- a/gnu/home/services/shepherd.scm
+++ b/gnu/home/services/shepherd.scm
@@ -93,17 +93,21 @@ (define (launch-shepherd-gexp config)
          (services (home-shepherd-configuration-services config)))
     (if (home-shepherd-configuration-auto-start? config)
         (with-imported-modules '((guix build utils))
-          #~(let ((log-dir (or (getenv "XDG_LOG_HOME")
-                               (format #f "~a/.local/var/log" (getenv "HOME")))))
-              ((@ (guix build utils) mkdir-p) log-dir)
-              (system*
-               #$(file-append shepherd "/bin/shepherd")
-               "--logfile"
-               (string-append
-                log-dir
-                "/shepherd.log")
-               "--config"
-               #$(home-shepherd-configuration-file services shepherd))))
+          #~(unless (file-exists?
+                     (string-append
+                      (or (getenv "XDG_RUNTIME_DIR")
+                          (format #f "/run/user/~a" (getuid)))
+                      "/shepherd/socket"))
+              (let ((log-dir (or (getenv "XDG_LOG_HOME")
+                                 (format #f "~a/.local/var/log"
+                                         (getenv "HOME")))))
+                ((@ (guix build utils) mkdir-p) log-dir)
+                (system*
+                 #$(file-append shepherd "/bin/shepherd")
+                 "--logfile"
+                 (string-append log-dir "/shepherd.log")
+                 "--config"
+                 #$(home-shepherd-configuration-file services shepherd)))))
         #~"")))
 
 (define (reload-configuration-gexp config)
-- 
2.35.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.3: 0002-home-shepherd-Use-run-on-change-to-reload-shepherd-c.patch --]
[-- Type: text/x-patch, Size: 3423 bytes --]

From 56d16b4cd511f6837329b888dade0c6d6da4d89d Mon Sep 17 00:00:00 2001
From: Andrew Tropin <andrew@trop.in>
Date: Tue, 12 Apr 2022 12:19:50 +0300
Subject: [PATCH 2/3] home: shepherd: Use run-on-change to reload shepherd
 config.

* gnu/home/services/shepherd.scm: Add shepherd configuration to
XDG_CONFIG_HOME and use it instead of full path to the store. It's necessary
to use run-on-change service.
---
 gnu/home/services/shepherd.scm | 40 +++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 17 deletions(-)

diff --git a/gnu/home/services/shepherd.scm b/gnu/home/services/shepherd.scm
index df6bbb30e6..9a99fed2b5 100644
--- a/gnu/home/services/shepherd.scm
+++ b/gnu/home/services/shepherd.scm
@@ -105,27 +105,30 @@ (define (launch-shepherd-gexp config)
                 (system*
                  #$(file-append shepherd "/bin/shepherd")
                  "--logfile"
-                 (string-append log-dir "/shepherd.log")
-                 "--config"
-                 #$(home-shepherd-configuration-file services shepherd)))))
+                 (string-append log-dir "/shepherd.log")))))
         #~"")))
 
 (define (reload-configuration-gexp config)
   (let* ((shepherd (home-shepherd-configuration-shepherd config))
          (services (home-shepherd-configuration-services config)))
-    #~(system*
-       #$(file-append shepherd "/bin/herd")
-       "load" "root"
-       #$(home-shepherd-configuration-file services shepherd))))
+    #~(when (file-exists?
+             (string-append
+              (or (getenv "XDG_RUNTIME_DIR")
+                  (format #f "/run/user/~a" (getuid)))
+              "/shepherd/socket"))
+        (system*
+         #$(file-append shepherd "/bin/herd")
+         "load" "root"
+         #$(home-shepherd-configuration-file services shepherd)))))
 
-(define (ensure-shepherd-gexp config)
-  #~(if (file-exists?
-         (string-append
-          (or (getenv "XDG_RUNTIME_DIR")
-              (format #f "/run/user/~a" (getuid)))
-          "/shepherd/socket"))
-        #$(reload-configuration-gexp config)
-        #$(launch-shepherd-gexp config)))
+(define (add-shepherd-configuration config)
+  (let* ((shepherd (home-shepherd-configuration-shepherd config))
+         (services (home-shepherd-configuration-services config)))
+    `(("shepherd/init.scm"
+       ,(home-shepherd-configuration-file services shepherd)))))
+
+(define (home-shepherd-run-on-change config)
+  `(("files/.config/shepherd/init.scm" ,(reload-configuration-gexp config))))
 
 (define-public home-shepherd-service-type
   (service-type (name 'home-shepherd)
@@ -134,8 +137,11 @@ (define-public home-shepherd-service-type
                         home-run-on-first-login-service-type
                         launch-shepherd-gexp)
                        (service-extension
-                        home-activation-service-type
-                        ensure-shepherd-gexp)
+                        home-xdg-configuration-files-service-type
+                        add-shepherd-configuration)
+                       (service-extension
+                        home-run-on-change-service-type
+                        home-shepherd-run-on-change)
                        (service-extension
                         home-profile-service-type
                         (lambda (config)
-- 
2.35.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.4: 0003-home-run-on-first-login-Add-a-startup-message-to-the.patch --]
[-- Type: text/x-patch, Size: 931 bytes --]

From e80e9fae6f6bcd478fa904aad8eb426da3f42f10 Mon Sep 17 00:00:00 2001
From: Andrew Tropin <andrew@trop.in>
Date: Tue, 12 Apr 2022 12:23:26 +0300
Subject: [PATCH 3/3] home: run-on-first-login: Add a startup message to the
 script.

gnu/home/services.scm: Add a startup message to the script to make it clear
when it begins.
---
 gnu/home/services.scm | 1 +
 1 file changed, 1 insertion(+)

diff --git a/gnu/home/services.scm b/gnu/home/services.scm
index 49bd6e3555..e2c51910a8 100644
--- a/gnu/home/services.scm
+++ b/gnu/home/services.scm
@@ -344,6 +344,7 @@ (define (compute-on-first-login-script _ gexps)
      #~(begin
        (use-modules (guix i18n))
        #$%initialize-gettext
+       (display (G_ "Starting run-on-first-login script.\n\n"))
 
        (let* ((xdg-runtime-dir (or (getenv "XDG_RUNTIME_DIR")
                                    (format #f "/run/user/~a" (getuid))))
-- 
2.35.1


[-- Attachment #1.5: Type: text/plain, Size: 39 bytes --]



-- 
Best regards,
Andrew Tropin

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 853 bytes --]

  reply	other threads:[~2022-04-12  9:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-24 14:21 bug#54545: [Guix Home] ‘shepherd’ started twice? Ludovic Courtès
2022-04-04  6:41 ` Andrew Tropin
2022-04-04 20:16   ` Ludovic Courtès
2022-04-12  9:27     ` Andrew Tropin [this message]
2022-04-12 18:28       ` Ludovic Courtès
2022-04-13  6:22         ` Andrew Tropin
2022-04-15 15:59           ` Ludovic Courtès

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871qy2irc4.fsf@trop.in \
    --to=andrew@trop.in \
    --cc=54545@debbugs.gnu.org \
    --cc=ludo@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 external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.