[Top][All Lists]

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

Custom Service Definition for Caddy

From: Cameron
Subject: Custom Service Definition for Caddy
Date: Tue, 26 Jan 2021 11:02:58 -0600
User-agent: Cyrus-JMAP/3.5.0-alpha0-78-g36b56e8-fm-20210120.001-g36b56e88

Hello again everyone!

I'm having a great time learning about Guix, but am struggling with defining a 
custom service for Caddy. The 'caddy' package below works as expected -- 
installing it puts the "caddy" binary in $PATH and it works fine when I run it 
from a shell.

(define caddy
   (name "caddy")
   (version "2.2.1")
     (method url-fetch/tarbomb)
     (uri (string-append 
""; version "/caddy_" 
version "_linux_amd64.tar.gz"))

   (build-system copy-build-system)

    '(#:install-plan '(("caddy" "bin/caddy"))))
   (synopsis "This is a *BAD* Caddy package. It just pulls the already-built 
binary from Github, rather than building from source.")
   (description "See";)
   (home-page "";)
   (license licenses:asl2.0)))

What doesn't work as expected is this service definition:

(define-record-type* <caddy-configuration>
  caddy-configuration  make-caddy-configuration caddy-configuration?
  (config-file          caddy-configuration-config-file
                        (default "/etc/Caddyfile")))

(define caddy-service-type
   (lambda (config)
      (documentation "Run the caddy daemon (caddy).")
      (provision '(caddy))
      (requirement '(user-processes))
      (start #~(make-forkexec-constructor
                             (list "caddy" "run"
                                   "-config" "/etc/Caddyfile")
                                   #:log-file "/var/log/caddy.log"))
      (stop #~(make-kill-destructor))))))

...which I then add to my services list in config.scm like this:

                         (service caddy-service-type
                                   (config-file "/etc/Caddyfile")))

With this setup, 'herd start caddy' hangs for 30 seconds, during which time the 
server is active and taking traffic according to the config in /etc/Caddyfile 
but then something (presumably Shepherd) sends it a SIGTERM and it dutifully 
shuts down. The 'herd start caddy' then exits with an error:

root@tindall ~# START=$(date +%s); herd start caddy; END=$(date +%s); echo 
$(($END - START))
Service caddy could not be started.
herd: failed to start service caddy
root@tindall ~# tail -n 1 /var/log/caddy.log 
root@tindall ~# 

'caddy run' will keep caddy in the foreground, but I see the same behavior when 
I use 'caddy start' (which forks another process for the daemon and exits 
immediately) in the service definition instead.

I suspect something is wrong with the 'start' procedure I've defined, but I'm 
struggling to figure out what it is.

What am I missing?


reply via email to

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