aboutsummaryrefslogtreecommitdiff
path: root/gnu/services/databases.scm
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/services/databases.scm')
-rw-r--r--gnu/services/databases.scm174
1 files changed, 174 insertions, 0 deletions
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index 7113f1f2a1..e2c2b13735 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -55,6 +55,19 @@
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-configuration-extra-config
+
+ elasticsearch-service
+ elasticsearch-service-type
+
memcached-service-type
<memcached-configuration>
memcached-configuration
@@ -299,6 +312,167 @@ 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))
+ (extra-config elasticsearch-configuration-extra-config
+ (default '())))
+
+(define (elasticsearch-configuration-directory data-path
+ logs-path
+ http-port
+ transport-port
+ extra-config)
+ (define contents
+ (append-map
+ (match-lambda
+ ((key) '())
+ ((key . #f) '())
+ ((key values ...) `(,key ": " ,@values "\n")))
+
+ `(("path.data" ,data-path)
+ ("path.logs" ,logs-path)
+ ("http.port" ,(number->string http-port))
+ ("transport.tcp.port" ,(number->string transport-port))
+ ,@extra-config)))
+
+ (computed-file
+ "elasticsearch-config"
+ #~(begin
+ (mkdir #$output)
+ (mkdir (string-append #$output "/scripts"))
+ (call-with-output-file (string-append #$output "/log4j2.properties")
+ (lambda (port)
+ (display "" port)))
+ (call-with-output-file (string-append #$output "/jvm.options")
+ (lambda (port)
+ (display "
+-Xms100m
+-Xmx100m
+
+-XX:+UseConcMarkSweepGC
+-XX:CMSInitiatingOccupancyFraction=75
+-XX:+UseCMSInitiatingOccupancyOnly
+
+## optimizations
+
+# pre-touch memory pages used by the JVM during initialization
+-XX:+AlwaysPreTouch
+
+## basic
+
+# force the server VM (remove on 32-bit client JVMs)
+-server
+
+# explicitly set the stack size (reduce to 320k on 32-bit client JVMs)
+-Xss1m
+
+# set to headless, just in case
+-Djava.awt.headless=true
+
+# ensure UTF-8 encoding by default (e.g. filenames)
+-Dfile.encoding=UTF-8
+
+# use our provided JNA always versus the system one
+-Djna.nosys=true
+
+# use old-style file permissions on JDK9
+-Djdk.io.permissionsUseCanonicalPath=true
+
+# flags to configure Netty
+-Dio.netty.noUnsafe=true
+-Dio.netty.noKeySetOptimization=true
+-Dio.netty.recycler.maxCapacityPerThread=0
+
+# log4j 2
+-Dlog4j.shutdownHookEnabled=false
+-Dlog4j2.disable.jmx=true
+-Dlog4j.skipJansi=true
+" port)))
+ (call-with-output-file (string-append #$output "/elasticsearch.yml")
+ (lambda (port)
+ (display
+ (string-append #$@contents)
+ 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 extra-config)
+ (list (shepherd-service
+ (provision '(elasticsearch))
+ (documentation "Run the Elasticsearch daemon.")
+ (requirement '(user-processes syslogd))
+ (start #~(let ((config-directory
+ #$(elasticsearch-configuration-directory
+ data-path logs-path http-port transport-port
+ extra-config)))
+ (make-forkexec-constructor
+ (list
+ (string-append #$elasticsearch "/bin/elasticsearch")
+ "-d"
+ "-p" "/var/run/elasticsearch/pid"
+ (string-append "-Epath.conf=" config-directory))
+ #:user "elasticsearch"
+ #:pid-file "/var/run/elasticsearch/pid"
+ #:environment-variables
+ (list (string-append "ES_JVM_OPTIONS="
+ config-directory "/jvm.options"))
+ #: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
;;;