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.
This commit is contained in:
Rickard Nilsson 2013-02-25 09:04:31 +01:00
parent b0f33f2052
commit e44021494c

View File

@ -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;