at 18.09-beta 2.8 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.marathon; 8 9in { 10 11 ###### interface 12 13 options.services.marathon = { 14 enable = mkOption { 15 type = types.bool; 16 default = false; 17 description = '' 18 Whether to enable the marathon mesos framework. 19 ''; 20 }; 21 22 master = mkOption { 23 type = types.str; 24 default = "zk://${concatStringsSep "," cfg.zookeeperHosts}/mesos"; 25 example = "zk://1.2.3.4:2181,2.3.4.5:2181,3.4.5.6:2181/mesos"; 26 description = '' 27 Mesos master address. See <link xlink:href="https://mesosphere.github.io/marathon/docs/"/> for details. 28 ''; 29 }; 30 31 zookeeperHosts = mkOption { 32 type = types.listOf types.str; 33 default = [ "localhost:2181" ]; 34 example = [ "1.2.3.4:2181" "2.3.4.5:2181" "3.4.5.6:2181" ]; 35 description = '' 36 ZooKeeper hosts' addresses. 37 ''; 38 }; 39 40 user = mkOption { 41 type = types.str; 42 default = "marathon"; 43 example = "root"; 44 description = '' 45 The user that the Marathon framework will be launched as. If the user doesn't exist it will be created. 46 If you want to run apps that require root access or you want to launch apps using arbitrary users, that 47 is using the `--mesos_user` flag then you need to change this to `root`. 48 ''; 49 }; 50 51 httpPort = mkOption { 52 type = types.int; 53 default = 8080; 54 description = '' 55 Marathon listening port for HTTP connections. 56 ''; 57 }; 58 59 extraCmdLineOptions = mkOption { 60 type = types.listOf types.str; 61 default = [ ]; 62 example = [ "--https_port=8443" "--zk_timeout=10000" "--marathon_store_timeout=2000" ]; 63 description = '' 64 Extra command line options to pass to Marathon. 65 See <link xlink:href="https://mesosphere.github.io/marathon/docs/command-line-flags.html"/> for all possible flags. 66 ''; 67 }; 68 69 environment = mkOption { 70 default = { }; 71 type = types.attrs; 72 example = { JAVA_OPTS = "-Xmx512m"; MESOSPHERE_HTTP_CREDENTIALS = "username:password"; }; 73 description = '' 74 Environment variables passed to Marathon. 75 ''; 76 }; 77 }; 78 79 ###### implementation 80 81 config = mkIf cfg.enable { 82 systemd.services.marathon = { 83 description = "Marathon Service"; 84 environment = cfg.environment; 85 wantedBy = [ "multi-user.target" ]; 86 after = [ "network.target" "zookeeper.service" "mesos-master.service" "mesos-slave.service" ]; 87 88 serviceConfig = { 89 ExecStart = "${pkgs.marathon}/bin/marathon --master ${cfg.master} --zk zk://${concatStringsSep "," cfg.zookeeperHosts}/marathon --http_port ${toString cfg.httpPort} ${concatStringsSep " " cfg.extraCmdLineOptions}"; 90 User = cfg.user; 91 Restart = "always"; 92 RestartSec = "2"; 93 }; 94 }; 95 96 users.users.${cfg.user} = { }; 97 }; 98}