graphite service: store PID files under /run and configure systemd to use them
The advantage of putting the PID file under the ephemeral /run is that when the machine crashes /run gets cleared allowing graphite to start once the machine is rebooted. We also set the PIDFile systemd option so that systemd knows the correct PID and enables systemd to remove the file after service shut down.
This commit is contained in:
@@ -41,8 +41,15 @@ let
|
|||||||
};
|
};
|
||||||
|
|
||||||
carbonOpts = name: with config.ids; ''
|
carbonOpts = name: with config.ids; ''
|
||||||
--nodaemon --syslog --prefix=${name} --pidfile ${dataDir}/${name}.pid ${name}
|
--nodaemon --syslog --prefix=${name} --pidfile /run/${name}/${name}.pid ${name}
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
mkPidFileDir = name: ''
|
||||||
|
mkdir -p /run/${name}
|
||||||
|
chmod 0700 /run/${name}
|
||||||
|
chown -R graphite:graphite /run/${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;
|
||||||
@@ -370,18 +377,20 @@ in {
|
|||||||
|
|
||||||
config = mkMerge [
|
config = mkMerge [
|
||||||
(mkIf cfg.carbon.enableCache {
|
(mkIf cfg.carbon.enableCache {
|
||||||
systemd.services.carbonCache = {
|
systemd.services.carbonCache = let name = "carbon-cache"; in {
|
||||||
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 = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-cache"}";
|
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts name}";
|
||||||
User = "graphite";
|
User = "graphite";
|
||||||
Group = "graphite";
|
Group = "graphite";
|
||||||
PermissionsStartOnly = true;
|
PermissionsStartOnly = true;
|
||||||
|
PIDFile="/run/${name}/${name}.pid";
|
||||||
};
|
};
|
||||||
preStart = ''
|
preStart = mkPidFileDir name + ''
|
||||||
|
|
||||||
mkdir -p ${cfg.dataDir}/whisper
|
mkdir -p ${cfg.dataDir}/whisper
|
||||||
chmod 0700 ${cfg.dataDir}/whisper
|
chmod 0700 ${cfg.dataDir}/whisper
|
||||||
chown -R graphite:graphite ${cfg.dataDir}
|
chown -R graphite:graphite ${cfg.dataDir}
|
||||||
@@ -390,31 +399,35 @@ in {
|
|||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.carbon.enableAggregator {
|
(mkIf cfg.carbon.enableAggregator {
|
||||||
systemd.services.carbonAggregator = {
|
systemd.services.carbonAggregator = let name = "carbon-aggregator"; in {
|
||||||
enable = cfg.carbon.enableAggregator;
|
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 = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-aggregator"}";
|
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts name}";
|
||||||
User = "graphite";
|
User = "graphite";
|
||||||
Group = "graphite";
|
Group = "graphite";
|
||||||
|
PIDFile="/run/${name}/${name}.pid";
|
||||||
};
|
};
|
||||||
|
preStart = mkPidFileDir name;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf cfg.carbon.enableRelay {
|
(mkIf cfg.carbon.enableRelay {
|
||||||
systemd.services.carbonRelay = {
|
systemd.services.carbonRelay = let name = "carbon-relay"; in {
|
||||||
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 = {
|
serviceConfig = {
|
||||||
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts "carbon-relay"}";
|
ExecStart = "${pkgs.twisted}/bin/twistd ${carbonOpts name}";
|
||||||
User = "graphite";
|
User = "graphite";
|
||||||
Group = "graphite";
|
Group = "graphite";
|
||||||
|
PIDFile="/run/${name}/${name}.pid";
|
||||||
};
|
};
|
||||||
|
preStart = mkPidFileDir name;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user