mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2024-12-26 06:18:07 -05:00
services: certbot: Refactor certbot command.
* gnu/services/certbot.scm (certbot-renewal-jobs, certbot-activation): Refactor common code into certbot-command.
This commit is contained in:
parent
966fd7b7e9
commit
c1dfcfdf58
1 changed files with 26 additions and 27 deletions
|
@ -57,41 +57,40 @@ (define-record-type* <certbot-configuration>
|
||||||
(body
|
(body
|
||||||
(list "return 301 https://$host$request_uri;"))))))
|
(list "return 301 https://$host$request_uri;"))))))
|
||||||
|
|
||||||
(define certbot-renewal-jobs
|
(define certbot-command
|
||||||
(match-lambda
|
(match-lambda
|
||||||
(($ <certbot-configuration> package webroot domains default-location)
|
(($ <certbot-configuration> package webroot domains default-location)
|
||||||
(match domains
|
(let* ((certbot (file-append package "/bin/certbot"))
|
||||||
;; Avoid pinging certbot if we have no domains.
|
(commands
|
||||||
(() '())
|
(map
|
||||||
(_
|
(lambda (domain)
|
||||||
(list
|
(list certbot "certonly"
|
||||||
;; Attempt to renew the certificates twice per day, at a random
|
"--webroot" "-w" webroot
|
||||||
;; minute within the hour. See
|
"-d" domain))
|
||||||
;; https://certbot.eff.org/all-instructions/.
|
domains)))
|
||||||
#~(job '(next-minute-from (next-hour '(0 12)) (list (random 60)))
|
(program-file
|
||||||
(string-append #$package "/bin/certbot renew"
|
"certbot-command"
|
||||||
(string-concatenate
|
#~(let ((code 0))
|
||||||
(map (lambda (domain)
|
(for-each
|
||||||
(string-append " -d " domain))
|
(lambda (command)
|
||||||
'#$domains))))))))))
|
(set! code (or (apply system* command) code)))
|
||||||
|
'#$commands) code))))))
|
||||||
|
|
||||||
(define certbot-activation
|
(define (certbot-renewal-jobs config)
|
||||||
(match-lambda
|
(list
|
||||||
|
;; Attempt to renew the certificates twice per day, at a random minute
|
||||||
|
;; within the hour. See https://certbot.eff.org/all-instructions/.
|
||||||
|
#~(job '(next-minute-from (next-hour '(0 12)) (list (random 60)))
|
||||||
|
#$(certbot-command config))))
|
||||||
|
|
||||||
|
(define (certbot-activation config)
|
||||||
|
(match config
|
||||||
(($ <certbot-configuration> package webroot domains default-location)
|
(($ <certbot-configuration> package webroot domains default-location)
|
||||||
(with-imported-modules '((guix build utils))
|
(with-imported-modules '((guix build utils))
|
||||||
#~(begin
|
#~(begin
|
||||||
(use-modules (guix build utils))
|
(use-modules (guix build utils))
|
||||||
(mkdir-p #$webroot)
|
(mkdir-p #$webroot)
|
||||||
(for-each
|
(zero? (system* #$(certbot-command config))))))))
|
||||||
(lambda (domain)
|
|
||||||
(unless (file-exists?
|
|
||||||
(in-vicinity "/etc/letsencrypt/live" domain))
|
|
||||||
(unless (zero? (system*
|
|
||||||
(string-append #$certbot "/bin/certbot")
|
|
||||||
"certonly" "--webroot" "-w" #$webroot
|
|
||||||
"-d" domain))
|
|
||||||
(error "failed to acquire cert for domain" domain))))
|
|
||||||
'#$domains))))))
|
|
||||||
|
|
||||||
(define certbot-nginx-server-configurations
|
(define certbot-nginx-server-configurations
|
||||||
(match-lambda
|
(match-lambda
|
||||||
|
|
Loading…
Reference in a new issue