From 227997d8cab68c3305da72cd48e425da36233936 Mon Sep 17 00:00:00 2001 From: Jaka Hudoklin Date: Mon, 10 Mar 2014 11:10:32 +0100 Subject: [PATCH] nixos/rabbitmq: rewrite - rewrite from old jobs options to new services - add simple test - add dataDir option --- nixos/modules/services/amqp/rabbitmq.nix | 71 +++++++++++------------- nixos/tests/default.nix | 1 + nixos/tests/rabbitmq.nix | 18 ++++++ 3 files changed, 52 insertions(+), 38 deletions(-) create mode 100644 nixos/tests/rabbitmq.nix diff --git a/nixos/modules/services/amqp/rabbitmq.nix b/nixos/modules/services/amqp/rabbitmq.nix index 696b5ad43797..dc1a68aefbbf 100644 --- a/nixos/modules/services/amqp/rabbitmq.nix +++ b/nixos/modules/services/amqp/rabbitmq.nix @@ -3,20 +3,11 @@ with pkgs.lib; let - cfg = config.services.rabbitmq; - run = cmd: "${pkgs.sudo}/bin/sudo -E -u rabbitmq ${cmd}"; - -in - -{ - - +in { ###### interface - options = { - services.rabbitmq = { enable = mkOption { @@ -40,55 +31,59 @@ in ''; }; - }; + dataDir = mkOption { + type = types.path; + default = "/var/lib/rabbitmq"; + description = '' + Data directory for rabbitmq. + ''; + }; + + }; }; ###### implementation - config = mkIf cfg.enable { environment.systemPackages = [ pkgs.rabbitmq_server ]; users.extraUsers.rabbitmq = { description = "RabbitMQ server user"; - home = "/var/empty"; + home = "${cfg.dataDir}"; group = "rabbitmq"; uid = config.ids.uids.rabbitmq; }; users.extraGroups.rabbitmq.gid = config.ids.gids.rabbitmq; - jobs.rabbitmq = { - description = "RabbitMQ server"; + systemd.services.rabbitmq = { + description = "RabbitMQ Server"; - startOn = "started network-interfaces"; + wantedBy = [ "multi-user.target" ]; + after = [ "network-interfaces.target" ]; - preStart = - '' - mkdir -m 0700 -p /var/lib/rabbitmq - chown rabbitmq /var/lib/rabbitmq - - mkdir -m 0700 -p /var/log/rabbitmq - chown rabbitmq /var/log/rabbitmq - ''; - - environment.HOME = "/var/lib/rabbitmq"; - environment.RABBITMQ_NODE_IP_ADDRESS = cfg.listenAddress; - environment.SYS_PREFIX = ""; - - exec = - '' - ${run "${pkgs.rabbitmq_server}/sbin/rabbitmq-server"} - ''; - - preStop = - '' - ${run "${pkgs.rabbitmq_server}/sbin/rabbitmqctl stop"} - ''; + environment = { + RABBITMQ_MNESIA_BASE = "${cfg.dataDir}/mnesia"; + RABBITMQ_NODE_IP_ADDRESS = cfg.listenAddress; + RABBITMQ_SERVER_START_ARGS = "-rabbit error_logger tty -rabbit sasl_error_logger false"; + SYS_PREFIX = ""; }; + serviceConfig = { + ExecStart = "${pkgs.rabbitmq_server}/sbin/rabbitmq-server"; + User = "rabbitmq"; + Group = "rabbitmq"; + PermissionsStartOnly = true; + }; + + preStart = '' + mkdir -p ${cfg.dataDir} && chmod 0700 ${cfg.dataDir} + if [ "$(id -u)" = 0 ]; then chown rabbitmq:rabbitmq ${cfg.dataDir}; fi + ''; + }; + }; } diff --git a/nixos/tests/default.nix b/nixos/tests/default.nix index 5b68862a2cd1..4aeb7f55ac39 100644 --- a/nixos/tests/default.nix +++ b/nixos/tests/default.nix @@ -33,6 +33,7 @@ with import ../lib/testing.nix { inherit system minimal; }; printing = makeTest (import ./printing.nix); proxy = makeTest (import ./proxy.nix); quake3 = makeTest (import ./quake3.nix); + rabbitmq = makeTest (import ./rabbitmq.nix); simple = makeTest (import ./simple.nix); #subversion = makeTest (import ./subversion.nix); tomcat = makeTest (import ./tomcat.nix); diff --git a/nixos/tests/rabbitmq.nix b/nixos/tests/rabbitmq.nix new file mode 100644 index 000000000000..271661f06820 --- /dev/null +++ b/nixos/tests/rabbitmq.nix @@ -0,0 +1,18 @@ +{ pkgs, ... }: + +# This test runs rabbitmq and checks if rabbitmq is up and running + +{ + nodes = { + one = { config, pkgs, ... }: { + services.rabbitmq.enable = true; + }; + }; + + testScript = '' + startAll; + + $one->waitForUnit("rabbitmq.service"); + $one->waitUntilSucceeds("su -s ${pkgs.stdenv.shell} rabbitmq -c \"rabbitmqctl status\""); + ''; +}