summaryrefslogtreecommitdiff
path: root/gnu/services
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/services')
-rw-r--r--gnu/services/databases.scm119
-rw-r--r--gnu/services/message-broker.scm114
2 files changed, 229 insertions, 4 deletions
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index aff78a0566..ab63019f77 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -51,6 +51,18 @@
postgresql-service
postgresql-service-type
+ <elasticsearch-configuration>
+ elasticsearch-configuration
+ elasticsearch-configuration?
+ elasticsearch-configuration-elasticsearch
+ elasticsearch-configuration-data-path
+ elasticsearch-configuration-logs-path
+ elasticsearch-configuration-port
+ elasticsearch-configuration-transport-port
+
+ elasticsearch-service
+ elasticsearch-service-type
+
memcached-service-type
<memcached-configuration>
memcached-configuration
@@ -268,6 +280,101 @@ and stores the database cluster in @var{data-directory}."
;;;
+;;; Elasticsearch
+;;;
+
+(define-record-type* <elasticsearch-configuration>
+ elasticsearch-configuration make-elasticsearch-configuration
+ elasticsearch-configuration?
+ (elasticsearch elasticsearch-configuration-elasticsearch
+ (default elasticsearch))
+ (data-path elasticsearch-configuration-data-path
+ (default "/var/lib/"))
+ (logs-path elasticsearch-configuration-logs-path
+ (default "/var/log/elasticsearch"))
+ (http-port elasticsearch-configuration-port
+ (default 9200))
+ (transport-port elasticsearch-configuration-transport-port
+ (default 9300)))
+
+(define (elasticsearch-configuration-directory
+ data-path logs-path http-port transport-port)
+ (computed-file
+ "elasticsearch-config"
+ #~(begin
+ (mkdir #$output)
+ (mkdir (string-append #$output "/scripts"))
+ (call-with-output-file (string-append #$output "/elasticsearch.yml")
+ (lambda (port)
+ (display
+ (string-append
+ "path.data: " #$data-path "\n"
+ "path.logs: " #$logs-path "\n"
+ "http.port: " #$(number->string http-port) "\n"
+ "transport.tcp.port: " #$(number->string transport-port) "\n")
+ port))))))
+
+(define %elasticsearch-accounts
+ (list (user-group (name "elasticsearch") (system? #t))
+ (user-account
+ (name "elasticsearch")
+ (group "elasticsearch")
+ (system? #t)
+ (comment "Elasticsearch server user")
+ (home-directory "/var/empty")
+ (shell (file-append shadow "/sbin/nologin")))))
+
+(define elasticsearch-activation
+ (match-lambda
+ (($ <elasticsearch-configuration> elasticsearch data-path logs-path
+ http-port transport-port)
+ #~(begin
+ (use-modules (guix build utils)
+ (ice-9 match))
+
+ (let ((user (getpwnam "elasticsearch")))
+ ;; Create db state directory.
+ (for-each
+ (lambda (path)
+ (mkdir-p path)
+ (chown path (passwd:uid user) (passwd:gid user)))
+ '(#$data-path #$logs-path "/var/run/elasticsearch")))))))
+
+(define elasticsearch-shepherd-service
+ (match-lambda
+ (($ <elasticsearch-configuration> elasticsearch data-path logs-path
+ http-port transport-port)
+ (list (shepherd-service
+ (provision '(elasticsearch))
+ (documentation "Run the Elasticsearch daemon.")
+ (requirement '(user-processes syslogd))
+ (start #~(make-forkexec-constructor
+ (list
+ (string-append #$elasticsearch "/bin/elasticsearch")
+ "-d"
+ "-p" "/var/run/elasticsearch/pid"
+ (string-append
+ "-Dpath.conf="
+ #$(elasticsearch-configuration-directory
+ data-path logs-path http-port transport-port)))
+ #:user "elasticsearch"
+ #:pid-file "/var/run/elasticsearch/pid"
+ #:log-file "/var/log/elasticsearch.log"))
+ (stop #~(make-kill-destructor)))))))
+
+(define elasticsearch-service-type
+ (service-type (name 'elasticsearch)
+ (extensions
+ (list (service-extension shepherd-root-service-type
+ elasticsearch-shepherd-service)
+ (service-extension activation-service-type
+ elasticsearch-activation)
+ (service-extension account-service-type
+ (const %elasticsearch-accounts))))
+ (default-value (elasticsearch-configuration))))
+
+
+;;;
;;; Memcached
;;;
@@ -449,8 +556,9 @@ storage:
(($ <mysql-configuration> mysql port)
(mixed-text-file "my.cnf" "[mysqld]
datadir=/var/lib/mysql
-socket=/run/mysqld/mysqld.sock
+socket=/var/run/mysql/mysqld.sock
port=" (number->string port) "
+max_allowed_packet=16M
"))))
(define (%mysql-activation config)
@@ -465,7 +573,7 @@ port=" (number->string port) "
(uid (passwd:uid user))
(gid (passwd:gid user))
(datadir "/var/lib/mysql")
- (rundir "/run/mysqld"))
+ (rundir "/var/run/mysql"))
(mkdir-p datadir)
(chown datadir uid gid)
(mkdir-p rundir)
@@ -516,8 +624,11 @@ FLUSH PRIVILEGES;
(my.cnf (mysql-configuration-file config)))
#~(make-forkexec-constructor
(list (string-append #$mysql "/bin/mysqld")
- (string-append "--defaults-file=" #$my.cnf))
- #:user "mysql" #:group "mysql")))
+ (string-append "--defaults-file=" #$my.cnf)
+ "--pid-file=/var/run/mysql/pid")
+ #:user "mysql"
+ #:group "mysql"
+ #:pid-file "/var/run/mysql/pid")))
(stop #~(make-kill-destructor)))))
(define mysql-service-type
diff --git a/gnu/services/message-broker.scm b/gnu/services/message-broker.scm
new file mode 100644
index 0000000000..e711a4cbdc
--- /dev/null
+++ b/gnu/services/message-broker.scm
@@ -0,0 +1,114 @@
+;;; GNU Guix --- Functional package management for GNU
+;;; Copyright © 2018 Christopher Baines <mail@cbaines.net>
+;;;
+;;; This file is part of GNU Guix.
+;;;
+;;; GNU Guix is free software; you can redistribute it and/or modify it
+;;; under the terms of the GNU General Public License as published by
+;;; the Free Software Foundation; either version 3 of the License, or (at
+;;; your option) any later version.
+;;;
+;;; GNU Guix is distributed in the hope that it will be useful, but
+;;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;;; GNU General Public License for more details.
+;;;
+;;; You should have received a copy of the GNU General Public License
+;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
+
+(define-module (gnu services message-broker)
+ #:use-module (gnu services)
+ #:use-module (gnu services shepherd)
+ #:use-module (gnu system shadow)
+ #:use-module (gnu packages admin)
+ #:use-module ((gnu packages base) #:select (glibc-utf8-locales))
+ #:use-module (gnu packages rabbitmq)
+ #:use-module (guix modules)
+ #:use-module (guix records)
+ #:use-module (guix gexp)
+ #:use-module (ice-9 match)
+ #:export (<rabbitmq-configuration>
+ rabbitmq-configuration
+ rabbitmq-configuration?
+ rabbitmq-configuration-rabbitmq
+ rabbitmq-configuration-locale
+ rabbitmq-configuration-interfaces
+ rabbitmq-configuration-tcp-port
+ rabbitmq-configuration-udp-port
+ rabbitmq-configuration-additional-options
+
+ rabbitmq-service-type))
+
+
+;;;
+;;; RabbitMQ
+;;;
+
+(define-record-type* <rabbitmq-configuration>
+ rabbitmq-configuration make-rabbitmq-configuration
+ rabbitmq-configuration?
+ (rabbitmq rabbitmq-configuration-rabbitmq ;<package>
+ (default rabbitmq))
+ (locale rabbitmq-configuration-rabbitmq
+ (default "en_US.UTF-8"))
+ (interfaces rabbitmq-configuration-interfaces
+ (default '("0.0.0.0")))
+ (tcp-port rabbitmq-configuration-tcp-port
+ (default 11211))
+ (udp-port rabbitmq-configuration-udp-port
+ (default 11211))
+ (additional-options rabbitmq-configuration-additional-options
+ (default '())))
+
+(define %rabbitmq-accounts
+ (list (user-group (name "rabbitmq") (system? #t))
+ (user-account
+ (name "rabbitmq")
+ (group "rabbitmq")
+ (system? #t)
+ (comment "Rabbitmq server user")
+ (home-directory "/var/lib/rabbitmq")
+ (shell (file-append shadow "/sbin/nologin")))))
+
+(define rabbitmq-activation
+ #~(begin
+ (use-modules (guix build utils))
+ (let ((user (getpwnam "rabbitmq")))
+ (mkdir-p "/var/run/rabbitmq")
+ (chown "/var/run/rabbitmq"
+ (passwd:uid user) (passwd:gid user)))))
+
+(define rabbitmq-shepherd-service
+ (match-lambda
+ (($ <rabbitmq-configuration> rabbitmq locale interfaces tcp-port udp-port
+ additional-options)
+ (with-imported-modules (source-module-closure
+ '((gnu build shepherd)))
+ (list (shepherd-service
+ (provision '(rabbitmq))
+ (documentation "Run the Rabbitmq daemon.")
+ (requirement '(user-processes loopback))
+ (modules '((gnu build shepherd)))
+ (start #~(make-forkexec-constructor
+ '(#$(file-append rabbitmq "/sbin/rabbitmq-server"))
+ #:pid-file "/var/run/rabbitmq/pid"
+ #:environment-variables
+ `("RABBITMQ_PID_FILE=/var/run/rabbitmq/pid"
+ "HOME=/var/lib/rabbitmq"
+ ;; Elixir, the language used by RabbitMQ requires a
+ ;; UTF8 locale to function properly
+ ,(string-append "GUIX_LOCPATH="
+ #$glibc-utf8-locales "/lib/locale")
+ ,#$(string-append "LC_ALL=" locale))))
+ (stop #~(make-kill-destructor))))))))
+
+(define rabbitmq-service-type
+ (service-type (name 'rabbitmq)
+ (extensions
+ (list (service-extension shepherd-root-service-type
+ rabbitmq-shepherd-service)
+ (service-extension activation-service-type
+ (const rabbitmq-activation))
+ (service-extension account-service-type
+ (const %rabbitmq-accounts))))
+ (default-value (rabbitmq-configuration))))