Patchwork [8/8] services: Add spice vdagent service.

login
register
mail settings
Submitter David Craven
Date July 29, 2016, 8:23 a.m.
Message ID <20160729082357.17501-8-david@craven.ch>
Download mbox | patch
Permalink /patch/14139/
State New
Headers show

Comments

David Craven - July 29, 2016, 8:23 a.m.
* gnu/services/spice.scm: New file.
* gnu/packages/spice.scm (spice-vdagent): Set Exec path in
spice-vdagent.desktop.
* gnu/local.mk (GNU_SYSTEM_MODULES): Add it.
---
 gnu/local.mk           |  1 +
 gnu/packages/spice.scm |  5 +++++
 gnu/services/spice.scm | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+)
 create mode 100644 gnu/services/spice.scm
Ludovic Courtès - July 29, 2016, 7:16 p.m.
David Craven <david@craven.ch> skribis:

> * gnu/services/spice.scm: New file.
> * gnu/packages/spice.scm (spice-vdagent): Set Exec path in
> spice-vdagent.desktop.
> * gnu/local.mk (GNU_SYSTEM_MODULES): Add it.

[...]

> --- a/gnu/packages/spice.scm
> +++ b/gnu/packages/spice.scm
> @@ -235,6 +235,11 @@ Internet and from a wide variety of machine architectures.")
>                 (((string-append "\\$\\(mkdir_p\\) \\$\\(DESTDIR\\)"
>                                  "\\$\\(localstatedir\\)/run/spice-vdagentd"))
>                   "-$(mkdir_p) $(DESTDIR)$(localstatedir)/run/spice-vdagentd"))
> +             #t))
> +         (add-after 'unpack 'patch-spice-vdagent.desktop
> +           (lambda _
> +             (substitute* "data/spice-vdagent.desktop"
> +                 (("Exec=/usr/bin/spice-vdagent\n") "Exec=spice-vdagent\n"))

What about:

  (lambda* (#:key outputs #:allow-other-keys)
    (substitute* …
      (…
       (string-append "Exec=" (assoc-ref outputs "out")
                      "/bin/spice-vdagent")))
    #t)

?

Also, I think this should be a separate patch as it seems to be
unrelated.

> diff --git a/gnu/services/spice.scm b/gnu/services/spice.scm
> new file mode 100644
> index 0000000..ff8f2a2
> --- /dev/null
> +++ b/gnu/services/spice.scm
> @@ -0,0 +1,55 @@

Please add a license header.

> +  (list
> +    (shepherd-service
> +      (documentation "Spice vdagentd service")
> +      (requirement '(udev))
> +      (provision '(spice-vdagentd))
> +      (start #~(make-forkexec-constructor #$@spice-vdagentd-command))

If spice-vdagend produces a PID file, make sure to use #:pid-file here
(there are several examples in the tree), which often provides more
reliable startup notification.

> +(define* (spice-vdagent-service
> +          #:optional (config (spice-vdagent-configuration)))
> +  "Start the @command{vdagentd} and @command{vdagent} deamons
> +from @var{spice-vdagent} to enable guest window resizing and
> +clipboard sharing."
> +  (service spice-vdagent-service-type config))

Could you add documentation to doc/guix.texi under “Services”, either in
an existing subsection or in a new one if that seems appropriate.  Make
sure to add one or two sentences to give context, and an @uref link to
the relevant Spice documentation.

Could you send updated patches?

Thanks!

Ludo’.
David Craven - July 29, 2016, 7:20 p.m.
> Also, I think this should be a separate patch as it seems to be
unrelated.

It's related to:

> (service-extension profile-service-type
+                               (compose list
+
spice-vdagent-configuration-spice-vdagent))))))

But ok. I'll do it first thing tomorrow =)
David Craven - July 30, 2016, 10:29 a.m.
> If spice-vdagend produces a PID file, make sure to use #:pid-file here
> (there are several examples in the tree), which often provides more
> reliable startup notification.

I'm passing the -x flag which prevents spice-vdagentd from
daemonizing. I thought that make-forkexec-constructor took care of
setting the correct stdout stderr stdin user process-parent and pid
file automatically. Is that not the way it's intended to be used?
Because otherwise a (system*) call would be enough wouldn't it?
Ludovic Courtès - July 30, 2016, 10:41 p.m.
David Craven <david@craven.ch> skribis:

>> If spice-vdagend produces a PID file, make sure to use #:pid-file here
>> (there are several examples in the tree), which often provides more
>> reliable startup notification.
>
> I'm passing the -x flag which prevents spice-vdagentd from
> daemonizing. I thought that make-forkexec-constructor took care of
> setting the correct stdout stderr stdin user process-parent and pid
> file automatically. Is that not the way it's intended to be used?

It is, but it can also wait until a PID file is created:

  https://www.gnu.org/software/shepherd/manual/html_node/Service-De_002d-and-Constructors.html

HTH!

Ludo’.
David Craven - July 31, 2016, 6:14 p.m.
> If spice-vdagend produces a PID file, make sure to use #:pid-file here
> (there are several examples in the tree), which often provides more
> reliable startup notification.

spice-vdagentd doesn't create a pid file itself. [0] [1]

I haven't updated the documentation yet because I'm running into
issues building guix, haven't figured out why yet.

guix environment guix && make

Complains about not finding sqlite3. The pc file is and the libraries
are in the profile, so it might just be guix and nixos getting at it
again. I haven't had time to investigate this further yet.

[0] https://github.com/SPICE/linux-vd_agent/blob/master/data/spice-vdagentd#L43
[1] https://github.com/SPICE/linux-vd_agent/blob/master/data/spice-vdagentd.service#L13
Ludovic Courtès - Aug. 1, 2016, 12:01 p.m.
David Craven <david@craven.ch> skribis:

>> If spice-vdagend produces a PID file, make sure to use #:pid-file here
>> (there are several examples in the tree), which often provides more
>> reliable startup notification.
>
> spice-vdagentd doesn't create a pid file itself. [0] [1]

OK.  In that case, ‘make-forkexec-constructor’ like your patch uses it
is perfect.

> I haven't updated the documentation yet because I'm running into
> issues building guix, haven't figured out why yet.
>
> guix environment guix && make
>
> Complains about not finding sqlite3. The pc file is and the libraries
> are in the profile, so it might just be guix and nixos getting at it
> again. I haven't had time to investigate this further yet.

If you used ./configure -C (to create a cache file), then you probably
have to “rm config.cache” and rerun ./configure.

Otherwise you can post config.log or stop by on IRC for a live debugging
session.  :-)

Thanks,
Ludo’.

Patch

diff --git a/gnu/local.mk b/gnu/local.mk
index c789b19..0fce83a 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -384,6 +384,7 @@  GNU_SYSTEM_MODULES =				\
   %D%/services/networking.scm			\
   %D%/services/shepherd.scm			\
   %D%/services/herd.scm				\
+  %D%/services/spice.scm				\
   %D%/services/ssh.scm				\
   %D%/services/web.scm				\
   %D%/services/xorg.scm				\
diff --git a/gnu/packages/spice.scm b/gnu/packages/spice.scm
index 1a356b0..1b538fc 100644
--- a/gnu/packages/spice.scm
+++ b/gnu/packages/spice.scm
@@ -235,6 +235,11 @@  Internet and from a wide variety of machine architectures.")
                (((string-append "\\$\\(mkdir_p\\) \\$\\(DESTDIR\\)"
                                 "\\$\\(localstatedir\\)/run/spice-vdagentd"))
                  "-$(mkdir_p) $(DESTDIR)$(localstatedir)/run/spice-vdagentd"))
+             #t))
+         (add-after 'unpack 'patch-spice-vdagent.desktop
+           (lambda _
+             (substitute* "data/spice-vdagent.desktop"
+                 (("Exec=/usr/bin/spice-vdagent\n") "Exec=spice-vdagent\n"))
              #t)))))
     (inputs
       `(("alsa-lib" ,alsa-lib)
diff --git a/gnu/services/spice.scm b/gnu/services/spice.scm
new file mode 100644
index 0000000..ff8f2a2
--- /dev/null
+++ b/gnu/services/spice.scm
@@ -0,0 +1,55 @@ 
+(define-module (gnu services spice)
+  #:use-module (gnu packages spice)
+  #:use-module (gnu services)
+  #:use-module (gnu services shepherd)
+  #:use-module (guix gexp)
+  #:use-module (guix records)
+  #:export (spice-vdagent-configuration
+            spice-vdagent-configuration?
+            spice-vdagent-service-type
+            spice-vdagent-service))
+
+(define-record-type* <spice-vdagent-configuration>
+  spice-vdagent-configuration make-spice-vdagent-configuration
+  spice-vdagent-configuration?
+  (spice-vdagent spice-vdagent-configuration-spice-vdagent
+                 (default spice-vdagent)))
+
+(define (spice-vdagent-activation config)
+  "Return the activation gexp for CONFIG."
+  #~(mkdir-p "/var/run/spice-vdagentd"))
+
+(define (spice-vdagent-shepherd-service config)
+  "Return a <shepherd-service> for spice-vdagentd with CONFIG."
+  (define spice-vdagent (spice-vdagent-configuration-spice-vdagent config))
+
+  (define spice-vdagentd-command
+    (list
+      #~(string-append #$spice-vdagent "/sbin/spice-vdagentd")
+      "-x"))
+
+  (list
+    (shepherd-service
+      (documentation "Spice vdagentd service")
+      (requirement '(udev))
+      (provision '(spice-vdagentd))
+      (start #~(make-forkexec-constructor #$@spice-vdagentd-command))
+      (stop #~(make-kill-destructor)))))
+
+(define spice-vdagent-service-type
+  (service-type (name 'spice-vdagent)
+    (extensions
+      (list (service-extension shepherd-root-service-type
+                               spice-vdagent-shepherd-service)
+            (service-extension activation-service-type
+                               spice-vdagent-activation)
+            (service-extension profile-service-type
+                               (compose list
+                                 spice-vdagent-configuration-spice-vdagent))))))
+
+(define* (spice-vdagent-service
+          #:optional (config (spice-vdagent-configuration)))
+  "Start the @command{vdagentd} and @command{vdagent} deamons
+from @var{spice-vdagent} to enable guest window resizing and
+clipboard sharing."
+  (service spice-vdagent-service-type config))