all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* add shepherd requirement to an existing service?
@ 2024-03-11 11:04 Remco van 't Veer
  2024-03-11 18:59 ` Oleg Pykhalov
  0 siblings, 1 reply; 5+ messages in thread
From: Remco van 't Veer @ 2024-03-11 11:04 UTC (permalink / raw)
  To: help-guix

Hi,

I'd like to add a shepherd requirement to an existing service, as
provided by guix, to prevent it from starting before some other service
starts.

For exampple: I have NAS which is very slow to start after a power
failure so I created a simple service to keep trying to mount an NFS
share until it succeeds.  This share contains files shared through
syncthing, so I want syncthing to start after the NFS service is
started.

Is there any way to do this apart from defining my own
syncthing-shepherd-service which includes the extra shepherd
requirement?

Kind regards,
Remco


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: add shepherd requirement to an existing service?
  2024-03-11 11:04 add shepherd requirement to an existing service? Remco van 't Veer
@ 2024-03-11 18:59 ` Oleg Pykhalov
  2024-03-12 10:25   ` Remco van 't Veer
  0 siblings, 1 reply; 5+ messages in thread
From: Oleg Pykhalov @ 2024-03-11 18:59 UTC (permalink / raw)
  To: Remco van 't Veer; +Cc: help-guix

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

Hi,

Remco van 't Veer <remco@remworks.net> writes:

> I'd like to add a shepherd requirement to an existing service, as
> provided by guix, to prevent it from starting before some other service
> starts.
>
> For exampple: I have NAS which is very slow to start after a power
> failure so I created a simple service to keep trying to mount an NFS
> share until it succeeds.  This share contains files shared through
> syncthing, so I want syncthing to start after the NFS service is
> started.

How do you mount the NFS share? From my understanding, system services
typically wait for all mounts listed in 'file-systems' to be mounted
unless 'mount?' is specifically set to false.

> Is there any way to do this apart from defining my own
> syncthing-shepherd-service which includes the extra shepherd
> requirement?

To my knowledge, unless the service definition explicitly allows for it,
there may not be an alternative approach aside from creating a custom
syncthing-shepherd service that incorporates the additional shepherd
requirement.

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: add shepherd requirement to an existing service?
  2024-03-11 18:59 ` Oleg Pykhalov
@ 2024-03-12 10:25   ` Remco van 't Veer
  2024-03-14 17:54     ` Richard Sent
  0 siblings, 1 reply; 5+ messages in thread
From: Remco van 't Veer @ 2024-03-12 10:25 UTC (permalink / raw)
  To: Oleg Pykhalov; +Cc: help-guix

Hi Oleg,

2024/03/11, Oleg Pykhalov:

>> I'd like to add a shepherd requirement to an existing service, as
>> provided by guix, to prevent it from starting before some other service
>> starts.
>>
>> For exampple: I have NAS which is very slow to start after a power
>> failure so I created a simple service to keep trying to mount an NFS
>> share until it succeeds.  This share contains files shared through
>> syncthing, so I want syncthing to start after the NFS service is
>> started.
>
> How do you mount the NFS share? From my understanding, system services
> typically wait for all mounts listed in 'file-systems' to be mounted
> unless 'mount?' is specifically set to false.

I tried the file-systems declaration about a year ago but found it
didn't work all the time when automatically booting after a power
failure.  There's also routers and stuff booting at the same time so
the order of things may have been an issue.  Anyway, a simple service
trying to mount until it succeeds works pretty reliably.

>> Is there any way to do this apart from defining my own
>> syncthing-shepherd-service which includes the extra shepherd
>> requirement?
>
> To my knowledge, unless the service definition explicitly allows for it,
> there may not be an alternative approach aside from creating a custom
> syncthing-shepherd service that incorporates the additional shepherd
> requirement.

I was afraid so.  There may be other situations where I'd like some
home grown service to startup before another pre-existing one, so maybe
this should be a feature request, if others are also running into this.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: add shepherd requirement to an existing service?
  2024-03-12 10:25   ` Remco van 't Veer
@ 2024-03-14 17:54     ` Richard Sent
  2024-03-15  9:22       ` Remco van 't Veer
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Sent @ 2024-03-14 17:54 UTC (permalink / raw)
  To: Remco van 't Veer; +Cc: Oleg Pykhalov, help-guix

If this winds up being something you do frequently, it may be possible
to write a function to modify the service type. See [1] as an example. I
suspect your code would be smaller, something like

--8<---------------cut here---------------start------------->8---
(define (depend-on type new-requirement)
  "Returns a @code{service-type} record derived from @var{type} with any
  shepherd extensions additionally depending on @var{new-requirement}."
  (service-type
   (inherit type)
   (extensions
    (map (lambda (extension)
           (let ((target (service-extension-target extension))
                 (compute (service-extension-compute extension)))
             (if (eq? target shepherd-root-service-type)
                 (service-extension shepherd-root-service-type
                                    (lambda (config)
                                      (map (lambda (service)
                                             (shepherd-service
                                              (inherit service)
                                              (requirement
                                               (cons*
                                                new-requirement
                                                (shepherd-service-requirement config)))))
                                           (compute config))))
                 extension)))
         (service-type-extensions type)))))
--8<---------------cut here---------------end--------------->8---

This code might not be it exactly, but something similar to this
/should/ work.

[1] https://git.sr.ht/~freakingpenguin/rsent/tree/master/item/channel/rsent/utils/services.scm


-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: add shepherd requirement to an existing service?
  2024-03-14 17:54     ` Richard Sent
@ 2024-03-15  9:22       ` Remco van 't Veer
  0 siblings, 0 replies; 5+ messages in thread
From: Remco van 't Veer @ 2024-03-15  9:22 UTC (permalink / raw)
  To: Richard Sent; +Cc: help-guix

That's exactly what I need!  Thanks!


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-15  9:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11 11:04 add shepherd requirement to an existing service? Remco van 't Veer
2024-03-11 18:59 ` Oleg Pykhalov
2024-03-12 10:25   ` Remco van 't Veer
2024-03-14 17:54     ` Richard Sent
2024-03-15  9:22       ` Remco van 't Veer

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.