bug#67802: Shepherd is not able to run simple networked programs as services

2023-12-17 Thread Ludovic Courtès
Hi,

Lars Rustand  skribis:

> So, I figured this out. It had nothing to do with networking even though
> it looked like it. The problem was that I had cargo cult-copied a
> #:pid-file parameter from another service, believing that this was just
> a path were Shepherd could create a pid-file for the service, but
> Shepherd was in fact expecting the program to create the pid-file. So
> when the program did not create this pid-file then Shepherd killed the
> program.
>
> So the original bug I reported is in fact not a bug at all and can be
> closed. However, the error handling in Shepherd could be improved in
> order to make it more clear what is happening.

Good that you found the issue!  I improved logging for this particular
case as a result of this report:

  
https://git.savannah.gnu.org/cgit/shepherd.git/commit/?id=ace4a3b2dba43b826640d5c1ca970f9040d27416

Thanks for reporting it,
Ludo’.





bug#67802: Shepherd is not able to run simple networked programs as services

2023-12-15 Thread Lars Rustand


Lars Rustand  writes:

> Hello, I have created two very simple shepherd services for two
> different mail programs (offlineimap and davmail). Both of the programs
> are able to run without problem when ran from the commandline, but both
> of them fail with networking related errors when I try to run them as
> shepherd services.
...
> They both seem to fail when opening an *outgoing* socket, but davmail
> seems to be able to start *listening* on several ports just fine.

So, I figured this out. It had nothing to do with networking even though
it looked like it. The problem was that I had cargo cult-copied a
#:pid-file parameter from another service, believing that this was just
a path were Shepherd could create a pid-file for the service, but
Shepherd was in fact expecting the program to create the pid-file. So
when the program did not create this pid-file then Shepherd killed the
program.

So the original bug I reported is in fact not a bug at all and can be
closed. However, the error handling in Shepherd could be improved in
order to make it more clear what is happening.





bug#67802: Shepherd is not able to run simple networked programs as services

2023-12-12 Thread Lars Rustand


Hello, I have created two very simple shepherd services for two
different mail programs (offlineimap and davmail). Both of the programs
are able to run without problem when ran from the commandline, but both
of them fail with networking related errors when I try to run them as
shepherd services.

I have read all the relevant sections of the manual and looked at
similar shepherd services in the source code, but I can't find anything
that I am missing in my services. I am either missing something obvious
here or shepherd is doing something weird that messes up these programs.

Here is my service definition for offlineimap:

--8<---cut here---start->8---
(define-module (lrustand services offlineimap)
  #:use-module (gnu)
  #:use-module (gnu services)
  #:use-module (gnu packages mail)
  #:use-module (gnu services shepherd)
  #:use-module (gnu services configuration)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (ice-9 curried-definitions)
  #:use-module (gnu home services)
  ;; For the 'home-shepherd-service-type' mapping.
  #:use-module (gnu home services shepherd)
  #:export (offlineimap-configuration
offlineimap-configuration?

offlineimap-configuration-log-file
offlineimap-configuration-pid-file

offlineimap-shepherd-service
offlineimap-service-type
home-offlineimap-service-type))

(define-configuration/no-serialization offlineimap-configuration
  (pid-file
   (string "/var/run/offlineimap.pid")
   "Where to store the PID file.")
  (config-file
   (string "/home/lars/.config/offlineimap/config")
   "Configuration file to use.")
  (log-file
   (string "/home/lars/offlineimap.log")
   "File where ‘offlineimap’ writes its log to.")
  (user
   (string "lars")
   "")
  (extra-options
   (list-of-strings '())
   "This option provides an “escape hatch” for the user to provide
arbitrary command-line arguments to ‘offlineimap’ as a list of strings.")
  (home-service?
   (boolean for-home?)
   ""))

(define offlineimap-shepherd-service
  (match-record-lambda 
(pid-file config-file log-file user extra-options home-service?)
(list (shepherd-service
   (provision '(offlineimap))
   (documentation "")
   (requirement (if home-service? '() '(networking user-processes)))
   (start #~(make-forkexec-constructor
  (list (string-append #$offlineimap
   "/bin/offlineimap")
 #$@extra-options
 "-c" #$config-file
 "-l" #$log-file)
 #:user #$user
 #:environment-variables
 (list (string-append "HOME=" (passwd:dir (getpw #$user
 #:log-file #$log-file
 #:pid-file #$pid-file))
   (stop #~(make-kill-destructor))
   (one-shot? #f)
   (respawn? #t)

(define offlineimap-service-type
  (service-type
   (name 'offlineimap)
   (extensions
(list (service-extension shepherd-root-service-type
 offlineimap-shepherd-service)))
   (default-value (offlineimap-configuration))
   (description
"Synchronize remote IMAP mail with local Maildir.")))

(define home-offlineimap-service-type
  (service-type
   (inherit (system->home-service-type offlineimap-service-type))
   (default-value (for-home (offlineimap-configuration)
--8<---cut here---end--->8---



And here is my service definition for davmail:


--8<---cut here---start->8---
(define-module (lrustand services davmail)
  #:use-module (gnu)
  #:use-module (gnu services)
  #:use-module (gnu packages mail)
  #:use-module (gnu services shepherd)
  #:use-module (gnu services configuration)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module (ice-9 curried-definitions)
  #:use-module (gnu home services)
  ;; For the 'home-shepherd-service-type' mapping.
  #:use-module (gnu home services shepherd)
  #:export (davmail-configuration
davmail-configuration?

davmail-configuration-log-file
davmail-configuration-pid-file

davmail-shepherd-service
davmail-service-type
home-davmail-service-type))

(define-configuration/no-serialization davmail-configuration
  (pid-file
   (string "/var/run/davmail.pid")
   "Where to store the PID file.")
  (config-file
   (string "/home/lars/.config/davmail/davmail.properties")
   "Configuration file to use.")
  (log-file
   (string "/home/lars/davmail.log")
   "File where ‘davmail’ writes its log to.")
  (extra-options
   (list-of-strings '())
   "This option provides an “escape hatch” for the user to provide
arbitrary command-line arguments to ‘davmail’ as a list of strings.")
  (home-service?
   (boolean for-home?)
   ""))

(define