diff options
author | Christopher Baines <mail@cbaines.net> | 2017-08-22 11:15:39 +0100 |
---|---|---|
committer | Christopher Baines <christopher.baines@digital.cabinet-office.gov.uk> | 2018-02-06 17:36:41 +0000 |
commit | 599a7321685e4cb291ea78b0472cb634903c9776 (patch) | |
tree | 92bca387f52a32d3d1a62c1c3ccd0336b263ded0 /gnu/services/databases.scm | |
parent | d7a25c8091adff15700b0010fcef455f41f2f467 (diff) | |
download | gnu-guix-599a7321685e4cb291ea78b0472cb634903c9776.tar gnu-guix-599a7321685e4cb291ea78b0472cb634903c9776.tar.gz |
services: Add elasticsearch.
Diffstat (limited to 'gnu/services/databases.scm')
-rw-r--r-- | gnu/services/databases.scm | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm index b34a67aa95..6dee16ded4 100644 --- a/gnu/services/databases.scm +++ b/gnu/services/databases.scm @@ -35,6 +35,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 @@ -205,6 +217,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 ;;; |