all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] gnu: services: Add redis-service
@ 2017-01-10  7:24 Christopher Baines
  2017-01-12 15:49 ` Ludovic Courtès
  2017-01-13 14:22 ` Thompson, David
  0 siblings, 2 replies; 8+ messages in thread
From: Christopher Baines @ 2017-01-10  7:24 UTC (permalink / raw)
  To: guix-devel

* gnu/services/database.scm (<redis-configuration>): New record type.
(%redis-accounts, redis-service-type): New variables.
(default-redis.conf, redis-activation, redis-shepherd-service): New
procedures.
* doc/guix.texi (Database Services): Document the new redis service.
---
 doc/guix.texi              | 24 ++++++++++++++
 gnu/services/databases.scm | 81 +++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 104 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index d46a7743d..4848254ad 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -10331,6 +10331,30 @@ TCP port on which the database server listens for incoming connections.
 @end table
 @end deftp
 
+@defvr {Scheme Variable} redis-service-type
+This is the type of the Redis service, whose value is a
+@code{redis-configuration} object.
+@end defvr
+
+@deftp {Data Type} redis-configuration
+Data type representing the configuration of redis.
+
+@table @asis
+@item @code{redis} (default: @code{redis})
+The Redis package to use.
+
+@item @code{bind} (default: @code{"127.0.0.1"})
+Network interface on which to listen.
+
+@item @code{port} (default: @code{6379})
+Port on which to accept connections on, a value of 0 will disable
+listining on a TCP socket.
+
+@item @code{working-directory} (default: @code{"/var/lib/redis"})
+Directory in which to store the database and related files.
+@end table
+@end deftp
+
 @node Mail Services
 @subsubsection Mail Services
 
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index d88c839f7..b6bdd6080 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -35,7 +35,11 @@
             mysql-service
             mysql-service-type
             mysql-configuration
-            mysql-configuration?))
+            mysql-configuration?
+
+            redis-configuration
+            redis-configuration?
+            redis-service-type))
 
 ;;; Commentary:
 ;;;
@@ -287,3 +291,78 @@ database server.
 The optional @var{config} argument specifies the configuration for
 @command{mysqld}, which should be a @code{<mysql-configuration>} object."
   (service mysql-service-type config))
+
+\f
+;;;
+;;; Redis
+;;;
+
+(define-record-type* <redis-configuration>
+  redis-configuration make-redis-configuration
+  redis-configuration?
+  (redis             redis-configuration-redis ;<package>
+                     (default redis))
+  (bind              redis-configuration-bind
+                     (default "127.0.0.1"))
+  (port              redis-configuration-port
+                     (default 6379))
+  (working-directory redis-configuration-working-directory
+                     (default "/var/lib/redis"))
+  (config-file       redis-configuration-config-file
+                     (default #f)))
+
+(define (default-redis.conf bind port working-directory)
+  (mixed-text-file "redis.conf"
+                   "bind " bind "\n"
+                   "port " (number->string port) "\n"
+                   "dir " working-directory "\n"
+                   "daemonize no\n"))
+
+(define %redis-accounts
+  (list (user-group (name "redis") (system? #t))
+        (user-account
+         (name "redis")
+         (group "redis")
+         (system? #t)
+         (comment "Redis server user")
+         (home-directory "/var/empty")
+         (shell (file-append shadow "/sbin/nologin")))))
+
+(define redis-activation
+  (match-lambda
+    (($ <redis-configuration> redis bind port working-directory config-file)
+     #~(begin
+         (use-modules (guix build utils)
+                      (ice-9 match))
+
+         (let ((user (getpwnam "redis")))
+           (mkdir-p #$working-directory)
+           (chown #$working-directory (passwd:uid user) (passwd:gid user)))))))
+
+(define redis-shepherd-service
+  (match-lambda
+    (($ <redis-configuration> redis bind port working-directory config-file)
+     (let
+         ((config-file
+           (or config-file
+               (default-redis.conf bind port working-directory))))
+       (list (shepherd-service
+              (provision '(redis))
+              (documentation "Run the Redis daemon.")
+              (requirement '(user-processes syslogd))
+              (start #~(make-forkexec-constructor
+                        `(,(string-append #$redis "/bin/redis-server")
+                          #$config-file)
+                        #:user "redis"
+                        #:group "redis"))
+              (stop #~(make-kill-destructor))))))))
+
+(define redis-service-type
+  (service-type (name 'redis)
+                (extensions
+                 (list (service-extension shepherd-root-service-type
+                                          redis-shepherd-service)
+                       (service-extension activation-service-type
+                                          redis-activation)
+                       (service-extension account-service-type
+                                          (const %redis-accounts))))))
-- 
2.11.0

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] gnu: services: Add redis-service
  2017-01-10  7:24 [PATCH] gnu: services: Add redis-service Christopher Baines
@ 2017-01-12 15:49 ` Ludovic Courtès
  2017-01-13 14:22 ` Thompson, David
  1 sibling, 0 replies; 8+ messages in thread
From: Ludovic Courtès @ 2017-01-12 15:49 UTC (permalink / raw)
  To: Christopher Baines; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 373 bytes --]

Hi,

Christopher Baines <mail@cbaines.net> skribis:

> * gnu/services/database.scm (<redis-configuration>): New record type.
> (%redis-accounts, redis-service-type): New variables.
> (default-redis.conf, redis-activation, redis-shepherd-service): New
> procedures.
> * doc/guix.texi (Database Services): Document the new redis service.

Nice!  Applied with these changes:


[-- Attachment #2: Type: text/x-patch, Size: 2031 bytes --]

diff --git a/doc/guix.texi b/doc/guix.texi
index de1ef2add..c495e39f4 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -10332,8 +10332,8 @@ TCP port on which the database server listens for incoming connections.
 @end deftp
 
 @defvr {Scheme Variable} redis-service-type
-This is the type of the Redis service, whose value is a
-@code{redis-configuration} object.
+This is the service type for the @uref{https://redis.io/, Redis}
+key/value store, whose value is a @code{redis-configuration} object.
 @end defvr
 
 @deftp {Data Type} redis-configuration
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index b6bdd6080..3ecc8aff7 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2015 David Thompson <davet@gnu.org>
 ;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2016 Leo Famulari <leo@famulari.name>
+;;; Copyright © 2017 Christopher Baines <mail@cbaines.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -342,16 +343,15 @@ The optional @var{config} argument specifies the configuration for
 (define redis-shepherd-service
   (match-lambda
     (($ <redis-configuration> redis bind port working-directory config-file)
-     (let
-         ((config-file
-           (or config-file
-               (default-redis.conf bind port working-directory))))
+     (let ((config-file
+            (or config-file
+                (default-redis.conf bind port working-directory))))
        (list (shepherd-service
               (provision '(redis))
               (documentation "Run the Redis daemon.")
               (requirement '(user-processes syslogd))
               (start #~(make-forkexec-constructor
-                        `(,(string-append #$redis "/bin/redis-server")
+                        '(#$(file-append redis "/bin/redis-server")
                           #$config-file)
                         #:user "redis"
                         #:group "redis"))

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]


Could you consider writing a system test for Redis?  See (gnu tests ssh)
and (gnu tests mail) for examples.

Thank you!

Ludo’.

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] gnu: services: Add redis-service
  2017-01-10  7:24 [PATCH] gnu: services: Add redis-service Christopher Baines
  2017-01-12 15:49 ` Ludovic Courtès
@ 2017-01-13 14:22 ` Thompson, David
  2017-01-13 14:42   ` David Craven
                     ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: Thompson, David @ 2017-01-13 14:22 UTC (permalink / raw)
  To: Christopher Baines; +Cc: guix-devel

Hello,

On Tue, Jan 10, 2017 at 2:24 AM, Christopher Baines <mail@cbaines.net> wrote:
>
> diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
> index d88c839f7..b6bdd6080 100644
> --- a/gnu/services/databases.scm
> +++ b/gnu/services/databases.scm
> @@ -35,7 +35,11 @@
>              mysql-service
>              mysql-service-type
>              mysql-configuration
> -            mysql-configuration?))
> +            mysql-configuration?
> +
> +            redis-configuration
> +            redis-configuration?
> +            redis-service-type))
>
>  ;;; Commentary:
>  ;;;
> @@ -287,3 +291,78 @@ database server.
>  The optional @var{config} argument specifies the configuration for
>  @command{mysqld}, which should be a @code{<mysql-configuration>} object."
>    (service mysql-service-type config))
> +
> +
> +;;;
> +;;; Redis
> +;;;
> +
> +(define-record-type* <redis-configuration>
> +  redis-configuration make-redis-configuration
> +  redis-configuration?
> +  (redis             redis-configuration-redis ;<package>
> +                     (default redis))
> +  (bind              redis-configuration-bind
> +                     (default "127.0.0.1"))
> +  (port              redis-configuration-port
> +                     (default 6379))
> +  (working-directory redis-configuration-working-directory
> +                     (default "/var/lib/redis"))
> +  (config-file       redis-configuration-config-file
> +                     (default #f)))

I'm seeing a trend where people write services with configuration
types that don't cover nearly the amount of configuration options to
make the service useful.  MySQL, and now this Redis server, are
examples of this.  There are many more configuration options in Redis
than this service exposes.

What do we do?

- Dave

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gnu: services: Add redis-service
  2017-01-13 14:22 ` Thompson, David
@ 2017-01-13 14:42   ` David Craven
  2017-01-13 14:56   ` John Darrington
  2017-01-13 22:01   ` Ricardo Wurmus
  2 siblings, 0 replies; 8+ messages in thread
From: David Craven @ 2017-01-13 14:42 UTC (permalink / raw)
  To: Thompson, David; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 259 bytes --]

Hi Dave,

Someone can always extend the configuration with more options, I don't
think that all options need to be exposed to make the service useful.

I don't think we should hold up patches that can easily be extended later
and don't break anything.

David

[-- Attachment #2: Type: text/html, Size: 432 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gnu: services: Add redis-service
  2017-01-13 14:22 ` Thompson, David
  2017-01-13 14:42   ` David Craven
@ 2017-01-13 14:56   ` John Darrington
  2017-01-13 22:01   ` Ricardo Wurmus
  2 siblings, 0 replies; 8+ messages in thread
From: John Darrington @ 2017-01-13 14:56 UTC (permalink / raw)
  To: Thompson, David; +Cc: guix-devel

[-- Attachment #1: Type: text/plain, Size: 1535 bytes --]

On Fri, Jan 13, 2017 at 09:22:01AM -0500, Thompson, David wrote:

     I'm seeing a trend where people write services with configuration
     types that don't cover nearly the amount of configuration options to
     make the service useful.  MySQL, and now this Redis server, are
     examples of this.  There are many more configuration options in Redis
     than this service exposes.


Probably what the author of the service does, it to provide just enough
configurations to make it useful to him/her.   

In the kerberos service I took the opposite approach, and provided the
full range of options that the underlying daemon has - the trouble is,
I have only a very vague idea of what many of those options do - so I
have no chance of writing a test which exercises them.

What is the worst evil - having a service with limited capabilities, or
having a service which is oestensibly fully featured, but we don't know
if all those features work or not?

I don't know the answer to that question.

     What do we do?
     
File a bug with an example of how it could usefully be extended?

Perhaps one thing we should do is - if we know that the service does
not expose a particular feature, then we should ensure that limitation
is explicitly noted in the manual.

J'

-- 
Avoid eavesdropping.  Send strong encrypted email.
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.


[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gnu: services: Add redis-service
  2017-01-13 14:22 ` Thompson, David
  2017-01-13 14:42   ` David Craven
  2017-01-13 14:56   ` John Darrington
@ 2017-01-13 22:01   ` Ricardo Wurmus
  2017-01-14 10:37     ` Hartmut Goebel
  2017-01-14 13:40     ` Ludovic Courtès
  2 siblings, 2 replies; 8+ messages in thread
From: Ricardo Wurmus @ 2017-01-13 22:01 UTC (permalink / raw)
  To: Thompson, David; +Cc: guix-devel


Thompson, David <dthompson2@worcester.edu> writes:

> I'm seeing a trend where people write services with configuration
> types that don't cover nearly the amount of configuration options to
> make the service useful.  MySQL, and now this Redis server, are
> examples of this.  There are many more configuration options in Redis
> than this service exposes.
>
> What do we do?

Since there is no automated way to cover all options (or even the most
useful subset) for all possible services I think it’s okay to start with
a minimally useful service definition.

We can extend them later as people see the need for better coverage.
One thing I’d always like to see, though, is an escape hatch that allows
users to extend the service with plain text configuration snippets.

-- 
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
http://elephly.net

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gnu: services: Add redis-service
  2017-01-13 22:01   ` Ricardo Wurmus
@ 2017-01-14 10:37     ` Hartmut Goebel
  2017-01-14 13:40     ` Ludovic Courtès
  1 sibling, 0 replies; 8+ messages in thread
From: Hartmut Goebel @ 2017-01-14 10:37 UTC (permalink / raw)
  To: guix-devel

[-- Attachment #1: Type: text/plain, Size: 445 bytes --]

Am 13.01.2017 um 23:01 schrieb Ricardo Wurmus:
> We can extend them later as people see the need for better coverage.
> One thing I’d always like to see, though, is an escape hatch that allows
> users to extend the service with plain text configuration snippets.

+1

-- 
Regards
Hartmut Goebel

| Hartmut Goebel          | h.goebel@crazy-compilers.com               |
| www.crazy-compilers.com | compilers which you thought are impossible |


[-- Attachment #2: 0xBF773B65.asc --]
[-- Type: application/pgp-keys, Size: 14855 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gnu: services: Add redis-service
  2017-01-13 22:01   ` Ricardo Wurmus
  2017-01-14 10:37     ` Hartmut Goebel
@ 2017-01-14 13:40     ` Ludovic Courtès
  1 sibling, 0 replies; 8+ messages in thread
From: Ludovic Courtès @ 2017-01-14 13:40 UTC (permalink / raw)
  To: Ricardo Wurmus; +Cc: guix-devel

Ricardo Wurmus <rekado@elephly.net> skribis:

> Thompson, David <dthompson2@worcester.edu> writes:
>
>> I'm seeing a trend where people write services with configuration
>> types that don't cover nearly the amount of configuration options to
>> make the service useful.  MySQL, and now this Redis server, are
>> examples of this.  There are many more configuration options in Redis
>> than this service exposes.
>>
>> What do we do?
>
> Since there is no automated way to cover all options (or even the most
> useful subset) for all possible services I think it’s okay to start with
> a minimally useful service definition.
>
> We can extend them later as people see the need for better coverage.
> One thing I’d always like to see, though, is an escape hatch that allows
> users to extend the service with plain text configuration snippets.

Agreed.  I like it when people submit full-featured services, like the
OpenVPN services that were posted recently, but I think it’s also
valuable to have first stabs at services like this Redis server.  It
is functional and useful, lowers the barrier for the initial submitter
as well as for people who want to improve it.

Ludo’.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-01-14 13:40 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-10  7:24 [PATCH] gnu: services: Add redis-service Christopher Baines
2017-01-12 15:49 ` Ludovic Courtès
2017-01-13 14:22 ` Thompson, David
2017-01-13 14:42   ` David Craven
2017-01-13 14:56   ` John Darrington
2017-01-13 22:01   ` Ricardo Wurmus
2017-01-14 10:37     ` Hartmut Goebel
2017-01-14 13:40     ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.