summary refs log tree commit diff
path: root/nixos/modules/services/databases/mongodb.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nixos/modules/services/databases/mongodb.nix')
-rw-r--r--nixos/modules/services/databases/mongodb.nix55
1 files changed, 29 insertions, 26 deletions
diff --git a/nixos/modules/services/databases/mongodb.nix b/nixos/modules/services/databases/mongodb.nix
index fe82ca430e1..14ffdad9217 100644
--- a/nixos/modules/services/databases/mongodb.nix
+++ b/nixos/modules/services/databases/mongodb.nix
@@ -15,9 +15,11 @@ let
     bind_ip = ${cfg.bind_ip}
     ${optionalString cfg.quiet "quiet = true"}
     dbpath = ${cfg.dbpath}
-    logpath = ${cfg.logpath}
-    logappend = ${b2s cfg.logappend}
+    syslog = true
+    fork = true
+    pidfilepath = ${cfg.pidFile}
     ${optionalString (cfg.replSetName != "") "replSet = ${cfg.replSetName}"}
+    ${cfg.extraConfig}
   '';
 
 in
@@ -65,14 +67,9 @@ in
         description = "Location where MongoDB stores its files";
       };
 
-      logpath = mkOption {
-        default = "/var/log/mongodb/mongod.log";
-        description = "Location where MongoDB stores its logfile";
-      };
-
-      logappend = mkOption {
-        default = true;
-        description = "Append logfile instead over overwriting";
+      pidFile = mkOption {
+        default = "/var/run/mongodb.pid";
+        description = "Location of MongoDB pid file";
       };
 
       replSetName = mkOption {
@@ -82,6 +79,14 @@ in
           Otherwise, leave empty to run as single node.
         '';
       };
+
+      extraConfig = mkOption {
+        default = "";
+        example = ''
+          nojournal = true
+        '';
+        description = "MongoDB extra configuration";
+      };
     };
 
   };
@@ -99,22 +104,6 @@ in
 
     environment.systemPackages = [ mongodb ];
 
-    systemd.services.mongodb_init =
-      { description = "MongoDB server initialisation";
-
-        wantedBy = [ "mongodb.service" ];
-        before = [ "mongodb.service" ];
-
-        serviceConfig.Type = "oneshot";
-
-        script = ''
-          if ! test -e ${cfg.dbpath}; then
-              install -d -m0700 -o ${cfg.user} ${cfg.dbpath}
-              install -d -m0755 -o ${cfg.user} `dirname ${cfg.logpath}`
-          fi
-        '';
-      };
-
     systemd.services.mongodb =
       { description = "MongoDB server";
 
@@ -124,7 +113,21 @@ in
         serviceConfig = {
           ExecStart = "${mongodb}/bin/mongod --quiet --config ${mongoCnf}";
           User = cfg.user;
+          PIDFile = cfg.pidFile;
+          Type = "forking";
+          TimeoutStartSec=120; # intial creating of journal can take some time
+          PermissionsStartOnly = true;
         };
+
+        preStart = ''
+          rm ${cfg.dbpath}/mongod.lock || true
+          if ! test -e ${cfg.dbpath}; then
+              install -d -m0700 -o ${cfg.user} ${cfg.dbpath}
+          fi
+          if ! test -e ${cfg.pidFile}; then
+              install -D -o ${cfg.user} /dev/null ${cfg.pidFile}
+          fi
+        '';
       };
 
   };