services: web: Add support for configuring the nginx server names hash.

The nginx service can fail to start if the server names hash bucket size is
too small, which can happen on some systems, and when using QEMU, depending on
the CPU.

* gnu/services/web.scm (<nginx-configuration>): Add
  server-names-hash-bucket-size and server-names-hash-bucket-max-size.
  (default-nginx-config): Add support for the new hash bucket size parameters.
  (nginx-service, nginx-activation): Pass the new hash bucket size parameters
  through to the default-nginx-config procedure.
* doc/guix.texi (Web Services): Document the new hash bucket size parameters.
This commit is contained in:
Christopher Baines 2017-11-25 11:57:37 +00:00
parent c48aa70a9a
commit 2881f85220
No known key found for this signature in database
GPG Key ID: 5E28A33B0B84F577
2 changed files with 38 additions and 5 deletions

View File

@ -14913,6 +14913,13 @@ This can be useful if you have an existing configuration file, or it's
not possible to do what is required through the other parts of the not possible to do what is required through the other parts of the
nginx-configuration record. nginx-configuration record.
@item @code{server-names-hash-bucket-size} (default: @code{#f})
Bucket size for the server names hash tables, defaults to @code{#f} to
use the size of the processors cache line.
@item @code{server-names-hash-bucket-max-size} (default: @code{#f})
Maximum bucket size for the server names hash tables.
@end table @end table
@end deffn @end deffn

View File

@ -38,6 +38,8 @@
nginx-configuration-run-directory nginx-configuration-run-directory
nginx-configuration-server-blocks nginx-configuration-server-blocks
nginx-configuration-upstream-blocks nginx-configuration-upstream-blocks
nginx-configuration-server-names-hash-bucket-size
nginx-configuration-server-names-hash-bucket-max-size
nginx-configuration-file nginx-configuration-file
<nginx-server-configuration> <nginx-server-configuration>
@ -141,6 +143,10 @@
(default '())) ;list of <nginx-server-configuration> (default '())) ;list of <nginx-server-configuration>
(upstream-blocks nginx-configuration-upstream-blocks (upstream-blocks nginx-configuration-upstream-blocks
(default '())) ;list of <nginx-upstream-configuration> (default '())) ;list of <nginx-upstream-configuration>
(server-names-hash-bucket-size nginx-configuration-server-names-hash-bucket-size
(default #f))
(server-names-hash-bucket-max-size nginx-configuration-server-names-hash-bucket-max-size
(default #f))
(file nginx-configuration-file ;#f | string | file-like (file nginx-configuration-file ;#f | string | file-like
(default #f))) (default #f)))
@ -225,7 +231,9 @@ of index files."
(cons head out))) (cons head out)))
(fold-right flatten1 '() lst)) (fold-right flatten1 '() lst))
(define (default-nginx-config nginx log-directory run-directory server-list upstream-list) (define (default-nginx-config nginx log-directory run-directory server-list
upstream-list server-names-hash-bucket-size
server-names-hash-bucket-max-size)
(apply mixed-text-file "nginx.conf" (apply mixed-text-file "nginx.conf"
(flatten (flatten
"user nginx nginx;\n" "user nginx nginx;\n"
@ -239,6 +247,18 @@ of index files."
" scgi_temp_path " run-directory "/scgi_temp;\n" " scgi_temp_path " run-directory "/scgi_temp;\n"
" access_log " log-directory "/access.log;\n" " access_log " log-directory "/access.log;\n"
" include " nginx "/share/nginx/conf/mime.types;\n" " include " nginx "/share/nginx/conf/mime.types;\n"
(if server-names-hash-bucket-size
(string-append
" server_names_hash_bucket_size "
(number->string server-names-hash-bucket-size)
";\n")
"")
(if server-names-hash-bucket-max-size
(string-append
" server_names_hash_bucket_max_size "
(number->string server-names-hash-bucket-max-size)
";\n")
"")
"\n" "\n"
(map emit-nginx-upstream-config upstream-list) (map emit-nginx-upstream-config upstream-list)
(map emit-nginx-server-config server-list) (map emit-nginx-server-config server-list)
@ -258,7 +278,8 @@ of index files."
(define nginx-activation (define nginx-activation
(match-lambda (match-lambda
(($ <nginx-configuration> nginx log-directory run-directory server-blocks (($ <nginx-configuration> nginx log-directory run-directory server-blocks
upstream-blocks file) upstream-blocks server-names-hash-bucket-size
server-names-hash-bucket-max-size file)
#~(begin #~(begin
(use-modules (guix build utils)) (use-modules (guix build utils))
@ -279,13 +300,16 @@ of index files."
(system* (string-append #$nginx "/sbin/nginx") (system* (string-append #$nginx "/sbin/nginx")
"-c" #$(or file "-c" #$(or file
(default-nginx-config nginx log-directory (default-nginx-config nginx log-directory
run-directory server-blocks upstream-blocks)) run-directory server-blocks upstream-blocks
server-names-hash-bucket-size
server-names-hash-bucket-max-size))
"-t"))))) "-t")))))
(define nginx-shepherd-service (define nginx-shepherd-service
(match-lambda (match-lambda
(($ <nginx-configuration> nginx log-directory run-directory server-blocks (($ <nginx-configuration> nginx log-directory run-directory server-blocks
upstream-blocks file) upstream-blocks server-names-hash-bucket-size
server-names-hash-bucket-max-size file)
(let* ((nginx-binary (file-append nginx "/sbin/nginx")) (let* ((nginx-binary (file-append nginx "/sbin/nginx"))
(nginx-action (nginx-action
(lambda args (lambda args
@ -294,7 +318,9 @@ of index files."
(system* #$nginx-binary "-c" (system* #$nginx-binary "-c"
#$(or file #$(or file
(default-nginx-config nginx log-directory (default-nginx-config nginx log-directory
run-directory server-blocks upstream-blocks)) run-directory server-blocks upstream-blocks
server-names-hash-bucket-size
server-names-hash-bucket-max-size))
#$@args)))))) #$@args))))))
;; TODO: Add 'reload' action. ;; TODO: Add 'reload' action.