[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
05/11: services: certbot: Refactor certbot command.
From: |
Clément Lassieur |
Subject: |
05/11: services: certbot: Refactor certbot command. |
Date: |
Thu, 22 Feb 2018 15:44:40 -0500 (EST) |
snape pushed a commit to branch master
in repository guix.
commit c1dfcfdf58b4a05903d6b4266ca3c04f1c4cb6e2
Author: Clément Lassieur <address@hidden>
Date: Sat Feb 10 16:06:12 2018 +0100
services: certbot: Refactor certbot command.
* gnu/services/certbot.scm (certbot-renewal-jobs, certbot-activation):
Refactor common code into certbot-command.
---
gnu/services/certbot.scm | 53 ++++++++++++++++++++++++------------------------
1 file changed, 26 insertions(+), 27 deletions(-)
diff --git a/gnu/services/certbot.scm b/gnu/services/certbot.scm
index 0b425ba..661e174 100644
--- a/gnu/services/certbot.scm
+++ b/gnu/services/certbot.scm
@@ -57,41 +57,40 @@
(body
(list "return 301 https://$host$request_uri;"))))))
-(define certbot-renewal-jobs
+(define certbot-command
(match-lambda
(($ <certbot-configuration> package webroot domains default-location)
- (match domains
- ;; Avoid pinging certbot if we have no domains.
- (() '())
- (_
- (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)))
- (string-append #$package "/bin/certbot renew"
- (string-concatenate
- (map (lambda (domain)
- (string-append " -d " domain))
- '#$domains))))))))))
+ (let* ((certbot (file-append package "/bin/certbot"))
+ (commands
+ (map
+ (lambda (domain)
+ (list certbot "certonly"
+ "--webroot" "-w" webroot
+ "-d" domain))
+ domains)))
+ (program-file
+ "certbot-command"
+ #~(let ((code 0))
+ (for-each
+ (lambda (command)
+ (set! code (or (apply system* command) code)))
+ '#$commands) code))))))
-(define certbot-activation
- (match-lambda
+(define (certbot-renewal-jobs config)
+ (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)
(with-imported-modules '((guix build utils))
#~(begin
(use-modules (guix build utils))
(mkdir-p #$webroot)
- (for-each
- (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))))))
+ (zero? (system* #$(certbot-command config))))))))
(define certbot-nginx-server-configurations
(match-lambda
- branch master updated (5c213d1 -> fece75f), Clément Lassieur, 2018/02/22
- 01/11: services: certbot: Listen on IPv6., Clément Lassieur, 2018/02/22
- 03/11: services: certbot: Fix indentation., Clément Lassieur, 2018/02/22
- 02/11: services: certbot: Run certbot twice a day at a random minute., Clément Lassieur, 2018/02/22
- 08/11: doc: Fix typo in certbot-configuration description., Clément Lassieur, 2018/02/22
- 05/11: services: certbot: Refactor certbot command.,
Clément Lassieur <=
- 06/11: services: certbot: Get certbot to run non-interactively., Clément Lassieur, 2018/02/22
- 09/11: services: certbot: Allow to set RSA key size., Clément Lassieur, 2018/02/22
- 04/11: services: certbot: Rename 'host' to 'domain'., Clément Lassieur, 2018/02/22
- 11/11: services: certbot: Allow to set a deploy hook., Clément Lassieur, 2018/02/22
- 07/11: services: certbot: Associate one certificate with several domains., Clément Lassieur, 2018/02/22
- 10/11: services: certbot: Add verbosity., Clément Lassieur, 2018/02/22