From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christopher Baines Subject: [PATCH] gnu: services: Add redis-service Date: Tue, 10 Jan 2017 07:24:01 +0000 Message-ID: <20170110072401.6756-1-mail@cbaines.net> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35839) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cQqmt-0002QV-Ik for guix-devel@gnu.org; Tue, 10 Jan 2017 02:24:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cQqmq-0006PJ-D1 for guix-devel@gnu.org; Tue, 10 Jan 2017 02:24:07 -0500 Received: from mira.cbaines.net ([2a01:7e00::f03c:91ff:fe69:8da9]:43751) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cQqmq-0006PD-4b for guix-devel@gnu.org; Tue, 10 Jan 2017 02:24:04 -0500 Received: from localhost (88-104-172-223.dynamic.dsl.as9105.com [88.104.172.223]) by mira.cbaines.net (Postfix) with ESMTPSA id 6EF8D13E3AF for ; Tue, 10 Jan 2017 07:24:02 +0000 (GMT) Received: from lesath.dlink.com (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id e0ac3a87 for ; Tue, 10 Jan 2017 07:24:02 +0000 (UTC) List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: guix-devel@gnu.org * gnu/services/database.scm (): 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{} object." (service mysql-service-type config)) + + +;;; +;;; Redis +;;; + +(define-record-type* + redis-configuration make-redis-configuration + redis-configuration? + (redis redis-configuration-redis ; + (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 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 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