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:
parent
271e0f7488
commit
996da030b6
|
@ -15,9 +15,11 @@ let
|
|||
bind_ip = ${cfg.bind_ip}
|
||||
${optionalString cfg.quiet "quiet = true"}
|
||||
dbpath = ${cfg.dbpath}
|
||||
logpath = ${cfg.logpath}
|
||||
logappend = ${b2s cfg.logappend}
|
||||
syslog = true
|
||||
fork = true
|
||||
pidfilepath = ${cfg.pidFile}
|
||||
${optionalString (cfg.replSetName != "") "replSet = ${cfg.replSetName}"}
|
||||
${cfg.extraConfig}
|
||||
'';
|
||||
|
||||
in
|
||||
|
@ -65,14 +67,9 @@ in
|
|||
description = "Location where MongoDB stores its files";
|
||||
};
|
||||
|
||||
logpath = mkOption {
|
||||
default = "/var/log/mongodb/mongod.log";
|
||||
description = "Location where MongoDB stores its logfile";
|
||||
};
|
||||
|
||||
logappend = mkOption {
|
||||
default = true;
|
||||
description = "Append logfile instead over overwriting";
|
||||
pidFile = mkOption {
|
||||
default = "/var/run/mongodb.pid";
|
||||
description = "Location of MongoDB pid file";
|
||||
};
|
||||
|
||||
replSetName = mkOption {
|
||||
|
@ -82,6 +79,14 @@ in
|
|||
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 ];
|
||||
|
||||
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";
|
||||
|
||||
|
@ -124,7 +113,20 @@ in
|
|||
serviceConfig = {
|
||||
ExecStart = "${mongodb}/bin/mongod --quiet --config ${mongoCnf}";
|
||||
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
|
||||
'';
|
||||
};
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue