0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/mongodb: service fixes

- Log to syslog, so journal picks-up logs
- Start as foring service, so systemd will wait for service to start
- Add extraConfig option
This commit is contained in:
Jaka Hudoklin 2014-09-16 10:24:35 +02:00
parent 271e0f7488
commit 996da030b6

View file

@ -15,9 +15,11 @@ let
bind_ip = ${cfg.bind_ip} bind_ip = ${cfg.bind_ip}
${optionalString cfg.quiet "quiet = true"} ${optionalString cfg.quiet "quiet = true"}
dbpath = ${cfg.dbpath} dbpath = ${cfg.dbpath}
logpath = ${cfg.logpath} syslog = true
logappend = ${b2s cfg.logappend} fork = true
pidfilepath = ${cfg.pidFile}
${optionalString (cfg.replSetName != "") "replSet = ${cfg.replSetName}"} ${optionalString (cfg.replSetName != "") "replSet = ${cfg.replSetName}"}
${cfg.extraConfig}
''; '';
in in
@ -65,14 +67,9 @@ in
description = "Location where MongoDB stores its files"; description = "Location where MongoDB stores its files";
}; };
logpath = mkOption { pidFile = mkOption {
default = "/var/log/mongodb/mongod.log"; default = "/var/run/mongodb.pid";
description = "Location where MongoDB stores its logfile"; description = "Location of MongoDB pid file";
};
logappend = mkOption {
default = true;
description = "Append logfile instead over overwriting";
}; };
replSetName = mkOption { replSetName = mkOption {
@ -82,6 +79,14 @@ in
Otherwise, leave empty to run as single node. Otherwise, leave empty to run as single node.
''; '';
}; };
extraConfig = mkOption {
default = "";
example = ''
nojournal = true
'';
description = "MongoDB extra configuration";
};
}; };
}; };
@ -99,22 +104,6 @@ in
environment.systemPackages = [ mongodb ]; 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 = systemd.services.mongodb =
{ description = "MongoDB server"; { description = "MongoDB server";
@ -124,7 +113,20 @@ in
serviceConfig = { serviceConfig = {
ExecStart = "${mongodb}/bin/mongod --quiet --config ${mongoCnf}"; ExecStart = "${mongodb}/bin/mongod --quiet --config ${mongoCnf}";
User = cfg.user; User = cfg.user;
PIDFile = cfg.pidFile;
Type = "forking";
TimeoutStartSec=120; # intial creating of journal can take some time
PermissionsStartOnly = true;
}; };
preStart = ''
if ! test -e ${cfg.dbpath}; then
install -d -m0700 -o ${cfg.user} ${cfg.dbpath}
fi
if ! test -e ${cfg.pidFile}; then
install -D -o ${cfg.user} /dev/null ${cfg.pidFile}
fi
'';
}; };
}; };