[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
04/04: services: Add 'redis-service-type'.
From: |
Ludovic Courtès |
Subject: |
04/04: services: Add 'redis-service-type'. |
Date: |
Thu, 12 Jan 2017 15:50:06 +0000 (UTC) |
civodul pushed a commit to branch master
in repository guix.
commit 67cadaca4746f847fbbea5ef69f6cc65d1eb3acc
Author: Christopher Baines <address@hidden>
Date: Tue Jan 10 07:24:01 2017 +0000
services: Add 'redis-service-type'.
* 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.
Signed-off-by: Ludovic Courtès <address@hidden>
---
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 0868959..c495e39 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
address@hidden {Scheme Variable} redis-service-type
+This is the service type for the @uref{https://redis.io/, Redis}
+key/value store, whose value is a @code{redis-configuration} object.
address@hidden defvr
+
address@hidden {Data Type} redis-configuration
+Data type representing the configuration of redis.
+
address@hidden @asis
address@hidden @code{redis} (default: @code{redis})
+The Redis package to use.
+
address@hidden @code{bind} (default: @code{"127.0.0.1"})
+Network interface on which to listen.
+
address@hidden @code{port} (default: @code{6379})
+Port on which to accept connections on, a value of 0 will disable
+listining on a TCP socket.
+
address@hidden @code{working-directory} (default: @code{"/var/lib/redis"})
+Directory in which to store the database and related files.
address@hidden table
address@hidden deftp
+
@node Mail Services
@subsubsection Mail Services
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index d88c839..3ecc8af 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -2,6 +2,7 @@
;;; Copyright © 2015 David Thompson <address@hidden>
;;; Copyright © 2015, 2016 Ludovic Courtès <address@hidden>
;;; Copyright © 2016 Leo Famulari <address@hidden>
+;;; Copyright © 2017 Christopher Baines <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -35,7 +36,11 @@
mysql-service
mysql-service-type
mysql-configuration
- mysql-configuration?))
+ mysql-configuration?
+
+ redis-configuration
+ redis-configuration?
+ redis-service-type))
;;; Commentary:
;;;
@@ -287,3 +292,77 @@ 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)))
+
+(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
+ '(#$(file-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))))))