forked from mirrors/nixpkgs
Merge branch 'pkgs/pythonPackages/fix_graphite2' of git://github.com/offlinehacker/nixpkgs
nixos/graphite: Make pure, fix several bugs, add dataDir option
This commit is contained in:
commit
d944c01db6
|
@ -4,17 +4,31 @@ with pkgs.lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.graphite;
|
cfg = config.services.graphite;
|
||||||
writeTextOrNull = f: t: if t == null then null else pkgs.writeText f t;
|
writeTextOrNull = f: t: if t == null then null else pkgs.writeTextDir f t;
|
||||||
|
|
||||||
|
dataDir = cfg.dataDir;
|
||||||
|
|
||||||
|
configDir = pkgs.buildEnv {
|
||||||
|
name = "graphite-config";
|
||||||
|
paths = lists.filter (el: el != null) [
|
||||||
|
(writeTextOrNull "carbon.conf" cfg.carbon.config)
|
||||||
|
(writeTextOrNull "storage-agregation.conf" cfg.carbon.storageAggregation)
|
||||||
|
(writeTextOrNull "storage-schemas.conf" cfg.carbon.storageSchemas)
|
||||||
|
(writeTextOrNull "blacklist.conf" cfg.carbon.blacklist)
|
||||||
|
(writeTextOrNull "whitelist.conf" cfg.carbon.whitelist)
|
||||||
|
(writeTextOrNull "rewrite-rules.conf" cfg.carbon.rewriteRules)
|
||||||
|
(writeTextOrNull "relay-rules.conf" cfg.carbon.relayRules)
|
||||||
|
(writeTextOrNull "aggregation-rules.conf" cfg.carbon.aggregationRules)
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
dataDir = "/var/db/graphite";
|
|
||||||
carbonOpts = name: with config.ids; ''
|
carbonOpts = name: with config.ids; ''
|
||||||
--nodaemon --syslog --prefix=${name} --pidfile /var/run/${name}.pid \
|
--nodaemon --syslog --prefix=${name} --pidfile ${dataDir}/${name}.pid ${name}
|
||||||
--uid ${toString uids.graphite} --gid ${toString uids.graphite} ${name}
|
|
||||||
'';
|
'';
|
||||||
carbonEnv = {
|
carbonEnv = {
|
||||||
PYTHONPATH = "${pkgs.python27Packages.carbon}/lib/python2.7/site-packages";
|
PYTHONPATH = "${pkgs.python27Packages.carbon}/lib/python2.7/site-packages";
|
||||||
GRAPHITE_ROOT = dataDir;
|
GRAPHITE_ROOT = dataDir;
|
||||||
GRAPHITE_CONF_DIR = "/etc/graphite/";
|
GRAPHITE_CONF_DIR = configDir;
|
||||||
GRAPHITE_STORAGE_DIR = dataDir;
|
GRAPHITE_STORAGE_DIR = dataDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,6 +37,14 @@ in {
|
||||||
###### interface
|
###### interface
|
||||||
|
|
||||||
options.services.graphite = {
|
options.services.graphite = {
|
||||||
|
dataDir = mkOption {
|
||||||
|
type = types.path;
|
||||||
|
default = "/var/db/graphite";
|
||||||
|
description = ''
|
||||||
|
Data directory for graphite.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
web = {
|
web = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
description = "Whether to enable graphite web frontend";
|
description = "Whether to enable graphite web frontend";
|
||||||
|
@ -38,8 +60,8 @@ in {
|
||||||
|
|
||||||
port = mkOption {
|
port = mkOption {
|
||||||
description = "Graphite web frontend port";
|
description = "Graphite web frontend port";
|
||||||
default = "8080";
|
default = 8080;
|
||||||
type = types.str;
|
type = types.int;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -152,31 +174,17 @@ in {
|
||||||
###### implementation
|
###### implementation
|
||||||
|
|
||||||
config = mkIf (cfg.carbon.enableAggregator || cfg.carbon.enableCache || cfg.carbon.enableRelay || cfg.web.enable) {
|
config = mkIf (cfg.carbon.enableAggregator || cfg.carbon.enableCache || cfg.carbon.enableRelay || cfg.web.enable) {
|
||||||
environment.etc = lists.filter (el: el.source != null) [
|
systemd.services.carbonCache = {
|
||||||
{ source = writeTextOrNull "carbon.conf" cfg.carbon.config;
|
enable = cfg.carbon.enableCache;
|
||||||
target = "graphite/carbon.conf"; }
|
|
||||||
{ source = writeTextOrNull "storage-agregation.conf" cfg.carbon.storageAggregation;
|
|
||||||
target = "graphite/storage-agregation.conf"; }
|
|
||||||
{ source = writeTextOrNull "storage-schemas.conf" cfg.carbon.storageSchemas;
|
|
||||||
target = "graphite/storage-schemas.conf"; }
|
|
||||||
{ source = writeTextOrNull "blacklist.conf" cfg.carbon.blacklist;
|
|
||||||
target = "graphite/blacklist.conf"; }
|
|
||||||
{ source = writeTextOrNull "whitelist.conf" cfg.carbon.whitelist;
|
|
||||||
target = "graphite/whitelist.conf"; }
|
|
||||||
{ source = writeTextOrNull "rewrite-rules.conf" cfg.carbon.rewriteRules;
|
|
||||||
target = "graphite/rewrite-rules.conf"; }
|
|
||||||
{ source = writeTextOrNull "relay-rules.conf" cfg.carbon.relayRules;
|
|
||||||
target = "graphite/relay-rules.conf"; }
|
|
||||||
{ source = writeTextOrNull "aggregation-rules.conf" cfg.carbon.aggregationRules;
|
|
||||||
target = "graphite/aggregation-rules.conf"; }
|
|
||||||
];
|
|
||||||
|
|
||||||
systemd.services.carbonCache = mkIf cfg.carbon.enableCache {
|
|
||||||
description = "Graphite Data Storage Backend";
|
description = "Graphite Data Storage Backend";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-interfaces.target" ];
|
after = [ "network-interfaces.target" ];
|
||||||
environment = carbonEnv;
|
environment = carbonEnv;
|
||||||
serviceConfig.ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-cache"}";
|
serviceConfig = {
|
||||||
|
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-cache"}";
|
||||||
|
User = "graphite";
|
||||||
|
Group = "graphite";
|
||||||
|
};
|
||||||
restartTriggers = [
|
restartTriggers = [
|
||||||
pkgs.pythonPackages.carbon
|
pkgs.pythonPackages.carbon
|
||||||
cfg.carbon.config
|
cfg.carbon.config
|
||||||
|
@ -185,33 +193,45 @@ in {
|
||||||
cfg.carbon.rewriteRules
|
cfg.carbon.rewriteRules
|
||||||
];
|
];
|
||||||
preStart = ''
|
preStart = ''
|
||||||
mkdir -p ${dataDir}/whisper
|
mkdir -m 0700 -p ${cfg.dataDir}/whisper
|
||||||
|
if [ "$(id -u)" = 0 ]; then chown -R graphite:graphite ${cfg.dataDir}; fi
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.carbonAggregator = mkIf cfg.carbon.enableAggregator {
|
systemd.services.carbonAggregator = {
|
||||||
|
enable = cfg.carbon.enableAggregator;
|
||||||
description = "Carbon Data Aggregator";
|
description = "Carbon Data Aggregator";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-interfaces.target" ];
|
after = [ "network-interfaces.target" ];
|
||||||
environment = carbonEnv;
|
environment = carbonEnv;
|
||||||
serviceConfig.ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-aggregator"}";
|
serviceConfig = {
|
||||||
|
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-aggregator"}";
|
||||||
|
User = "graphite";
|
||||||
|
Group = "graphite";
|
||||||
|
};
|
||||||
restartTriggers = [
|
restartTriggers = [
|
||||||
pkgs.pythonPackages.carbon cfg.carbon.config cfg.carbon.aggregationRules
|
pkgs.pythonPackages.carbon cfg.carbon.config cfg.carbon.aggregationRules
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.carbonRelay = mkIf cfg.carbon.enableRelay {
|
systemd.services.carbonRelay = {
|
||||||
|
enable = cfg.carbon.enableRelay;
|
||||||
description = "Carbon Data Relay";
|
description = "Carbon Data Relay";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-interfaces.target" ];
|
after = [ "network-interfaces.target" ];
|
||||||
environment = carbonEnv;
|
environment = carbonEnv;
|
||||||
serviceConfig.ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-relay"}";
|
serviceConfig = {
|
||||||
|
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-relay"}";
|
||||||
|
User = "graphite";
|
||||||
|
Group = "graphite";
|
||||||
|
};
|
||||||
restartTriggers = [
|
restartTriggers = [
|
||||||
pkgs.pythonPackages.carbon cfg.carbon.config cfg.carbon.relayRules
|
pkgs.pythonPackages.carbon cfg.carbon.config cfg.carbon.relayRules
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.services.graphiteWeb = mkIf cfg.web.enable {
|
systemd.services.graphiteWeb = {
|
||||||
|
enable = cfg.web.enable;
|
||||||
description = "Graphite Web Interface";
|
description = "Graphite Web Interface";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
after = [ "network-interfaces.target" ];
|
after = [ "network-interfaces.target" ];
|
||||||
|
@ -224,14 +244,15 @@ in {
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
ExecStart = ''
|
ExecStart = ''
|
||||||
${pkgs.python27Packages.waitress}/bin/waitress-serve \
|
${pkgs.python27Packages.waitress}/bin/waitress-serve \
|
||||||
--host=${cfg.web.host} --port=${cfg.web.port} \
|
--host=${cfg.web.host} --port=${toString cfg.web.port} \
|
||||||
--call django.core.handlers.wsgi:WSGIHandler'';
|
--call django.core.handlers.wsgi:WSGIHandler'';
|
||||||
User = "graphite";
|
User = "graphite";
|
||||||
Group = "graphite";
|
Group = "graphite";
|
||||||
};
|
};
|
||||||
preStart = ''
|
preStart = ''
|
||||||
if ! test -e ${dataDir}/db-created; then
|
if ! test -e ${dataDir}/db-created; then
|
||||||
mkdir -p ${dataDir}/{whisper/,log/webapp/}
|
mkdir -m 0700 -p ${dataDir}/{whisper/,log/webapp/}
|
||||||
|
if [ "$(id -u)" = 0 ]; then chown -R graphite:graphite ${cfg.dataDir}; fi
|
||||||
|
|
||||||
# populate database
|
# populate database
|
||||||
${pkgs.python27Packages.graphite_web}/bin/manage-graphite.py syncdb --noinput
|
${pkgs.python27Packages.graphite_web}/bin/manage-graphite.py syncdb --noinput
|
||||||
|
@ -259,7 +280,6 @@ in {
|
||||||
uid = config.ids.uids.graphite;
|
uid = config.ids.uids.graphite;
|
||||||
description = "Graphite daemon user";
|
description = "Graphite daemon user";
|
||||||
home = dataDir;
|
home = dataDir;
|
||||||
createHome = true;
|
|
||||||
};
|
};
|
||||||
users.extraGroups.graphite.gid = config.ids.gids.graphite;
|
users.extraGroups.graphite.gid = config.ids.gids.graphite;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue