summaryrefslogtreecommitdiff
path: root/gnu/services
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2017-10-06 21:24:30 +0100
committerChristopher Baines <mail@cbaines.net>2017-10-06 21:24:30 +0100
commit5266ff719e274056cb3e2b9740183f0063177255 (patch)
tree6cb4b938f8d00566425762fba3799cc3105cf915 /gnu/services
parent6bbbca90736b6a34776a4ef15e954c80d8085878 (diff)
services: Add MongoDB.
* gnu/services/databases.scm (%default-mongodb-configuration-file, %mongodb-accounts, mongodb-service-type): New variables. (<mongodb-configuration>): New record type. (mongodb-activation, mongodb-shepherd-service): New procedures. * gnu/tests/databases.scm (%test-mongodb): New variable. * doc/guix.texi (Database Services): Add MongoDB documentation.
Diffstat (limited to 'gnu/services')
-rw-r--r--gnu/services/databases.scm89
1 files changed, 89 insertions, 0 deletions
diff --git a/gnu/services/databases.scm b/gnu/services/databases.scm
index de1f6b8411..6a01cb1ce6 100644
--- a/gnu/services/databases.scm
+++ b/gnu/services/databases.scm
@@ -44,6 +44,14 @@
memcached-configuration-udp-port
memcached-configuration-additional-options
+ <mongodb-configuration>
+ mongodb-configuration
+ mongodb-configuration?
+ mongodb-configuration-mongodb
+ mongodb-configuration-config-file
+ mongodb-configuration-data-directory
+ mongodb-service-type
+
mysql-service
mysql-service-type
mysql-configuration
@@ -264,6 +272,87 @@ and stores the database cluster in @var{data-directory}."
;;;
+;;; MongoDB
+;;;
+
+(define %default-mongodb-configuration-file
+ (plain-file
+ "mongodb.yaml"
+ "# GNU Guix: MongoDB default configuration file
+processManagement:
+ pidFilePath: /var/run/mongodb/pid
+storage:
+ dbPath: /var/lib/mongodb
+"))
+
+
+(define-record-type* <mongodb-configuration>
+ mongodb-configuration make-mongodb-configuration
+ mongodb-configuration?
+ (mongodb mongodb-configuration-mongodb
+ (default mongodb))
+ (config-file mongodb-configuration-config-file
+ (default %default-mongodb-configuration-file))
+ (data-directory mongodb-configuration-data-directory
+ (default "/var/lib/mongodb")))
+
+(define %mongodb-accounts
+ (list (user-group (name "mongodb") (system? #t))
+ (user-account
+ (name "mongodb")
+ (group "mongodb")
+ (system? #t)
+ (comment "Mongodb server user")
+ (home-directory "/var/lib/mongodb")
+ (shell (file-append shadow "/sbin/nologin")))))
+
+(define mongodb-activation
+ (match-lambda
+ (($ <mongodb-configuration> mongodb config-file data-directory)
+ #~(begin
+ (use-modules (guix build utils))
+ (let ((user (getpwnam "mongodb")))
+ (for-each
+ (lambda (directory)
+ (mkdir-p directory)
+ (chown directory
+ (passwd:uid user) (passwd:gid user)))
+ '("/var/run/mongodb" #$data-directory)))))))
+
+(define mongodb-shepherd-service
+ (match-lambda
+ (($ <mongodb-configuration> mongodb config-file data-directory)
+ (shepherd-service
+ (provision '(mongodb))
+ (documentation "Run the Mongodb daemon.")
+ (requirement '(user-processes loopback))
+ (start #~(make-forkexec-constructor
+ `(,(string-append #$mongodb "/bin/mongod")
+ "--config"
+ ,#$config-file)
+ #:user "mongodb"
+ #:group "mongodb"
+ #:pid-file "/var/run/mongodb/pid"
+ #:log-file "/var/log/mongodb.log"))
+ (stop #~(make-kill-destructor))))))
+
+(define mongodb-service-type
+ (service-type
+ (name 'mongodb)
+ (description "Run the MongoDB document database server.")
+ (extensions
+ (list (service-extension shepherd-root-service-type
+ (compose list
+ mongodb-shepherd-service))
+ (service-extension activation-service-type
+ mongodb-activation)
+ (service-extension account-service-type
+ (const %mongodb-accounts))))
+ (default-value
+ (mongodb-configuration))))
+
+
+;;;
;;; MySQL.
;;;