[PATCH] NGinx service changes (add default value, and remove nginx-service procedure)

  • Done
  • quality assurance status badge
Details
2 participants
  • Ludovic Courtès
  • Christopher Baines
Owner
unassigned
Submitted by
Christopher Baines
Severity
normal

Debbugs page

Christopher Baines wrote 8 years ago
(address . guix-patches@gnu.org)
20170817185055.35b48476@cbaines.net
Christopher Baines (3):
web: Export more nginx related procedures, macros and record types
web: Add default-value for the nginx-service-type
web: Remove the nginx-service procedure.

doc/guix.texi | 149 +++++++++++++++++++++++++++++++++++++++------------
gnu/services/web.scm | 56 +++++++++++--------
2 files changed, 150 insertions(+), 55 deletions(-)
-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmV139fFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE
9XcrJQ/+PnZSUMp2/WDAkP4Hwn3XXQqzVIJ9y0j/v1Phi0lEQ38UewrFESLf40D9
Uj0SKpfmS0vSAeyYtAK1UbKNKJM9gmTR90i9vRcBtGBxKcTSzyn9p5AI42LKAiLd
xBrvXMxUQdJgfGdrVi603eGxwLbVGDwmPjB0xmfNWl26VxjVAFGVgfbXetJwn8Od
v4j2zCTiMcbxI8QhnC8Ilepix2xrSZt6I5iFieiXrr7/a7pd8LkIxIafWEpnY2rQ
Kb6dEPx1kNDIaFO8p3eByDymg0M+umxyCqnWorozfPRNSGp7lQaINfVZx8ZaoCjb
ig4KU8FPmVO1rT+QWhFUsNLEbyEhbGnWGwSdnFXnD8DsKKH7P7m3ZnNEdKxZ32Vx
xFVrh2iELm1olLynQuZ+Svg66z3GHYfQRQSPkVW38yj16iERzZcxZLX/8OaAll3u
YO4j/YwmQ3DjqHQy32KsTHPaCQ8fBD6n3vfWOf/0DQUxD9yU9B97J4rDWSn1vPGJ
RDcMmCtNVXLfkD9L2Z0f58ONZ7Lvy1UWv3f17o11b8DN22ACFVz7k+NWy5EHTyPB
8aaOzhG8hiippkTmr1ELv6byvqPWUj1NjIdHUZ2cdssdhWl2CKH9aWqWYqTL4a3A
gkMLW/Sj/pijN3mhCpBfDKMfGGAiIvj+GeI5bGSRvb1koODA0gg=
=ufcg
-----END PGP SIGNATURE-----


Christopher Baines wrote 8 years ago
[PATCH 1/3] web: Export more nginx related procedures, macros and record types
(address . 28125@debbugs.gnu.org)
20170817180109.14785-1-mail@cbaines.net
This makes it possible to work with the configuration of the NGinx service
programatically.

* gnu/services/web.scm (<nginx-configuration>, <nginx-server-configuration>,
<nginx-upstream-configuration>, <nginx-location-configuration>,
<nginx-named-location-configuration>): Export NGinx related record
types.
(nginx-configuration-*, nginx-server-configuration-*,
nginx-upstream-configuration-*, nginx-location-configuration-*,
nginx-named-location-configuration-*): Export NGinx related record
procedures.
(nginx-configuration): Export NGinx related record macro.
---
gnu/services/web.scm | 33 ++++++++++++++++++++++++++++++++-
1 file changed, 32 insertions(+), 1 deletion(-)

Toggle diff (55 lines)
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index cc7adeb5e..4156b1a56 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -30,16 +30,47 @@
#:use-module (guix gexp)
#:use-module (srfi srfi-1)
#:use-module (ice-9 match)
- #:export (nginx-configuration
+ #:export (<nginx-configuration>
+ nginx-configuration
nginx-configuration?
+ nginx-configuartion-nginx
+ nginx-configuration-log-directory
+ nginx-configuration-run-directory
+ nginx-configuration-server-blocks
+ nginx-configuration-upstream-blocks
+ nginx-configuration-file
+
+ <nginx-server-configuration>
nginx-server-configuration
nginx-server-configuration?
+ nginx-server-configuration-http-port
+ nginx-server-configuartion-https-port
+ nginx-server-configuration-server-name
+ nginx-server-configuration-root
+ nginx-server-configuration-locations
+ nginx-server-configuration-index
+ nginx-server-configuration-ssl-certificate
+ nginx-server-configuration-ssl-certificate-key
+ nginx-server-configuration-server-tokens?
+
+ <nginx-upstream-configuration>
nginx-upstream-configuration
nginx-upstream-configuration?
+ nginx-upstream-configuration-name
+ nginx-upstream-configuration-servers
+
+ <nginx-location-configuration>
nginx-location-configuration
nginx-location-configuration?
+ nginx-location-configuration-uri
+ nginx-location-configuration-body
+
+ <nginx-named-location-configuration>
nginx-named-location-configuration
nginx-named-location-configuration?
+ nginx-named-location-configuration-name
+ nginx-named-location-configuration-body
+
nginx-service
nginx-service-type
--
2.14.1
Christopher Baines wrote 8 years ago
[PATCH 2/3] web: Add default-value for the nginx-service-type
(address . 28125@debbugs.gnu.org)
20170817180109.14785-2-mail@cbaines.net
---
gnu/services/web.scm | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

Toggle diff (17 lines)
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index 4156b1a56..aefae5aed 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -324,7 +324,9 @@ of index files."
(inherit config)
(server-blocks
(append (nginx-configuration-server-blocks config)
- servers)))))))
+ servers)))))
+ (default-value
+ (nginx-configuration))))
(define* (nginx-service #:key (nginx nginx)
(log-directory "/var/log/nginx")
--
2.14.1
Christopher Baines wrote 8 years ago
[PATCH 3/3] web: Remove the nginx-service procedure.
(address . 28125@debbugs.gnu.org)
20170817180109.14785-3-mail@cbaines.net
Now that the service-type has a default value, and configuration record is
accessible.

* gnu/services/web.scm (nginx-service): Remove procedure.
* doc/guix.texi (Web Services): Update and improve NGinx documentation.
---
doc/guix.texi | 149 +++++++++++++++++++++++++++++++++++++++------------
gnu/services/web.scm | 19 -------
2 files changed, 115 insertions(+), 53 deletions(-)

Toggle diff (204 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 94277ba39..35fff0e1e 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -13933,52 +13933,133 @@ Local accounts with lower values will silently fail to authenticate.
The @code{(gnu services web)} module provides the nginx web server and
also a fastcgi wrapper daemon.
-@deffn {Scheme Procedure} nginx-service [#:nginx nginx] @
- [#:log-directory ``/var/log/nginx''] @
- [#:run-directory ``/var/run/nginx''] @
- [#:server-list '()] @
- [#:upstream-list '()] @
- [#:config-file @code{#f}]
-
-Return a service that runs @var{nginx}, the nginx web server.
-
-The nginx daemon loads its runtime configuration from @var{config-file}.
-Log files are written to @var{log-directory} and temporary runtime data
-files are written to @var{run-directory}. For proper operation, these
-arguments should match what is in @var{config-file} to ensure that the
-directories are created when the service is activated.
-
-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 and
-@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}.
-
-At startup, @command{nginx} has not yet read its configuration file, so it
-uses a default file to log error messages. If it fails to load its
-configuration file, that is where error messages are logged. After the
-configuration file is loaded, the default error log file changes as per
-configuration. In our case, startup error messages can be found in
-@file{/var/run/nginx/logs/error.log}, and after configuration in
-@file{/var/log/nginx/error.log}. The second location can be changed with the
-@var{log-directory} configuration option.
+@deffn {Scheme Variable} nginx-service-type
+Service type for the @uref{https://nginx.org/,NGinx} web server. The
+value for this service type is a @code{<nginx-configuration>} record.
-@end deffn
+A simple example configuration is given below.
-@deffn {Scheme Variable} nginx-service-type
-This is type for the nginx web server.
+@example
+(service nginx-service-type
+ (nginx-configuration
+ (server-list
+ (list (nginx-server-configuration
+ (server-name '("www.example.com"))
+ (root "/srv/http/www.example.com")
+ (https-port #f)
+ (ssl-certificate #f)
+ (ssl-certificate-key #f))))))
+@end example
-This service can be extended to add server blocks in addition to the
-default one, as in this example:
+In addition to adding server blocks to the service configuration
+directly, this service can be extended by other services to add server
+blocks, as in this example:
@example
(simple-service 'my-extra-server nginx-service-type
(list (nginx-server-configuration
(https-port #f)
+ (ssl-certificate #f)
+ (ssl-certificate-key #f)
(root "/srv/http/extra-website"))))
@end example
@end deffn
+At startup, @command{nginx} has not yet read its configuration file, so
+it uses a default file to log error messages. If it fails to load its
+configuration file, that is where error messages are logged. After the
+configuration file is loaded, the default error log file changes as per
+configuration. In our case, startup error messages can be found in
+@file{/var/run/nginx/logs/error.log}, and after configuration in
+@file{/var/log/nginx/error.log}. The second location can be changed
+with the @var{log-directory} configuration option.
+
+@deffn {Data Type} nginx-configuration
+This data type represents the configuration for NGinx. Some
+configuration can be done through this and the other provided record
+types, or alternatively, a config file can be provided.
+
+@table @asis
+@item @code{nginx} (default: @code{nginx})
+The nginx package to use.
+
+@item @code{log-directory} (default: @code{"/var/log/nginx"})
+The directory to which NGinx will write log files.
+
+@item @code{run-directory} (default: @code{"/var/run/nginx"})
+The directory in which NGinx will create a pid file, and write temporary
+files.
+
+@item @code{server-list} (default: @code{'()})
+A list of @dfn{server blocks} to create in the generated configuration
+file, the elements should be of type
+@code{<nginx-server-configuration>}.
+
+The following example would setup NGinx to serve @code{www.example.com}
+from the @code{/srv/http/www.example.com} directory, without using
+HTTPS.
+@example
+(service nginx-service-type
+ (nginx-configuration
+ (server-list
+ (list (nginx-server-configuration
+ (server-name '("www.example.com"))
+ (root "/srv/http/www.example.com")
+ (https-port #f)
+ (ssl-certificate #f)
+ (ssl-certificate-key #f))))))
+@end example
+
+@item @code{upstream-list} (default: @code{'()})
+A list of @dfn{upstream blocks} to create in the generated configuration
+file, the elements should be of type
+@code{<nginx-upstream-configuration>}.
+
+Configuring upstreams through the @code{upstream-list} can be useful
+when combined with @code{locations} in the
+@code{<nginx-server-configuration>} records. The following example
+creates a server configuration with one location configuration, that
+will proxy requests to a upstream configuration, which will handle
+requests with two servers.
+
+@example
+(service
+ nginx-service-type
+ (nginx-configuration
+ (server-list
+ (list (nginx-server-configuration
+ (server-name '("www.example.com"))
+ (root "/srv/http/www.example.com")
+ (https-port #f)
+ (ssl-certificate #f)
+ (ssl-certificate-key #f)
+ (locations
+ (list
+ (nginx-location-configuration
+ (uri "/path1")
+ (body '("proxy_pass http://server-proxy;"))))))))
+ (upstream-list
+ (list (nginx-upstream-configuration
+ (name "server-proxy")
+ (servers (list "server1.example.com"
+ "server2.example.com")))))))
+@end example
+
+@item @code{config-file} (default: @code{#f})
+If the @var{config-file} is provided, this will be used, rather than
+generating a configuration file from the provided @code{log-directory},
+@code{run-directory}, @code{server-list} and @code{upstream-list}. For
+proper operation, these arguments should match what is in
+@var{config-file} to ensure that the directories are created when the
+service is activated.
+
+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
+nginx-configuration record.
+
+@end table
+@end deffn
+
@deftp {Data Type} nginx-server-configuration
Data type representing the configuration of an nginx server block.
This type has the following parameters:
diff --git a/gnu/services/web.scm b/gnu/services/web.scm
index aefae5aed..18278502e 100644
--- a/gnu/services/web.scm
+++ b/gnu/services/web.scm
@@ -328,25 +328,6 @@ of index files."
(default-value
(nginx-configuration))))
-(define* (nginx-service #:key (nginx nginx)
- (log-directory "/var/log/nginx")
- (run-directory "/var/run/nginx")
- (server-list '())
- (upstream-list '())
- (config-file #f))
- "Return a service that runs NGINX, the nginx web server.
-
-The nginx daemon loads its runtime configuration from CONFIG-FILE, stores log
-files in LOG-DIRECTORY, and stores temporary runtime files in RUN-DIRECTORY."
- (service nginx-service-type
- (nginx-configuration
- (nginx nginx)
- (log-directory log-directory)
- (run-directory run-directory)
- (server-blocks server-list)
- (upstream-blocks upstream-list)
- (file config-file))))
-
(define-record-type* <fcgiwrap-configuration> fcgiwrap-configuration
make-fcgiwrap-configuration
fcgiwrap-configuration?
--
2.14.1
Ludovic Courtès wrote 8 years ago
Re: [bug#28125] [PATCH 1/3] web: Export more nginx related procedures, macros and record types
(name . Christopher Baines)(address . mail@cbaines.net)(address . 28125@debbugs.gnu.org)
87mv6r69f7.fsf@gnu.org
Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (13 lines)
> This makes it possible to work with the configuration of the NGinx service
> programatically.
>
> * gnu/services/web.scm (<nginx-configuration>, <nginx-server-configuration>,
> <nginx-upstream-configuration>, <nginx-location-configuration>,
> <nginx-named-location-configuration>): Export NGinx related record
> types.
> (nginx-configuration-*, nginx-server-configuration-*,
> nginx-upstream-configuration-*, nginx-location-configuration-*,
> nginx-named-location-configuration-*): Export NGinx related record
> procedures.
> (nginx-configuration): Export NGinx related record macro.

LGTM!
Ludovic Courtès wrote 8 years ago
Re: [bug#28125] [PATCH 2/3] web: Add default-value for the nginx-service-type
(name . Christopher Baines)(address . mail@cbaines.net)(address . 28125@debbugs.gnu.org)
87inhf69et.fsf@gnu.org
Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (17 lines)
> ---
> gnu/services/web.scm | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/gnu/services/web.scm b/gnu/services/web.scm
> index 4156b1a56..aefae5aed 100644
> --- a/gnu/services/web.scm
> +++ b/gnu/services/web.scm
> @@ -324,7 +324,9 @@ of index files."
> (inherit config)
> (server-blocks
> (append (nginx-configuration-server-blocks config)
> - servers)))))))
> + servers)))))
> + (default-value
> + (nginx-configuration))))

OK with a commit log. :-)
Ludovic Courtès wrote 8 years ago
Re: [bug#28125] [PATCH 3/3] web: Remove the nginx-service procedure.
(name . Christopher Baines)(address . mail@cbaines.net)(address . 28125@debbugs.gnu.org)
87efs369do.fsf@gnu.org
Christopher Baines <mail@cbaines.net> skribis:

Toggle quote (6 lines)
> Now that the service-type has a default value, and configuration record is
> accessible.
>
> * gnu/services/web.scm (nginx-service): Remove procedure.
> * doc/guix.texi (Web Services): Update and improve NGinx documentation.

LGTM, thank you!

Ludo’.
Christopher Baines wrote 8 years ago
(name . Ludovic Courtès)(address . ludo@gnu.org)(address . 28125-done@debbugs.gnu.org)
20170822180401.7df1cfb6@cbaines.net
On Tue, 22 Aug 2017 15:05:07 +0200
ludo@gnu.org (Ludovic Courtès) wrote:

Toggle quote (13 lines)
> Christopher Baines <mail@cbaines.net> skribis:
>
> > Now that the service-type has a default value, and configuration
> > record is accessible.
> >
> > * gnu/services/web.scm (nginx-service): Remove procedure.
> > * doc/guix.texi (Web Services): Update and improve NGinx
> > documentation.
>
> LGTM, thank you!
>
> Ludo’.

Thanks for your review Ludo, I've now pushed these 3 patches :)
-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEPonu50WOcg2XVOCyXiijOwuE9XcFAlmcZAFfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF
ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcACgkQXiijOwuE
9Xe7Hg//eP9SIxHM1AZAMFt48n7TsX+nstlu3o1vAGd3LHTfVr0EsyXo6GLz9a+b
y6Xz6SlkE1hDQBhETT5MLz6n0WC2oQ5ztXSYR0gDb7Rc9xCeiw3NbOAqp0ag6S04
CihiHgtUz9CJZ2qQwtK/fz+e3dL9AU4aRciWcTJK9QVFcNL7TW1M7BXydlWh+4bu
GTb6vfoRfYyP9LK7t7AvTGtD9ZwW101uRLBQEINVz+5tZeXtbMlpj5zz3ZDDFYpm
vtL33RC8Uk6d+73YnE9u3IQHLTeUE7ehnQdq/w7mbHCtTP/qcxqfHDx123Q4HrDW
kzjxwjzSwwJNXYHoIeRjvasM8Iv8/iYSO6co6S1wENiTLoBnSreMnouzM+9/bJ0B
12qNRbQKS7ApcnUhm9KSulWYw6jaXM1Yda9WnqgZ6PltPHxGYCWkw5KEwoq5UAi3
We39rwsu1acxOulNXb0SsxWnzlPoF0gDf1WgHuo+xE7uPeO8g2AjYwtEDL6pY9tL
b5g2BYy3m/FHgOrFrs+0vapOSUJ3cvYm5ra0R7/v/FeO3SufDHEDftWq8cqccEka
EfVfw4zf9cL0BB5ymjlnz+E6qWPbGjQeLJCM+saEXXBaDH2TYWjvmT1aEwmPcRdL
Sy84lcWV/IzlM9uKKwYpNG9YfQDcmwdmZj5dxsnEKH11UP/o/ro=
=MpDm
-----END PGP SIGNATURE-----


Closed
?
Your comment

This issue is archived.

To comment on this conversation send an email to 28125@debbugs.gnu.org

To respond to this issue using the mumi CLI, first switch to it
mumi current 28125
Then, you may apply the latest patchset in this issue (with sign off)
mumi am -- -s
Or, compose a reply to this issue
mumi compose
Or, send patches to this issue
mumi send-email *.patch
You may also tag this issue. See list of standard tags. For example, to set the confirmed and easy tags
mumi command -t +confirmed -t +easy
Or, remove the moreinfo tag and set the help tag
mumi command -t -moreinfo -t +help