2
0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-01-06 04:53:27 +00:00

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,19 +102,27 @@ in
environment.systemPackages = [ mongodb ];
systemd.services.mongodb =
{ description = "MongoDB server";
systemd.services.mongodb_init =
{ description = "MongoDB server initialisation";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
wantedBy = [ "mongodb.service" ];
before = [ "mongodb.service" ];
preStart =
''
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" ];
serviceConfig = {
ExecStart = "${mongodb}/bin/mongod --quiet --config ${mongoCnf}";