services: nginx: Make service extensible.
* gnu/services/web.scm (<nginx-configuration>)[server-blocks]: New field. (nginx-activation): When CONFIG-FILE is #f, use 'default-nginx-config'. (nginx-shepherd-service): Likewise. (nginx-service-type): Add 'compose' and 'extend' fields. (nginx-service): Change default value of #:server-list to '(), and default value of #:config-file to #f. * doc/guix.texi (Web Services): Document it. Co-authored-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
parent
4e9ae301ce
commit
d338237d8c
|
@ -11827,8 +11827,8 @@ The @code{(gnu services web)} module provides the following service:
|
||||||
@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
|
@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
|
||||||
[#:log-directory ``/var/log/nginx''] @
|
[#:log-directory ``/var/log/nginx''] @
|
||||||
[#:run-directory ``/var/run/nginx''] @
|
[#:run-directory ``/var/run/nginx''] @
|
||||||
[#:server-list (list (nginx-server-configuration))] @
|
[#:server-list '()] @
|
||||||
[#:config-file]
|
[#: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.
|
||||||
|
|
||||||
|
@ -11844,6 +11844,20 @@ this to work, use the default value for @var{config-file}.
|
||||||
|
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
@deffn {Scheme Variable} nginx-service-type
|
||||||
|
This is type for the nginx web server.
|
||||||
|
|
||||||
|
This service can be extended to add server blocks in addition to the
|
||||||
|
default one, as in this example:
|
||||||
|
|
||||||
|
@example
|
||||||
|
(simple-service 'my-extra-server nginx-service-type
|
||||||
|
(list (nginx-server-configuration
|
||||||
|
(https-port #f)
|
||||||
|
(root "/srv/http/extra-website"))))
|
||||||
|
@end example
|
||||||
|
@end deffn
|
||||||
|
|
||||||
@deftp {Data Type} nginx-server-configuration
|
@deftp {Data Type} nginx-server-configuration
|
||||||
Data type representing the configuration of an nginx server block.
|
Data type representing the configuration of an nginx server block.
|
||||||
This type has the following parameters:
|
This type has the following parameters:
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#:use-module (gnu packages web)
|
#:use-module (gnu packages web)
|
||||||
#:use-module (guix records)
|
#:use-module (guix records)
|
||||||
#:use-module (guix gexp)
|
#:use-module (guix gexp)
|
||||||
|
#:use-module (srfi srfi-1)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:export (nginx-configuration
|
#:export (nginx-configuration
|
||||||
nginx-configuration?
|
nginx-configuration?
|
||||||
|
@ -67,6 +68,7 @@
|
||||||
(nginx nginx-configuration-nginx) ;<package>
|
(nginx nginx-configuration-nginx) ;<package>
|
||||||
(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
|
||||||
(file nginx-configuration-file)) ;string | file-like
|
(file nginx-configuration-file)) ;string | file-like
|
||||||
|
|
||||||
(define (config-domain-strings names)
|
(define (config-domain-strings names)
|
||||||
|
@ -148,7 +150,8 @@ of index files."
|
||||||
|
|
||||||
(define nginx-activation
|
(define nginx-activation
|
||||||
(match-lambda
|
(match-lambda
|
||||||
(($ <nginx-configuration> nginx log-directory run-directory config-file)
|
(($ <nginx-configuration> nginx log-directory run-directory server-blocks
|
||||||
|
config-file)
|
||||||
#~(begin
|
#~(begin
|
||||||
(use-modules (guix build utils))
|
(use-modules (guix build utils))
|
||||||
|
|
||||||
|
@ -164,17 +167,25 @@ of index files."
|
||||||
(mkdir-p (string-append #$run-directory "/scgi_temp"))
|
(mkdir-p (string-append #$run-directory "/scgi_temp"))
|
||||||
;; Check configuration file syntax.
|
;; Check configuration file syntax.
|
||||||
(system* (string-append #$nginx "/sbin/nginx")
|
(system* (string-append #$nginx "/sbin/nginx")
|
||||||
"-c" #$config-file "-t")))))
|
"-c" #$(or config-file
|
||||||
|
(default-nginx-config log-directory
|
||||||
|
run-directory server-blocks))
|
||||||
|
"-t")))))
|
||||||
|
|
||||||
(define nginx-shepherd-service
|
(define nginx-shepherd-service
|
||||||
(match-lambda
|
(match-lambda
|
||||||
(($ <nginx-configuration> nginx log-directory run-directory config-file)
|
(($ <nginx-configuration> nginx log-directory run-directory server-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
|
||||||
#~(lambda _
|
#~(lambda _
|
||||||
(zero?
|
(zero?
|
||||||
(system* #$nginx-binary "-c" #$config-file #$@args))))))
|
(system* #$nginx-binary "-c"
|
||||||
|
#$(or config-file
|
||||||
|
(default-nginx-config log-directory
|
||||||
|
run-directory server-blocks))
|
||||||
|
#$@args))))))
|
||||||
|
|
||||||
;; TODO: Add 'reload' action.
|
;; TODO: Add 'reload' action.
|
||||||
(list (shepherd-service
|
(list (shepherd-service
|
||||||
|
@ -192,14 +203,20 @@ of index files."
|
||||||
(service-extension activation-service-type
|
(service-extension activation-service-type
|
||||||
nginx-activation)
|
nginx-activation)
|
||||||
(service-extension account-service-type
|
(service-extension account-service-type
|
||||||
(const %nginx-accounts))))))
|
(const %nginx-accounts))))
|
||||||
|
(compose concatenate)
|
||||||
|
(extend (lambda (config servers)
|
||||||
|
(nginx-configuration
|
||||||
|
(inherit config)
|
||||||
|
(server-blocks
|
||||||
|
(append (nginx-configuration-server-blocks config)
|
||||||
|
servers)))))))
|
||||||
|
|
||||||
(define* (nginx-service #:key (nginx nginx)
|
(define* (nginx-service #:key (nginx nginx)
|
||||||
(log-directory "/var/log/nginx")
|
(log-directory "/var/log/nginx")
|
||||||
(run-directory "/var/run/nginx")
|
(run-directory "/var/run/nginx")
|
||||||
(server-list (list (nginx-server-configuration)))
|
(server-list '())
|
||||||
(config-file
|
(config-file #f))
|
||||||
(default-nginx-config log-directory run-directory server-list)))
|
|
||||||
"Return a service that runs NGINX, the nginx web server.
|
"Return a service that runs NGINX, the nginx web server.
|
||||||
|
|
||||||
The nginx daemon loads its runtime configuration from CONFIG-FILE, stores log
|
The nginx daemon loads its runtime configuration from CONFIG-FILE, stores log
|
||||||
|
@ -209,4 +226,5 @@ files in LOG-DIRECTORY, and stores temporary runtime files in RUN-DIRECTORY."
|
||||||
(nginx nginx)
|
(nginx nginx)
|
||||||
(log-directory log-directory)
|
(log-directory log-directory)
|
||||||
(run-directory run-directory)
|
(run-directory run-directory)
|
||||||
|
(server-blocks server-list)
|
||||||
(file config-file))))
|
(file config-file))))
|
||||||
|
|
Loading…
Reference in New Issue