nixpkgs/nixos/modules/services/cluster/panamax.nix

157 lines
4.0 KiB
Nix
Raw Normal View History

2014-12-08 12:02:57 +03:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.panamax;
2015-01-07 04:40:55 +03:00
panamax_api = pkgs.panamax_api.override { dataDir = cfg.dataDir + "/api"; };
panamax_ui = pkgs.panamax_ui.override { dataDir = cfg.dataDir + "/ui"; };
2014-12-08 12:02:57 +03:00
in {
##### Interface
options.services.panamax = {
enable = mkOption {
type = types.bool;
default = false;
description = ''
Whether to enable Panamax service.
'';
};
UIPort = mkOption {
type = types.int;
default = 8888;
description = ''
Panamax UI listening port.
'';
};
APIPort = mkOption {
type = types.int;
default = 3000;
description = ''
Panamax UI listening port.
'';
};
dataDir = mkOption {
type = types.str;
default = "/var/lib/panamax";
description = ''
Data dir for Panamax.
'';
};
fleetctlEndpoint = mkOption {
type = types.str;
default = "http://127.0.0.1:2379";
2014-12-08 12:02:57 +03:00
description = ''
2015-01-07 04:40:55 +03:00
Panamax fleetctl endpoint.
2014-12-08 12:02:57 +03:00
'';
};
journalEndpoint = mkOption {
type = types.str;
default = "http://127.0.0.1:19531";
description = ''
2015-01-07 04:40:55 +03:00
Panamax journal endpoint.
2014-12-08 12:02:57 +03:00
'';
};
secretKey = mkOption {
type = types.str;
default = "SomethingVeryLong.";
description = ''
2015-01-07 04:40:55 +03:00
Panamax secret key (do change this).
2014-12-08 12:02:57 +03:00
'';
};
};
##### Implementation
config = mkIf cfg.enable {
2015-01-07 04:40:55 +03:00
systemd.services.panamax-api = {
2014-12-08 12:02:57 +03:00
description = "Panamax API";
2015-01-07 04:40:55 +03:00
2014-12-08 12:02:57 +03:00
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "fleet.service" "etcd.service" "docker.service" ];
2015-01-07 04:40:55 +03:00
path = [ panamax_api ];
2014-12-08 12:02:57 +03:00
environment = {
2015-01-07 04:40:55 +03:00
RAILS_ENV = "production";
2014-12-08 12:02:57 +03:00
JOURNAL_ENDPOINT = cfg.journalEndpoint;
FLEETCTL_ENDPOINT = cfg.fleetctlEndpoint;
2015-01-07 04:40:55 +03:00
PANAMAX_DATABASE_PATH = "${cfg.dataDir}/api/db/mnt/db.sqlite3";
2014-12-08 12:02:57 +03:00
};
2015-01-07 04:40:55 +03:00
preStart = ''
rm -rf ${cfg.dataDir}/state/tmp
mkdir -p ${cfg.dataDir}/api/{db/mnt,state/log,state/tmp}
ln -sf ${panamax_api}/share/panamax-api/_db/{schema.rb,seeds.rb,migrate} ${cfg.dataDir}/api/db/
if [ ! -f ${cfg.dataDir}/.created ]; then
bundle exec rake db:setup
bundle exec rake db:seed
bundle exec rake panamax:templates:load || true
touch ${cfg.dataDir}/.created
else
bundle exec rake db:migrate
fi
'';
2014-12-08 12:02:57 +03:00
serviceConfig = {
2015-01-07 04:40:55 +03:00
ExecStart = "${panamax_api}/bin/bundle exec rails server --binding 127.0.0.1 --port ${toString cfg.APIPort}";
2014-12-08 12:02:57 +03:00
User = "panamax";
Group = "panamax";
};
};
2015-01-07 04:40:55 +03:00
systemd.services.panamax-ui = {
2014-12-08 12:02:57 +03:00
description = "Panamax UI";
2015-01-07 04:40:55 +03:00
2014-12-08 12:02:57 +03:00
wantedBy = [ "multi-user.target" ];
after = [ "network.target" "panamax_api.service" ];
2015-01-07 04:40:55 +03:00
path = [ panamax_ui ];
2014-12-08 12:02:57 +03:00
environment = {
2015-01-07 04:40:55 +03:00
RAILS_ENV = "production";
2014-12-08 12:02:57 +03:00
JOURNAL_ENDPOINT = cfg.journalEndpoint;
2015-01-07 04:40:55 +03:00
PMX_API_PORT_3000_TCP_ADDR = "localhost";
2014-12-08 12:02:57 +03:00
PMX_API_PORT_3000_TCP_PORT = toString cfg.APIPort;
SECRET_KEY_BASE = cfg.secretKey;
};
2015-01-07 04:40:55 +03:00
preStart = ''
mkdir -p ${cfg.dataDir}/ui/state/{log,tmp}
2015-03-18 16:12:13 +03:00
chown -R panamax:panamax ${cfg.dataDir}
2015-01-07 04:40:55 +03:00
'';
2014-12-08 12:02:57 +03:00
serviceConfig = {
2015-01-07 04:40:55 +03:00
ExecStart = "${panamax_ui}/bin/bundle exec rails server --binding 127.0.0.1 --port ${toString cfg.UIPort}";
2014-12-08 12:02:57 +03:00
User = "panamax";
Group = "panamax";
2015-03-18 16:12:13 +03:00
PermissionsStartOnly = true;
2014-12-08 12:02:57 +03:00
};
};
users.extraUsers.panamax =
{ uid = config.ids.uids.panamax;
description = "Panamax user";
createHome = true;
home = cfg.dataDir;
extraGroups = [ "docker" ];
};
services.journald.enableHttpGateway = mkDefault true;
services.fleet.enable = mkDefault true;
2015-03-18 16:12:13 +03:00
services.cadvisor.enable = mkDefault true;
services.cadvisor.port = mkDefault 3002;
2014-12-08 12:02:57 +03:00
virtualisation.docker.enable = mkDefault true;
environment.systemPackages = [ panamax_api panamax_ui ];
users.extraGroups.panamax.gid = config.ids.gids.panamax;
};
}