mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-21 05:04:00 +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:
parent
b0f33f2052
commit
e44021494c
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user