2013-11-04 13:49:30 +04:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
with pkgs.lib;
|
|
|
|
let
|
|
|
|
serviceOpts = { name, config, ...}: {
|
|
|
|
options = {
|
|
|
|
command = mkOption {
|
|
|
|
description = "The command to execute";
|
|
|
|
};
|
|
|
|
directory = mkOption {
|
|
|
|
default = "/";
|
|
|
|
description = "Current directory when running the command";
|
|
|
|
};
|
2013-11-04 19:21:26 +04:00
|
|
|
environment = mkOption {
|
|
|
|
default = {};
|
|
|
|
example = {
|
|
|
|
PATH = "/some/path";
|
|
|
|
};
|
|
|
|
};
|
2014-03-07 20:57:45 +04:00
|
|
|
path = mkOption {
|
|
|
|
default = [];
|
|
|
|
description = "Current directory when running the command";
|
|
|
|
};
|
2014-02-18 02:15:41 +04:00
|
|
|
stopsignal = mkOption {
|
|
|
|
default = "TERM";
|
|
|
|
};
|
2013-11-08 14:26:23 +04:00
|
|
|
startsecs = mkOption {
|
|
|
|
default = 1;
|
|
|
|
example = 0;
|
|
|
|
};
|
2014-03-14 20:37:23 +04:00
|
|
|
pidfile = mkOption {
|
|
|
|
default = null;
|
|
|
|
};
|
2013-11-04 13:49:30 +04:00
|
|
|
};
|
|
|
|
};
|
|
|
|
services = config.supervisord.services;
|
|
|
|
in {
|
|
|
|
options = {
|
|
|
|
supervisord = {
|
|
|
|
enable = mkOption {
|
|
|
|
default = true;
|
|
|
|
type = types.bool;
|
|
|
|
};
|
|
|
|
|
2014-08-17 23:33:59 +04:00
|
|
|
port = mkOption {
|
|
|
|
default = 65123;
|
|
|
|
type = types.int;
|
|
|
|
};
|
|
|
|
|
2013-11-04 13:49:30 +04:00
|
|
|
services = mkOption {
|
|
|
|
default = {};
|
|
|
|
type = types.loaOf types.optionSet;
|
|
|
|
description = ''
|
|
|
|
Supervisord services to start
|
|
|
|
'';
|
|
|
|
options = [ serviceOpts ];
|
|
|
|
};
|
|
|
|
|
|
|
|
tailLogs = mkOption {
|
|
|
|
default = false;
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether or not to tail all logs to standard out.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
configFile = mkOption {};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf config.supervisord.enable {
|
|
|
|
supervisord.configFile = pkgs.writeText "supervisord.conf" ''
|
|
|
|
[supervisord]
|
2014-02-18 02:15:41 +04:00
|
|
|
|
|
|
|
[supervisorctl]
|
2014-08-17 23:33:59 +04:00
|
|
|
serverurl = http://localhost:${toString config.supervisord.port}
|
2014-02-18 02:15:41 +04:00
|
|
|
|
|
|
|
[inet_http_server]
|
2014-08-17 23:33:59 +04:00
|
|
|
port = 127.0.0.1:${toString config.supervisord.port}
|
2014-02-18 02:15:41 +04:00
|
|
|
|
|
|
|
[rpcinterface:supervisor]
|
|
|
|
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
|
2013-11-04 13:49:30 +04:00
|
|
|
|
|
|
|
${concatMapStrings (name:
|
|
|
|
let
|
|
|
|
cfg = getAttr name services;
|
|
|
|
in
|
|
|
|
''
|
|
|
|
[program:${name}]
|
2014-03-14 20:37:23 +04:00
|
|
|
command=${if cfg.pidfile == null then cfg.command else "${pkgs.pythonPackages.supervisor}/bin/pidproxy ${cfg.pidfile} ${cfg.command}"}
|
2014-03-07 20:57:45 +04:00
|
|
|
environment=${concatStrings
|
|
|
|
(mapAttrsToList (name: value: "${name}=\"${value}\",") (
|
|
|
|
cfg.environment // { PATH = concatStringsSep ":"
|
|
|
|
[("%(ENV_PATH)s") (cfg.path) (maybeAttr "PATH" "" cfg.environment)];
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)}
|
2013-11-04 13:49:30 +04:00
|
|
|
directory=${cfg.directory}
|
|
|
|
redirect_stderr=true
|
2013-11-08 14:26:23 +04:00
|
|
|
startsecs=${toString cfg.startsecs}
|
2014-02-18 02:15:41 +04:00
|
|
|
stopsignal=${cfg.stopsignal}
|
|
|
|
stopasgroup=true
|
2013-11-04 13:49:30 +04:00
|
|
|
''
|
|
|
|
) (attrNames services)
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2014-02-17 03:31:11 +04:00
|
|
|
}
|