mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-14 14:10:33 +03:00
nixos/services.mackerel-agent: remove with lib;
This commit is contained in:
parent
56bd2c2da6
commit
5419e3778f
1 changed files with 21 additions and 24 deletions
|
@ -1,24 +1,21 @@
|
||||||
{ config, lib, pkgs, ... }:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
with lib;
|
|
||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.mackerel-agent;
|
cfg = config.services.mackerel-agent;
|
||||||
settingsFmt = pkgs.formats.toml {};
|
settingsFmt = pkgs.formats.toml {};
|
||||||
in {
|
in {
|
||||||
options.services.mackerel-agent = {
|
options.services.mackerel-agent = {
|
||||||
enable = mkEnableOption "mackerel.io agent";
|
enable = lib.mkEnableOption "mackerel.io agent";
|
||||||
|
|
||||||
# the upstream package runs as root, but doesn't seem to be strictly
|
# the upstream package runs as root, but doesn't seem to be strictly
|
||||||
# necessary for basic functionality
|
# necessary for basic functionality
|
||||||
runAsRoot = mkEnableOption "running as root";
|
runAsRoot = lib.mkEnableOption "running as root";
|
||||||
|
|
||||||
autoRetirement = mkEnableOption ''
|
autoRetirement = lib.mkEnableOption ''
|
||||||
retiring the host upon OS shutdown
|
retiring the host upon OS shutdown
|
||||||
'';
|
'';
|
||||||
|
|
||||||
apiKeyFile = mkOption {
|
apiKeyFile = lib.mkOption {
|
||||||
type = types.path;
|
type = lib.types.path;
|
||||||
example = "/run/keys/mackerel-api-key";
|
example = "/run/keys/mackerel-api-key";
|
||||||
description = ''
|
description = ''
|
||||||
Path to file containing the Mackerel API key. The file should contain a
|
Path to file containing the Mackerel API key. The file should contain a
|
||||||
|
@ -28,7 +25,7 @@ in {
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
settings = mkOption {
|
settings = lib.mkOption {
|
||||||
description = ''
|
description = ''
|
||||||
Options for mackerel-agent.conf.
|
Options for mackerel-agent.conf.
|
||||||
|
|
||||||
|
@ -42,29 +39,29 @@ in {
|
||||||
silent = false;
|
silent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
type = types.submodule {
|
type = lib.types.submodule {
|
||||||
freeformType = settingsFmt.type;
|
freeformType = settingsFmt.type;
|
||||||
|
|
||||||
options.host_status = {
|
options.host_status = {
|
||||||
on_start = mkOption {
|
on_start = lib.mkOption {
|
||||||
type = types.enum [ "working" "standby" "maintenance" "poweroff" ];
|
type = lib.types.enum [ "working" "standby" "maintenance" "poweroff" ];
|
||||||
description = "Host status after agent startup.";
|
description = "Host status after agent startup.";
|
||||||
default = "working";
|
default = "working";
|
||||||
};
|
};
|
||||||
on_stop = mkOption {
|
on_stop = lib.mkOption {
|
||||||
type = types.enum [ "working" "standby" "maintenance" "poweroff" ];
|
type = lib.types.enum [ "working" "standby" "maintenance" "poweroff" ];
|
||||||
description = "Host status after agent shutdown.";
|
description = "Host status after agent shutdown.";
|
||||||
default = "poweroff";
|
default = "poweroff";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
options.diagnostic =
|
options.diagnostic =
|
||||||
mkEnableOption "collecting memory usage for the agent itself";
|
lib.mkEnableOption "collecting memory usage for the agent itself";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
environment.systemPackages = with pkgs; [ mackerel-agent ];
|
environment.systemPackages = with pkgs; [ mackerel-agent ];
|
||||||
|
|
||||||
environment.etc = {
|
environment.etc = {
|
||||||
|
@ -74,11 +71,11 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
services.mackerel-agent.settings = {
|
services.mackerel-agent.settings = {
|
||||||
root = mkDefault "/var/lib/mackerel-agent";
|
root = lib.mkDefault "/var/lib/mackerel-agent";
|
||||||
pidfile = mkDefault "/run/mackerel-agent/mackerel-agent.pid";
|
pidfile = lib.mkDefault "/run/mackerel-agent/mackerel-agent.pid";
|
||||||
|
|
||||||
# conf.d stores the symlink to cfg.apiKeyFile
|
# conf.d stores the symlink to cfg.apiKeyFile
|
||||||
include = mkDefault "/etc/mackerel-agent/conf.d/*.conf";
|
include = lib.mkDefault "/etc/mackerel-agent/conf.d/*.conf";
|
||||||
};
|
};
|
||||||
|
|
||||||
# upstream service file in https://github.com/mackerelio/mackerel-agent/blob/master/packaging/rpm/src/mackerel-agent.service
|
# upstream service file in https://github.com/mackerelio/mackerel-agent/blob/master/packaging/rpm/src/mackerel-agent.service
|
||||||
|
@ -88,20 +85,20 @@ in {
|
||||||
after = [ "network-online.target" "nss-lookup.target" ];
|
after = [ "network-online.target" "nss-lookup.target" ];
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
environment = {
|
environment = {
|
||||||
MACKEREL_PLUGIN_WORKDIR = mkDefault "%C/mackerel-agent";
|
MACKEREL_PLUGIN_WORKDIR = lib.mkDefault "%C/mackerel-agent";
|
||||||
};
|
};
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
DynamicUser = !cfg.runAsRoot;
|
DynamicUser = !cfg.runAsRoot;
|
||||||
PrivateTmp = mkDefault true;
|
PrivateTmp = lib.mkDefault true;
|
||||||
CacheDirectory = "mackerel-agent";
|
CacheDirectory = "mackerel-agent";
|
||||||
ConfigurationDirectory = "mackerel-agent";
|
ConfigurationDirectory = "mackerel-agent";
|
||||||
RuntimeDirectory = "mackerel-agent";
|
RuntimeDirectory = "mackerel-agent";
|
||||||
StateDirectory = "mackerel-agent";
|
StateDirectory = "mackerel-agent";
|
||||||
ExecStart = "${pkgs.mackerel-agent}/bin/mackerel-agent supervise";
|
ExecStart = "${pkgs.mackerel-agent}/bin/mackerel-agent supervise";
|
||||||
ExecStopPost = mkIf cfg.autoRetirement "${pkgs.mackerel-agent}/bin/mackerel-agent retire -force";
|
ExecStopPost = lib.mkIf cfg.autoRetirement "${pkgs.mackerel-agent}/bin/mackerel-agent retire -force";
|
||||||
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
ExecReload = "${pkgs.coreutils}/bin/kill -HUP $MAINPID";
|
||||||
LimitNOFILE = mkDefault 65536;
|
LimitNOFILE = lib.mkDefault 65536;
|
||||||
LimitNPROC = mkDefault 65536;
|
LimitNPROC = lib.mkDefault 65536;
|
||||||
};
|
};
|
||||||
restartTriggers = [
|
restartTriggers = [
|
||||||
config.environment.etc."mackerel-agent/mackerel-agent.conf".source
|
config.environment.etc."mackerel-agent/mackerel-agent.conf".source
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue