services: nginx: Add support the 'upstream' module.
* gnu/services/web.scm (<nginx-upstream-configuration>): New record type. (<nginx-configuration>): Add new field upstream-blocks. (nginx-upstream): New function. (default-nginx-config): Add upstream-list parameter. (nginx-service): Add optional upstream list keyword argument. * doc/guix.texi (Web Services): Document the new nginx-upstream-configuration data type and changes to the nginx function. Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
cb6d322afc
commit
cb341293fa
|
@ -12323,6 +12323,7 @@ The @code{(gnu services web)} module provides the following service:
|
||||||
[#:log-directory ``/var/log/nginx''] @
|
[#:log-directory ``/var/log/nginx''] @
|
||||||
[#:run-directory ``/var/run/nginx''] @
|
[#:run-directory ``/var/run/nginx''] @
|
||||||
[#:server-list '()] @
|
[#:server-list '()] @
|
||||||
|
[#:upstream-list '()] @
|
||||||
[#:config-file @code{#f}]
|
[#:config-file @code{#f}]
|
||||||
|
|
||||||
Return a service that runs @var{nginx}, the nginx web server.
|
Return a service that runs @var{nginx}, the nginx web server.
|
||||||
|
@ -12334,8 +12335,10 @@ arguments should match what is in @var{config-file} to ensure that the
|
||||||
directories are created when the service is activated.
|
directories are created when the service is activated.
|
||||||
|
|
||||||
As an alternative to using a @var{config-file}, @var{server-list} can be
|
As an alternative to using a @var{config-file}, @var{server-list} can be
|
||||||
used to specify the list of @dfn{server blocks} required on the host. For
|
used to specify the list of @dfn{server blocks} required on the host and
|
||||||
this to work, use the default value for @var{config-file}.
|
@var{upstream-list} can be used to specify a list of @dfn{upstream
|
||||||
|
blocks} to configure. For this to work, use the default value for
|
||||||
|
@var{config-file}.
|
||||||
|
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
@ -12753,6 +12756,25 @@ Defaults to @samp{#f}.
|
||||||
@c %end of automatic openvpn-server documentation
|
@c %end of automatic openvpn-server documentation
|
||||||
|
|
||||||
|
|
||||||
|
@deftp {Data Type} nginx-upstream-configuration
|
||||||
|
Data type representing the configuration of an nginx @code{upstream}
|
||||||
|
block. This type has the following parameters:
|
||||||
|
|
||||||
|
@table @asis
|
||||||
|
@item @code{name}
|
||||||
|
Name for this group of servers.
|
||||||
|
|
||||||
|
@item @code{servers}
|
||||||
|
Specify the addresses of the servers in the group. The address can be
|
||||||
|
specified as a IP address (e.g. @samp{127.0.0.1}), domain name
|
||||||
|
(e.g. @samp{backend1.example.com}) or a path to a UNIX socket using the
|
||||||
|
prefix @samp{unix:}. For addresses using an IP address or domain name,
|
||||||
|
the default port is 80, and a different port can be specified
|
||||||
|
explicitly.
|
||||||
|
|
||||||
|
@end table
|
||||||
|
@end deftp
|
||||||
|
|
||||||
@node Network File System
|
@node Network File System
|
||||||
@subsubsection Network File System
|
@subsubsection Network File System
|
||||||
@cindex NFS
|
@cindex NFS
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
|
;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
|
||||||
;;; Copyright © 2016 ng0 <ng0@we.make.ritual.n0.is>
|
;;; Copyright © 2016 ng0 <ng0@we.make.ritual.n0.is>
|
||||||
;;; Copyright © 2016 Julien Lepiller <julien@lepiller.eu>
|
;;; Copyright © 2016 Julien Lepiller <julien@lepiller.eu>
|
||||||
|
;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
|
||||||
;;;
|
;;;
|
||||||
;;; This file is part of GNU Guix.
|
;;; This file is part of GNU Guix.
|
||||||
;;;
|
;;;
|
||||||
|
@ -33,6 +34,8 @@
|
||||||
nginx-configuration?
|
nginx-configuration?
|
||||||
nginx-server-configuration
|
nginx-server-configuration
|
||||||
nginx-server-configuration?
|
nginx-server-configuration?
|
||||||
|
nginx-upstream-configuration
|
||||||
|
nginx-upstream-configuration?
|
||||||
nginx-service
|
nginx-service
|
||||||
nginx-service-type))
|
nginx-service-type))
|
||||||
|
|
||||||
|
@ -62,6 +65,12 @@
|
||||||
(server-tokens? nginx-server-configuration-server-tokens?
|
(server-tokens? nginx-server-configuration-server-tokens?
|
||||||
(default #f)))
|
(default #f)))
|
||||||
|
|
||||||
|
(define-record-type* <nginx-upstream-configuration>
|
||||||
|
nginx-upstream-configuration make-nginx-upstream-configuration
|
||||||
|
nginx-upstream-configuration?
|
||||||
|
(name nginx-upstream-configuration-name)
|
||||||
|
(servers nginx-upstream-configuration-servers))
|
||||||
|
|
||||||
(define-record-type* <nginx-configuration>
|
(define-record-type* <nginx-configuration>
|
||||||
nginx-configuration make-nginx-configuration
|
nginx-configuration make-nginx-configuration
|
||||||
nginx-configuration?
|
nginx-configuration?
|
||||||
|
@ -69,6 +78,7 @@
|
||||||
(log-directory nginx-configuration-log-directory) ;string
|
(log-directory nginx-configuration-log-directory) ;string
|
||||||
(run-directory nginx-configuration-run-directory) ;string
|
(run-directory nginx-configuration-run-directory) ;string
|
||||||
(server-blocks nginx-configuration-server-blocks) ;list
|
(server-blocks nginx-configuration-server-blocks) ;list
|
||||||
|
(upstream-blocks nginx-configuration-upstream-blocks) ;list
|
||||||
(file nginx-configuration-file)) ;string | file-like
|
(file nginx-configuration-file)) ;string | file-like
|
||||||
|
|
||||||
(define (config-domain-strings names)
|
(define (config-domain-strings names)
|
||||||
|
@ -116,11 +126,19 @@ of index files."
|
||||||
" index " (config-index-strings (nginx-server-configuration-index server)) ";\n"
|
" index " (config-index-strings (nginx-server-configuration-index server)) ";\n"
|
||||||
" server_tokens " (if (nginx-server-configuration-server-tokens? server)
|
" server_tokens " (if (nginx-server-configuration-server-tokens? server)
|
||||||
"on" "off") ";\n"
|
"on" "off") ";\n"
|
||||||
|
" }\n"))
|
||||||
|
|
||||||
|
(define (nginx-upstream-config upstream)
|
||||||
|
(string-append
|
||||||
|
" upstream " (nginx-upstream-configuration-name upstream) " {\n"
|
||||||
|
(string-concatenate
|
||||||
|
(map (lambda (server)
|
||||||
|
(simple-format #f " server ~A;\n" server))
|
||||||
|
(nginx-upstream-configuration-servers upstream)))
|
||||||
" }\n"))
|
" }\n"))
|
||||||
|
|
||||||
(define (default-nginx-config log-directory run-directory server-list)
|
(define (default-nginx-config log-directory run-directory server-list upstream-list)
|
||||||
(plain-file "nginx.conf"
|
(mixed-text-file "nginx.conf"
|
||||||
(string-append
|
|
||||||
"user nginx nginx;\n"
|
"user nginx nginx;\n"
|
||||||
"pid " run-directory "/pid;\n"
|
"pid " run-directory "/pid;\n"
|
||||||
"error_log " log-directory "/error.log info;\n"
|
"error_log " log-directory "/error.log info;\n"
|
||||||
|
@ -131,12 +149,18 @@ of index files."
|
||||||
" uwsgi_temp_path " run-directory "/uwsgi_temp;\n"
|
" uwsgi_temp_path " run-directory "/uwsgi_temp;\n"
|
||||||
" 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"
|
||||||
|
"\n"
|
||||||
|
(string-join
|
||||||
|
(filter (lambda (section) (not (null? section)))
|
||||||
|
(map nginx-upstream-config upstream-list))
|
||||||
|
"\n")
|
||||||
|
"\n"
|
||||||
(let ((http (map default-nginx-server-config server-list)))
|
(let ((http (map default-nginx-server-config server-list)))
|
||||||
(do ((http http (cdr http))
|
(do ((http http (cdr http))
|
||||||
(block "" (string-append (car http) "\n" block )))
|
(block "" (string-append (car http) "\n" block )))
|
||||||
((null? http) block)))
|
((null? http) block)))
|
||||||
"}\n"
|
"}\n"
|
||||||
"events {}\n")))
|
"events {}\n"))
|
||||||
|
|
||||||
(define %nginx-accounts
|
(define %nginx-accounts
|
||||||
(list (user-group (name "nginx") (system? #t))
|
(list (user-group (name "nginx") (system? #t))
|
||||||
|
@ -151,7 +175,7 @@ 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
|
||||||
config-file)
|
upstream-blocks config-file)
|
||||||
#~(begin
|
#~(begin
|
||||||
(use-modules (guix build utils))
|
(use-modules (guix build utils))
|
||||||
|
|
||||||
|
@ -169,13 +193,13 @@ of index files."
|
||||||
(system* (string-append #$nginx "/sbin/nginx")
|
(system* (string-append #$nginx "/sbin/nginx")
|
||||||
"-c" #$(or config-file
|
"-c" #$(or config-file
|
||||||
(default-nginx-config log-directory
|
(default-nginx-config log-directory
|
||||||
run-directory server-blocks))
|
run-directory server-blocks upstream-blocks))
|
||||||
"-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
|
||||||
config-file)
|
upstream-blocks config-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
|
||||||
|
@ -184,7 +208,7 @@ of index files."
|
||||||
(system* #$nginx-binary "-c"
|
(system* #$nginx-binary "-c"
|
||||||
#$(or config-file
|
#$(or config-file
|
||||||
(default-nginx-config log-directory
|
(default-nginx-config log-directory
|
||||||
run-directory server-blocks))
|
run-directory server-blocks upstream-blocks))
|
||||||
#$@args))))))
|
#$@args))))))
|
||||||
|
|
||||||
;; TODO: Add 'reload' action.
|
;; TODO: Add 'reload' action.
|
||||||
|
@ -216,6 +240,7 @@ of index files."
|
||||||
(log-directory "/var/log/nginx")
|
(log-directory "/var/log/nginx")
|
||||||
(run-directory "/var/run/nginx")
|
(run-directory "/var/run/nginx")
|
||||||
(server-list '())
|
(server-list '())
|
||||||
|
(upstream-list '())
|
||||||
(config-file #f))
|
(config-file #f))
|
||||||
"Return a service that runs NGINX, the nginx web server.
|
"Return a service that runs NGINX, the nginx web server.
|
||||||
|
|
||||||
|
@ -227,4 +252,5 @@ files in LOG-DIRECTORY, and stores temporary runtime files in RUN-DIRECTORY."
|
||||||
(log-directory log-directory)
|
(log-directory log-directory)
|
||||||
(run-directory run-directory)
|
(run-directory run-directory)
|
||||||
(server-blocks server-list)
|
(server-blocks server-list)
|
||||||
|
(upstream-blocks upstream-list)
|
||||||
(file config-file))))
|
(file config-file))))
|
||||||
|
|
Loading…
Reference in New Issue