guix-devel
[Top][All Lists]
Advanced

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

Re: Defining user services in Guix.


From: Danny Milosavljevic
Subject: Re: Defining user services in Guix.
Date: Sat, 22 Apr 2017 20:31:31 +0200

Hi Mathieu,

personally, I'd just start it inside ~/.xinitrc, ~/.xsession, 
~/.fluxbox/startup or similar.  That's a little old-school, though, but it's 
how I always did those things.  The disadvantage is that if redshift crashes, 
it's not being brought back up.

But you can start your own shepherd under your user account and have that 
shepherd manage user services - it's nice.

Create a file ${XDG_CONFIG_HOME-.config}/shepherd/init.scm and put your 
services there:

(use-modules (shepherd service))

(define redshift (make <service> #:provides '(redshift) #:start ...))
(register-services redshift) ; Note: if there has already been a 
(register-services) form, replace it

You can then launch your own shepherd:

address@hidden $ shepherd

And manage it using herd:

address@hidden $ herd start redshift

You can also load files at runtime using:

$ herd load shepherd ~/bla.scm

See also

$ info shepherd

Unfortunately, it still doesn't respawn redshift if it dies - it seems to 
require a pid file for that (#:start (make-forkexec-constructor ... #:pid-file 
"xxx.pid") and you have to specify #:respawn? #t.  The invoked program then has 
to create "xxx.pid").  I think it would be a nice addition to have it monitor 
the process that make-forkexec-constructor invoked - without any pid file.  
Maybe it's even a bug...

To reproduce:

address@hidden ~/.config/shepherd$ cat init.scm 

(use-modules (shepherd service))

(define redshift
  (make <service>
        #:provides '(redshift)
        #:start (make-forkexec-constructor
                 '("/run/current-system/profile/bin/xterm") ; to make it more 
obvious
)
        #:stop (make-kill-destructor)
        #:respawn? #t))
(register-services redshift)

;; Services known to shepherd:
;; Add new services (defined using 'make <service>') to shepherd here by
;; providing them as arguments to 'register-services'.
;(register-services)

;; Send shepherd into the background
(action 'shepherd 'daemonize)

;; Services to start when shepherd starts:
;; Add the name of each service that should be started to the list
;; below passed to 'for-each'.
(for-each start '())

address@hidden ~/.config/shepherd$ shepherd
address@hidden ~/.config/shepherd$ herd start redshift
<xterm pops up>
<exit it>
<xterm doesn't pop up again... bug?>

At first I thought that was because a regular exit is not bad - so I did 
instead:
address@hidden ~/.config/shepherd$ herd start redshift
<xterm pops up>
address@hidden ~/.config/shepherd$ herd status redshift
<note pid>
address@hidden ~/.config/shepherd$ kill -9 <pid>
<xterm doesn't pop up again... bug?>

On the plus side, you have access to the correct DISPLAY and XAUTHORITY just 
fine there.



reply via email to

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