diff options
author | Jaka Hudoklin <jakahudoklin@gmail.com> | 2015-01-07 02:40:55 +0100 |
---|---|---|
committer | Matej Cotman <cotman.matej@gmail.com> | 2015-02-07 15:32:20 +0100 |
commit | ae34f923f7ff67ad9c39fa00ccf812b41426c1f1 (patch) | |
tree | 07dff84f3582fe21c3b09629e65bf1947ebca8f0 /nixos | |
parent | 8c79a2df6335d979f523b76f5f5153afe8f594bc (diff) |
panamax: simplify, refactor, add test
Diffstat (limited to 'nixos')
-rw-r--r-- | nixos/modules/services/cluster/panamax.nix | 51 | ||||
-rw-r--r-- | nixos/release.nix | 1 | ||||
-rw-r--r-- | nixos/tests/panamax.nix | 18 |
3 files changed, 60 insertions, 10 deletions
diff --git a/nixos/modules/services/cluster/panamax.nix b/nixos/modules/services/cluster/panamax.nix index 011a1e3666b4a..a7233f23c9134 100644 --- a/nixos/modules/services/cluster/panamax.nix +++ b/nixos/modules/services/cluster/panamax.nix @@ -5,8 +5,8 @@ with lib; let cfg = config.services.panamax; - panamax_api = pkgs.panamax_api.override { dataDir = cfg.dataDir+"/api"; }; - panamax_ui = pkgs.panamax_ui.override { dataDir = cfg.dataDir+"/ui"; }; + panamax_api = pkgs.panamax_api.override { dataDir = cfg.dataDir + "/api"; }; + panamax_ui = pkgs.panamax_ui.override { dataDir = cfg.dataDir + "/ui"; }; in { @@ -48,7 +48,7 @@ in { type = types.str; default = "http://127.0.0.1:4001"; description = '' - Fleetctl endpoint. + Panamax fleetctl endpoint. ''; }; @@ -56,7 +56,7 @@ in { type = types.str; default = "http://127.0.0.1:19531"; description = '' - Journal endpoint. + Panamax journal endpoint. ''; }; @@ -64,7 +64,7 @@ in { type = types.str; default = "SomethingVeryLong."; description = '' - Secret key (do change this). + Panamax secret key (do change this). ''; }; @@ -72,33 +72,64 @@ in { ##### Implementation config = mkIf cfg.enable { - systemd.services.panamax_api = { + systemd.services.panamax-api = { description = "Panamax API"; + wantedBy = [ "multi-user.target" ]; after = [ "network.target" "fleet.service" "etcd.service" "docker.service" ]; + + path = [ panamax_api ]; environment = { + RAILS_ENV = "production"; JOURNAL_ENDPOINT = cfg.journalEndpoint; FLEETCTL_ENDPOINT = cfg.fleetctlEndpoint; + PANAMAX_DATABASE_PATH = "${cfg.dataDir}/api/db/mnt/db.sqlite3"; }; - preStart = "${panamax_api}/bin/panamax-api-init"; + + 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 + ''; + serviceConfig = { - ExecStart = "${panamax_api}/bin/panamax-api-run --port ${toString cfg.APIPort}"; + ExecStart = "${panamax_api}/bin/bundle exec rails server --binding 127.0.0.1 --port ${toString cfg.APIPort}"; User = "panamax"; Group = "panamax"; }; }; - systemd.services.panamax_ui = { + systemd.services.panamax-ui = { description = "Panamax UI"; + wantedBy = [ "multi-user.target" ]; after = [ "network.target" "panamax_api.service" ]; + + path = [ panamax_ui ]; environment = { + RAILS_ENV = "production"; JOURNAL_ENDPOINT = cfg.journalEndpoint; + PMX_API_PORT_3000_TCP_ADDR = "localhost"; PMX_API_PORT_3000_TCP_PORT = toString cfg.APIPort; SECRET_KEY_BASE = cfg.secretKey; }; + + preStart = '' + rm -rf ${cfg.dataDir}/state/tmp + mkdir -p ${cfg.dataDir}/ui/state/{log,tmp} + ''; + serviceConfig = { - ExecStart = "${panamax_ui}/bin/panamax-ui-run --port ${toString cfg.UIPort}"; + ExecStart = "${panamax_ui}/bin/bundle exec rails server --binding 127.0.0.1 --port ${toString cfg.UIPort}"; User = "panamax"; Group = "panamax"; }; diff --git a/nixos/release.nix b/nixos/release.nix index ca12a03f835c4..1bd3ec5773189 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -300,6 +300,7 @@ in rec { tests.nfs3 = callTest tests/nfs.nix { version = 3; }; tests.nsd = callTest tests/nsd.nix {}; tests.openssh = callTest tests/openssh.nix {}; + tests.panamax = scrubDrv (import tests/panamax.nix { system = "x86_64-linux"; }); tests.peerflix = callTest tests/peerflix.nix {}; tests.printing = callTest tests/printing.nix {}; tests.proxy = callTest tests/proxy.nix {}; diff --git a/nixos/tests/panamax.nix b/nixos/tests/panamax.nix new file mode 100644 index 0000000000000..80af8a19be152 --- /dev/null +++ b/nixos/tests/panamax.nix @@ -0,0 +1,18 @@ +import ./make-test.nix { + name = "panamax"; + + machine = { config, pkgs, ... }: { + services.panamax.enable = true; + }; + + testScript = + '' + startAll; + $machine->waitForUnit("panamax-api.service"); + $machine->waitForUnit("panamax-ui.service"); + $machine->waitForOpenPort(3000); + $machine->waitForOpenPort(8888); + $machine->succeed("curl --fail http://localhost:8888/ > /dev/null"); + $machine->shutdown; + ''; +} |