diff --git a/modules/services/databases/mongodb.nix b/modules/services/databases/mongodb.nix index 887f1f0529f1..bdae728c6463 100644 --- a/modules/services/databases/mongodb.nix +++ b/modules/services/databases/mongodb.nix @@ -102,20 +102,28 @@ 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"; wantedBy = [ "multi-user.target" ]; after = [ "network.target" ]; - preStart = - '' - if ! test -e ${cfg.dbpath}; then - install -d -m0700 -o ${cfg.user} ${cfg.dbpath} - install -d -m0755 -o ${cfg.user} `dirname ${cfg.logpath}` - fi - ''; - serviceConfig = { ExecStart = "${mongodb}/bin/mongod --quiet --config ${mongoCnf}"; User = cfg.user;