aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/nixos/modules/services/scheduling/marathon.nix
blob: 2e0d20c64b23a0f30cd59fa90de73821baeda0ae (plain)
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
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.marathon;

in {

  ###### interface

  options.services.marathon = {
    enable = mkOption {
      type = types.bool;
      default = false;
      description = ''
	Whether to enable the marathon mesos framework.
      '';
    };

    master = mkOption {
      type = types.str;
      default = "zk://${concatStringsSep "," cfg.zookeeperHosts}/mesos";
      example = "zk://1.2.3.4:2181,2.3.4.5:2181,3.4.5.6:2181/mesos";
      description = ''
	Mesos master address. See <link xlink:href="https://mesosphere.github.io/marathon/docs/"/> for details.
      '';
    };

    zookeeperHosts = mkOption {
      type = types.listOf types.str;
      default = [ "localhost:2181" ];
      example = [ "1.2.3.4:2181" "2.3.4.5:2181" "3.4.5.6:2181" ];
      description = ''
	ZooKeeper hosts' addresses.
      '';
    };

    user = mkOption {
      type = types.str;
      default = "marathon";
      example = "root";
      description = ''
	The user that the Marathon framework will be launched as. If the user doesn't exist it will be created.
	If you want to run apps that require root access or you want to launch apps using arbitrary users, that
	is using the `--mesos_user` flag then you need to change this to `root`.
      '';
    };

    httpPort = mkOption {
      type = types.int;
      default = 8080;
      description = ''
	Marathon listening port for HTTP connections.
      '';
    };

    extraCmdLineOptions = mkOption {
      type = types.listOf types.str;
      default = [ ];
      example = [ "--https_port=8443" "--zk_timeout=10000" "--marathon_store_timeout=2000" ];
      description = ''
	Extra command line options to pass to Marathon.
	See <link xlink:href="https://mesosphere.github.io/marathon/docs/command-line-flags.html"/> for all possible flags.
      '';
    };

    environment = mkOption {
      default = { };
      type = types.attrs;
      example = { JAVA_OPTS = "-Xmx512m"; MESOSPHERE_HTTP_CREDENTIALS = "username:password"; };
      description = ''
	Environment variables passed to Marathon.
      '';
    };
  };

  ###### implementation

  config = mkIf cfg.enable {
    systemd.services.marathon = {
      description = "Marathon Service";
      environment = cfg.environment;
      wantedBy = [ "multi-user.target" ];
      after = [ "network.target" "zookeeper.service" "mesos-master.service" "mesos-slave.service" ];

      serviceConfig = {
        ExecStart = "${pkgs.marathon}/bin/marathon --master ${cfg.master} --zk zk://${concatStringsSep "," cfg.zookeeperHosts}/marathon --http_port ${toString cfg.httpPort} ${concatStringsSep " " cfg.extraCmdLineOptions}";
        User = cfg.user;
        Restart = "always";
        RestartSec = "2";
      };
    };

    users.users.${cfg.user}.isSystemUser = true;
  };
}