Re: [PATCH] gnu: services: Add nginx-service.

2015-08-25 Thread Ludovic Courtès
Thompson, David dthomps...@worcester.edu skribis:

 On Tue, Aug 18, 2015 at 11:58 AM, Ludovic Courtès l...@gnu.org wrote:
 Thompson, David dthomps...@worcester.edu skribis:

 From c2da6c04eb1a12d0ee2f56a3954673f3bddc122b Mon Sep 17 00:00:00 2001
 From: David Thompson dthomps...@worcester.edu
 Date: Sun, 2 Aug 2015 23:29:53 -0400
 Subject: [PATCH] gnu: services: Add nginx-service.

 * gnu/services/web.scm: New file.
 * gnu-system.am (GNU_SYSTEM_MODULES): Add it.

 [...]

 +(define (default-nginx-config log-directory run-directory)
 +  (text-file* nginx.conf
 +  user nginx nginx;\n
 +  pid  run-directory /pid;\n
 +  error_log  log-directory /error.log info;\n
 +  http {\n
 +  access_log  log-directory /access.log;\n
 +  root /var/www;\n
 +  server {}\n
 +  }\n
 +  events {}\n))
 +
 +(define* (nginx-service #:key (nginx nginx)
 +(log-directory /var/log/nginx)
 +(run-directory /var/run/nginx)
 +(config-file
 + (default-nginx-config log-directory 
 run-directory)))

 There’s this annoying thing that here ‘config-file’ is a monadic value
 when we’d instead prefer a “file-like object.”

But it just occurred to me that you could write:

  (define (default-nginx-config log-directory run-directory)
(plain-file nginx.conf
(string-append ...)))

Problem solved!

(‘text-file*’ is more advanced: Instead of returning a file in the
store, it returns a *derivation* that builds a file possibly containing
references to store items.  But here, the default config file does not
refer to any store item, so ‘plain-file’ is enough.)

WDYT?

Thanks,
Ludo’.



Re: [PATCH] gnu: services: Add nginx-service.

2015-08-18 Thread Thompson, David
On Tue, Aug 18, 2015 at 11:58 AM, Ludovic Courtès l...@gnu.org wrote:
 Thompson, David dthomps...@worcester.edu skribis:

 From c2da6c04eb1a12d0ee2f56a3954673f3bddc122b Mon Sep 17 00:00:00 2001
 From: David Thompson dthomps...@worcester.edu
 Date: Sun, 2 Aug 2015 23:29:53 -0400
 Subject: [PATCH] gnu: services: Add nginx-service.

 * gnu/services/web.scm: New file.
 * gnu-system.am (GNU_SYSTEM_MODULES): Add it.

 [...]

 +(define (default-nginx-config log-directory run-directory)
 +  (text-file* nginx.conf
 +  user nginx nginx;\n
 +  pid  run-directory /pid;\n
 +  error_log  log-directory /error.log info;\n
 +  http {\n
 +  access_log  log-directory /access.log;\n
 +  root /var/www;\n
 +  server {}\n
 +  }\n
 +  events {}\n))
 +
 +(define* (nginx-service #:key (nginx nginx)
 +(log-directory /var/log/nginx)
 +(run-directory /var/run/nginx)
 +(config-file
 + (default-nginx-config log-directory 
 run-directory)))

 There’s this annoying thing that here ‘config-file’ is a monadic value
 when we’d instead prefer a “file-like object.”

 To work around it you could use ‘plain-file’ and make the default config
 file independent of the parameters.  The obvious issue is that if the
 user specifies LOG-DIRECTORY or RUN-DIRECTORY different from the
 default, yet use the default config files, things will break.  But maybe
 that’s an acceptable drawback?

Yeah, I'm not sure which way to go here, and I feel like this will be
an issue in many services to come.  Services often have to know some
details about the configuration to create directories and files that
the daemon won't just create on its own.  For context, I chose the
current implementation because Mark told me that he didn't like the
idea of the default configuration file being independent of the
#:log-directory and #:run-directory arguments, and I agreed it was not
good.

 Lastly, could you add a “Web Services” section under “Services” in the
 manual?

Yes, I can do that.

- Dave



Re: [PATCH] gnu: services: Add nginx-service.

2015-08-18 Thread Ludovic Courtès
Thompson, David dthomps...@worcester.edu skribis:

 From c2da6c04eb1a12d0ee2f56a3954673f3bddc122b Mon Sep 17 00:00:00 2001
 From: David Thompson dthomps...@worcester.edu
 Date: Sun, 2 Aug 2015 23:29:53 -0400
 Subject: [PATCH] gnu: services: Add nginx-service.

 * gnu/services/web.scm: New file.
 * gnu-system.am (GNU_SYSTEM_MODULES): Add it.

[...]

 +(define (default-nginx-config log-directory run-directory)
 +  (text-file* nginx.conf
 +  user nginx nginx;\n
 +  pid  run-directory /pid;\n
 +  error_log  log-directory /error.log info;\n
 +  http {\n
 +  access_log  log-directory /access.log;\n
 +  root /var/www;\n
 +  server {}\n
 +  }\n
 +  events {}\n))
 +
 +(define* (nginx-service #:key (nginx nginx)
 +(log-directory /var/log/nginx)
 +(run-directory /var/run/nginx)
 +(config-file
 + (default-nginx-config log-directory run-directory)))

There’s this annoying thing that here ‘config-file’ is a monadic value
when we’d instead prefer a “file-like object.”

To work around it you could use ‘plain-file’ and make the default config
file independent of the parameters.  The obvious issue is that if the
user specifies LOG-DIRECTORY or RUN-DIRECTORY different from the
default, yet use the default config files, things will break.  But maybe
that’s an acceptable drawback?

Lastly, could you add a “Web Services” section under “Services” in the
manual?

Thanks!

Ludo’.