summary refs log tree commit diff
path: root/gnu/services/web.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/services/web.scm')
-rw-r--r--gnu/services/web.scm132
1 files changed, 75 insertions, 57 deletions
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index e347f5dbcc..d56e893527 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -1,6 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
-;;; Copyright © 2015-2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2015-2023 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2016 Nikita <nikita@n0.is>
 ;;; Copyright © 2016, 2017, 2018 Julien Lepiller <julien@lepiller.eu>
 ;;; Copyright © 2017, 2018, 2019 Christopher Baines <mail@cbaines.net>
@@ -790,13 +790,11 @@ of index files."
                 (nginx file run-directory shepherd-requirement)
    (let* ((nginx-binary (file-append nginx "/sbin/nginx"))
           (pid-file (in-vicinity run-directory "pid"))
+          (config-file (or file (default-nginx-config config)))
           (nginx-action
            (lambda args
              #~(lambda _
-                 (invoke #$nginx-binary "-c"
-                         #$(or file
-                               (default-nginx-config config))
-                         #$@args)
+                 (invoke #$nginx-binary "-c" #$config-file #$@args)
                  (match '#$args
                    (("-s" . _) #f)
                    (_
@@ -807,7 +805,6 @@ of index files."
                           #~#t
                           #~(read-pid-file #$pid-file))))))))
 
-     ;; TODO: Add 'reload' action.
      (list (shepherd-service
             (provision '(nginx))
             (documentation "Run the nginx daemon.")
@@ -815,7 +812,18 @@ of index files."
             (modules `((ice-9 match)
                        ,@%default-modules))
             (start (nginx-action "-p" run-directory))
-            (stop (nginx-action "-s" "stop")))))))
+            (stop (nginx-action "-s" "stop"))
+            (actions
+              (list
+               (shepherd-configuration-action config-file)
+               (shepherd-action
+                 (name 'reload)
+                 (documentation "Reload nginx configuration file and restart worker processes.
+This has the effect of killing old worker processes and starting new ones, using
+the same configuration file.  It is useful for situations where the same nginx
+configuration file can point to different things after a reload, such as
+renewed TLS certificates, or @code{include}d files.")
+                 (procedure (nginx-action "-s" "reload"))))))))))
 
 (define nginx-service-type
   (service-type (name 'nginx)
@@ -978,7 +986,7 @@ and the back-end of a Web service.")))
 
 (define php-fpm-accounts
   (match-lambda
-    (($ <php-fpm-configuration> php socket user group socket-user socket-group _ _ _ _ _ _)
+    (($ <php-fpm-configuration> php socket user group socket-user socket-group)
      `(,@(if (equal? group "php-fpm")
              '()
              (list (user-group (name "php-fpm") (system? #t))))
@@ -1147,8 +1155,7 @@ a webserver.")
 
   (package  hpcguix-web-package (default hpcguix-web)) ;file-like
 
-  ;; Specs is gexp of hpcguix-web configuration file
-  (specs    hpcguix-web-configuration-specs)
+  (specs    hpcguix-web-configuration-specs (default #f)) ;#f | gexp
   (address  hpcguix-web-configuration-address (default "127.0.0.1"))
   (port     hpcguix-web-configuration-port (default 5000)))
 
@@ -1209,8 +1216,11 @@ a webserver.")
                        "-p"
                        #$(number->string
                           (hpcguix-web-configuration-port config))
-                       (string-append "--config="
-                                      #$(scheme-file "hpcguix-web.scm" specs)))
+                       #$@(if specs
+                              #~((string-append "--config="
+                                                #$(scheme-file
+                                                   "hpcguix-web.scm" specs)))
+                              #~()))
                  #:user "hpcguix-web"
                  #:group "hpcguix-web"
                  #:environment-variables
@@ -1231,7 +1241,8 @@ a webserver.")
           (service-extension rottlog-service-type
                              (const %hpcguix-web-log-rotations))
           (service-extension shepherd-root-service-type
-                             (compose list hpcguix-web-shepherd-service))))))
+                             (compose list hpcguix-web-shepherd-service))))
+   (default-value (hpcguix-web-configuration))))
 
 
 ;;;
@@ -1438,32 +1449,40 @@ files.")
       (documentation
        "Anonimyze the given log file location with anonip.")
       (start
-       #~(lambda _
-           (unless (file-exists? #$input)
-             (mknod #$input 'fifo #o600 0))
-           (let ((pid
-                  (fork+exec-command
-                   (append
-                    (list #$(file-append (anonip-configuration-anonip config)
-                                         "/bin/anonip")
-                          (string-append "--input=" #$input)
-                          (string-append "--output=" #$output))
-                    (if #$(anonip-configuration-skip-private? config)
-                        '("--skip-private") (list))
-                    '#$(optional anonip-configuration-column "--column")
-                    '#$(optional anonip-configuration-ipv4mask "--ipv4mask")
-                    '#$(optional anonip-configuration-ipv6mask "--ipv6mask")
-                    '#$(optional anonip-configuration-increment "--increment")
-                    '#$(optional anonip-configuration-replacement
-                                 "--replacement")
-                    '#$(optional anonip-configuration-delimiter "--delimiter")
-                    '#$(optional anonip-configuration-regex "--regex"))
-                   ;; Run in a UTF-8 locale
-                   #:environment-variables
-                   (list (string-append "GUIX_LOCPATH=" #$glibc-utf8-locales
-                                        "/lib/locale")
-                         "LC_ALL=en_US.utf8"))))
-             pid)))
+       #~(lambda ()
+           (define (spawn)
+             (fork+exec-command
+              (append
+               (list #$(file-append (anonip-configuration-anonip config)
+                                    "/bin/anonip")
+                     (string-append "--input=" #$input)
+                     (string-append "--output=" #$output))
+               (if #$(anonip-configuration-skip-private? config)
+                   '("--skip-private") (list))
+               '#$(optional anonip-configuration-column "--column")
+               '#$(optional anonip-configuration-ipv4mask "--ipv4mask")
+               '#$(optional anonip-configuration-ipv6mask "--ipv6mask")
+               '#$(optional anonip-configuration-increment "--increment")
+               '#$(optional anonip-configuration-replacement
+                            "--replacement")
+               '#$(optional anonip-configuration-delimiter "--delimiter")
+               '#$(optional anonip-configuration-regex "--regex"))
+              ;; Run in a UTF-8 locale
+              #:environment-variables
+              (list (string-append "GUIX_LOCPATH=" #$glibc-utf8-locales
+                                   "/lib/locale")
+                    "LC_ALL=en_US.utf8")))
+
+           (let ((stat (stat #$input #f)))
+             (cond ((not stat)
+                    (mknod #$input 'fifo #o600 0)
+                    (spawn))
+                   ((eq? 'fifo (stat:type stat))
+                    (spawn))
+                   (else
+                    (format #t "'~a' is not a FIFO; bailing out~%"
+                            #$input)
+                    #f)))))
       (stop #~(make-kill-destructor))))))
 
 (define anonip-service-type
@@ -2126,24 +2145,23 @@ root=/srv/gemini
             (stop #~(make-kill-destructor)))))))
 
 (define agate-accounts
-  (match-lambda
-    (($ <agate-configuration> _ _ _ _ _
-                              _ _ _ _
-                              _ user group _)
-     `(,@(if (equal? group "agate")
-             '()
-             (list (user-group (name "agate") (system? #t))))
-       ,(user-group
-         (name group)
-         (system? #t))
-       ,(user-account
-         (name user)
-         (group group)
-         (supplementary-groups '("agate"))
-         (system? #t)
-         (comment "agate server user")
-         (home-directory "/var/empty")
-         (shell (file-append shadow "/sbin/nologin")))))))
+  (lambda (config)
+    (let ((group (agate-configuration-group config))
+          (user (agate-configuration-user config)))
+      `(,@(if (equal? group "agate")
+              '()
+              (list (user-group (name "agate") (system? #t))))
+        ,(user-group
+          (name group)
+          (system? #t))
+        ,(user-account
+          (name user)
+          (group group)
+          (supplementary-groups '("agate"))
+          (system? #t)
+          (comment "agate server user")
+          (home-directory "/var/empty")
+          (shell (file-append shadow "/sbin/nologin")))))))
 
 (define agate-service-type
   (service-type