From e44021494c461f52b5060602fb7ecea758e0b313 Mon Sep 17 00:00:00 2001 From: Rickard Nilsson Date: Mon, 25 Feb 2013 09:04:31 +0100 Subject: [PATCH] mongodb: Add initialisation service The mongodb service runs as user mongodb, and therefore the preStart-script has no permissions to set up mongodb directories. This is solved by adding an initialisation service that runs as root and just sets up the required directories. --- modules/services/databases/mongodb.nix | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/modules/services/databases/mongodb.nix b/modules/services/databases/mongodb.nix index 887f1f0529f..bdae728c646 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;