summary refs log tree commit diff
path: root/nixos/modules/services/misc/mesos-master.nix
blob: 572a9847e46c698b731008aad0eb5b3669039e04 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.mesos.master;

in {

  options.services.mesos = {

    master = {
      enable = mkOption {
        description = "Whether to enable the Mesos Master.";
        default = false;
        type = types.bool;
      };

      ip = mkOption {
        description = "IP address to listen on.";
        default = "0.0.0.0";
        type = types.str;
      };

      port = mkOption {
        description = "Mesos Master port";
        default = 5050;
        type = types.int;
      };

      advertiseIp = mkOption {
        description = "IP address advertised to reach this master.";
        default = null;
        type = types.nullOr types.str;
      };

      advertisePort = mkOption {
        description = "Port advertised to reach this Mesos master.";
        default = null;
        type = types.nullOr types.int;
      };

      zk = mkOption {
        description = ''
          ZooKeeper URL (used for leader election amongst masters).
          May be one of:
            zk://host1:port1,host2:port2,.../mesos
            zk://username:password@host1:port1,host2:port2,.../mesos
        '';
        type = types.str;
      };

      workDir = mkOption {
        description = "The Mesos work directory.";
        default = "/var/lib/mesos/master";
        type = types.str;
      };

      extraCmdLineOptions = mkOption {
        description = ''
          Extra command line options for Mesos Master.

          See https://mesos.apache.org/documentation/latest/configuration/
        '';
        default = [ "" ];
        type = types.listOf types.str;
        example = [ "--credentials=VALUE" ];
      };

      quorum = mkOption {
        description = ''
          The size of the quorum of replicas when using 'replicated_log' based
          registry. It is imperative to set this value to be a majority of
          masters i.e., quorum > (number of masters)/2.

          If 0 will fall back to --registry=in_memory.
        '';
        default = 0;
        type = types.int;
      };

      logLevel = mkOption {
        description = ''
          The logging level used. Possible values:
            'INFO', 'WARNING', 'ERROR'
        '';
        default = "INFO";
        type = types.str;
      };

    };


  };


  config = mkIf cfg.enable {
    systemd.tmpfiles.rules = [
      "d '${cfg.workDir}' 0700 - - - -"
    ];
    systemd.services.mesos-master = {
      description = "Mesos Master";
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" ];
      serviceConfig = {
        ExecStart = ''
          ${pkgs.mesos}/bin/mesos-master \
            --ip=${cfg.ip} \
            --port=${toString cfg.port} \
            ${optionalString (cfg.advertiseIp != null) "--advertise_ip=${cfg.advertiseIp}"} \
            ${optionalString (cfg.advertisePort  != null) "--advertise_port=${toString cfg.advertisePort}"} \
            ${if cfg.quorum == 0
              then "--registry=in_memory"
              else "--zk=${cfg.zk} --registry=replicated_log --quorum=${toString cfg.quorum}"} \
            --work_dir=${cfg.workDir} \
            --logging_level=${cfg.logLevel} \
            ${toString cfg.extraCmdLineOptions}
        '';
        Restart = "on-failure";
      };
    };
  };

}