diff options
| author | wrobell <wrobell@riseup.net> | 2026-06-14 17:57:57 +0100 |
|---|---|---|
| committer | Sharlatan Hellseher <sharlatanus@gmail.com> | 2026-06-28 23:38:21 +0100 |
| commit | bfb35abf16bb4aa52b143dd1eb31ddef16898b37 (patch) | |
| tree | 7cf18943cc25ccde62a98cd0c81d1e0e11d62e4a | |
| parent | 2983d36030ba74037667b28012c76d4bf35e459f (diff) | |
services: Update rabbitmq service
Update RabbitMQ default configuration to use localhost interface by
default and avoid listening on public interfaces.
Change the default configuration file to set inter-node communication
listener to localhost network interface (see also
https://www.rabbitmq.com/docs/networking#distribution). This requires
setting RabbitMQ node name to `rabbit@localhost`, so introduce
`node-name` RabbitMQ configuration field with such default value.
Path to the RabbitMQ environment configuration file was hardcoded.
Remove the hardcoding and allow to create such file with env-config-file
RabbitMQ configuration field.
Add new RabbitMQ service tests to check RabbitMQ broker startup and
status after the service is started.
* gnu/services/high-availability.scm (<rabbitmq-configuration>)
[<node-name>, <env-config-file>]: New fields.
(rabbitmq-shepherd-service): Use them.
(%default-rabbitmq-config-file): Update.
* gnu/tests/high-availability.scm (run-rabbitmq-test): Add new tests.
* doc/gnu.texi (High Availability Services): Document new fields and
provide information about local interfaces.
Merges: guix/guix!9360
Signed-off-by: Sharlatan Hellseher <sharlatanus@gmail.com>
| -rw-r--r-- | doc/guix.texi | 30 | ||||
| -rw-r--r-- | gnu/services/high-availability.scm | 23 | ||||
| -rw-r--r-- | gnu/tests/high-availability.scm | 31 |
3 files changed, 68 insertions, 16 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index c349ffc6d33..7f587d73a9a 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -143,7 +143,7 @@ Copyright @copyright{} 2025 Zacchaeus@* | |||
| 143 | Copyright @copyright{} 2025, 2026 Sergio Pastor Pérez@* | 143 | Copyright @copyright{} 2025, 2026 Sergio Pastor Pérez@* |
| 144 | Copyright @copyright{} 2024 Evgeny Pisemsky@* | 144 | Copyright @copyright{} 2024 Evgeny Pisemsky@* |
| 145 | Copyright @copyright{} 2025 jgart@* | 145 | Copyright @copyright{} 2025 jgart@* |
| 146 | Copyright @copyright{} 2025 Artur Wroblewski@* | 146 | Copyright @copyright{} 2025-2026 Artur Wroblewski@* |
| 147 | Copyright @copyright{} 2025 Edouard Klein@* | 147 | Copyright @copyright{} 2025 Edouard Klein@* |
| 148 | Copyright @copyright{} 2025 Rodion Goritskov@* | 148 | Copyright @copyright{} 2025 Rodion Goritskov@* |
| 149 | Copyright @copyright{} 2025 dan@* | 149 | Copyright @copyright{} 2025 dan@* |
| @@ -37654,24 +37654,24 @@ A simple example configuration is given below. | |||
| 37654 | @lisp | 37654 | @lisp |
| 37655 | (service rabbitmq-service-type | 37655 | (service rabbitmq-service-type |
| 37656 | (rabbitmq-configuration | 37656 | (rabbitmq-configuration |
| 37657 | (rabbitmq-configuration | 37657 | (plugins '("rabbitmq_stream" |
| 37658 | (plugins '("rabbitmq_stream" | 37658 | "rabbitmq_management" |
| 37659 | "rabbitmq_management" | 37659 | "rabbitmq_prometheus")))) |
| 37660 | "rabbitmq_prometheus"))))) | ||
| 37661 | @end lisp | 37660 | @end lisp |
| 37662 | @end defvar | ||
| 37663 | 37661 | ||
| 37664 | At startup, RabbitMQ broker logs its initialization messages into | 37662 | At startup, RabbitMQ broker logs its initialization messages into |
| 37665 | @file{/var/log/messages} file. Once running, the logging messages can be | 37663 | @file{/var/log/messages} file. Once running, the logging messages can be |
| 37666 | found in a logging file of a RabbitMQ node in @file{/var/log/rabbitmq} | 37664 | found in a logging file of a RabbitMQ node in @file{/var/log/rabbitmq} |
| 37667 | directory. | 37665 | directory. |
| 37668 | 37666 | ||
| 37669 | @quotation Note | 37667 | @quotation Warning |
| 37670 | The default configuration of the RabbitMQ service enables the RabbitMQ | 37668 | The default configuration of the RabbitMQ service enables the RabbitMQ |
| 37671 | broker to accept connections only on loopback interfaces. However, | 37669 | broker to accept connections only on loopback interfaces. However, |
| 37672 | enabling certain plugins may open ports on all network interfaces. See | 37670 | enabling certain plugins may open ports on all network interfaces. See |
| 37673 | also @url{https://www.rabbitmq.com/docs/networking#ports, RabbitMQ Port Access}. | 37671 | also @url{https://www.rabbitmq.com/docs/networking#ports, RabbitMQ Port |
| 37672 | Access}. | ||
| 37674 | @end quotation | 37673 | @end quotation |
| 37674 | @end defvar | ||
| 37675 | 37675 | ||
| 37676 | @deftp {Data Type} rabbitmq-configuration | 37676 | @deftp {Data Type} rabbitmq-configuration |
| 37677 | This data type represents the configuration for RabbitMQ. | 37677 | This data type represents the configuration for RabbitMQ. |
| @@ -37680,10 +37680,23 @@ This data type represents the configuration for RabbitMQ. | |||
| 37680 | @item @code{rabbitmq} (default: @code{rabbitmq}) | 37680 | @item @code{rabbitmq} (default: @code{rabbitmq}) |
| 37681 | The RabbitMQ package to use. | 37681 | The RabbitMQ package to use. |
| 37682 | 37682 | ||
| 37683 | @item @code{node-name} (default: @code{"rabbit@@localhost"}) | ||
| 37684 | Node name of a RabbitMQ broker instance. See also | ||
| 37685 | @url{https://www.rabbitmq.com/docs/clustering#node-names, RabbitMQ Node | ||
| 37686 | Names}. | ||
| 37687 | |||
| 37683 | @item @code{config-file} (default: @code{%default-rabbitmq-config-file}) | 37688 | @item @code{config-file} (default: @code{%default-rabbitmq-config-file}) |
| 37684 | Configuration file for the RabbitMQ broker. See also | 37689 | Configuration file for the RabbitMQ broker. See also |
| 37685 | @url{https://www.rabbitmq.com/docs/configure, RabbitMQ Configuration}. | 37690 | @url{https://www.rabbitmq.com/docs/configure, RabbitMQ Configuration}. |
| 37686 | 37691 | ||
| 37692 | @item @code{env-config-file} (default: @code{#f}) | ||
| 37693 | Environment configuration file for the RabbitMQ broker. | ||
| 37694 | |||
| 37695 | Set RabbitMQ environment variables, for example Erlang parameters, node | ||
| 37696 | name, or configuration file location, using @code{variable=value} format. | ||
| 37697 | Each variable name without @code{RABBITMQ_} prefix. See also | ||
| 37698 | @url{https://www.rabbitmq.com/docs/configure, RabbitMQ Configuration}. | ||
| 37699 | |||
| 37687 | @item @code{data-directory} (default: @code{"/var/lib/rabbitmq/data"}) | 37700 | @item @code{data-directory} (default: @code{"/var/lib/rabbitmq/data"}) |
| 37688 | Directory with RabbitMQ broker data - a schema database, message stores, | 37701 | Directory with RabbitMQ broker data - a schema database, message stores, |
| 37689 | cluster member information, and other persistent node state. | 37702 | cluster member information, and other persistent node state. |
| @@ -37691,7 +37704,6 @@ cluster member information, and other persistent node state. | |||
| 37691 | @item @code{plugins} (default: @code{'()}) | 37704 | @item @code{plugins} (default: @code{'()}) |
| 37692 | A list of RabbitMQ plugins to enable. View all available plugins using | 37705 | A list of RabbitMQ plugins to enable. View all available plugins using |
| 37693 | the @command{rabbitmq-plugins list} command. | 37706 | the @command{rabbitmq-plugins list} command. |
| 37694 | |||
| 37695 | @end table | 37707 | @end table |
| 37696 | @end deftp | 37708 | @end deftp |
| 37697 | 37709 | ||
diff --git a/gnu/services/high-availability.scm b/gnu/services/high-availability.scm index 7b57d9a613e..73d534cf020 100644 --- a/gnu/services/high-availability.scm +++ b/gnu/services/high-availability.scm | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2018 Christopher Baines <mail@cbaines.net> | 2 | ;;; Copyright © 2018 Christopher Baines <mail@cbaines.net> |
| 3 | ;;; Copyright © 2025 Artur Wroblewski <wrobell@riseup.net> | 3 | ;;; Copyright © 2025-2026 Artur Wroblewski <wrobell@riseup.net> |
| 4 | ;;; Copyright © 2026 Mathieu Lirzin <mthl@gnu.org> | 4 | ;;; Copyright © 2026 Mathieu Lirzin <mthl@gnu.org> |
| 5 | ;;; | 5 | ;;; |
| 6 | ;;; This file is part of GNU Guix. | 6 | ;;; This file is part of GNU Guix. |
| @@ -32,19 +32,25 @@ | |||
| 32 | 32 | ||
| 33 | #:export (rabbitmq-configuration rabbitmq-configuration? | 33 | #:export (rabbitmq-configuration rabbitmq-configuration? |
| 34 | rabbitmq-configuration-rabbitmq | 34 | rabbitmq-configuration-rabbitmq |
| 35 | rabbitmq-configuration-node-name | ||
| 35 | rabbitmq-configuration-config-file | 36 | rabbitmq-configuration-config-file |
| 37 | rabbitmq-configuration-env-config-file | ||
| 36 | rabbitmq-configuration-plugins | 38 | rabbitmq-configuration-plugins |
| 37 | rabbitmq-service-type)) | 39 | rabbitmq-service-type)) |
| 38 | 40 | ||
| 39 | ;; By default, start on local ipv4 and ipv6 interfaces only, see also: | 41 | ;; By default, start messaging and inter-node RabbitMQ listeners on local |
| 42 | ;; interfaces only, see also: | ||
| 40 | ;; | 43 | ;; |
| 41 | ;; https://www.rabbitmq.com/docs/networking | 44 | ;; https://www.rabbitmq.com/docs/networking |
| 42 | ;; | 45 | ;; |
| 43 | ;; NOTE: How to enable plugins to listen on localhost only? | 46 | ;; NOTE: Enabling a RabbitMQ plugin will make it usually listen on a public |
| 47 | ;; interface. | ||
| 44 | (define %default-rabbitmq-config-file | 48 | (define %default-rabbitmq-config-file |
| 45 | (plain-file "rabbitmq.conf" " | 49 | (plain-file "rabbitmq.conf" " |
| 46 | listeners.tcp.1 = 127.0.0.1:5672 | 50 | listeners.tcp.1 = 127.0.0.1:5672 |
| 47 | listeners.tcp.2 = ::1:5672 | 51 | listeners.tcp.2 = ::1:5672 |
| 52 | |||
| 53 | distribution.listener.interface = 127.0.0.1 | ||
| 48 | ")) | 54 | ")) |
| 49 | 55 | ||
| 50 | (define-record-type* <rabbitmq-configuration> rabbitmq-configuration | 56 | (define-record-type* <rabbitmq-configuration> rabbitmq-configuration |
| @@ -52,8 +58,11 @@ listeners.tcp.2 = ::1:5672 | |||
| 52 | rabbitmq-configuration? | 58 | rabbitmq-configuration? |
| 53 | (rabbitmq rabbitmq-configuration-rabbitmq | 59 | (rabbitmq rabbitmq-configuration-rabbitmq |
| 54 | (default rabbitmq)) | 60 | (default rabbitmq)) |
| 61 | (node-name rabbitmq-configuration-node-name | ||
| 62 | (default "rabbit@localhost")) | ||
| 55 | (config-file rabbitmq-configuration-config-file | 63 | (config-file rabbitmq-configuration-config-file |
| 56 | (default %default-rabbitmq-config-file)) | 64 | (default %default-rabbitmq-config-file)) |
| 65 | (env-config-file rabbitmq-configuration-env-file (default #f)) | ||
| 57 | ;; It can be a mnesia database or a khepri database, so use "data" instead | 66 | ;; It can be a mnesia database or a khepri database, so use "data" instead |
| 58 | ;; of the traditional "mnesia". | 67 | ;; of the traditional "mnesia". |
| 59 | (data-directory rabbitmq-configuration-data-directory | 68 | (data-directory rabbitmq-configuration-data-directory |
| @@ -102,7 +111,7 @@ listeners.tcp.2 = ::1:5672 | |||
| 102 | 111 | ||
| 103 | (define (rabbitmq-shepherd-service config) | 112 | (define (rabbitmq-shepherd-service config) |
| 104 | (match-record config <rabbitmq-configuration> | 113 | (match-record config <rabbitmq-configuration> |
| 105 | (rabbitmq data-directory config-file plugins) | 114 | (rabbitmq node-name data-directory config-file env-config-file plugins) |
| 106 | (with-imported-modules | 115 | (with-imported-modules |
| 107 | (source-module-closure '((gnu build shepherd))) | 116 | (source-module-closure '((gnu build shepherd))) |
| 108 | (list | 117 | (list |
| @@ -119,10 +128,14 @@ listeners.tcp.2 = ::1:5672 | |||
| 119 | #:group "rabbitmq" | 128 | #:group "rabbitmq" |
| 120 | #:environment-variables | 129 | #:environment-variables |
| 121 | (append | 130 | (append |
| 131 | (if #$env-config-file | ||
| 132 | (list (string-append "RABBITMQ_CONF_ENV_FILE=" | ||
| 133 | #$env-config-file)) | ||
| 134 | (list)) | ||
| 122 | (list | 135 | (list |
| 136 | (string-append "RABBITMQ_NODENAME=" #$node-name) | ||
| 123 | (string-append "RABBITMQ_CONFIG_FILE=" #$config-file) | 137 | (string-append "RABBITMQ_CONFIG_FILE=" #$config-file) |
| 124 | "RABBITMQ_PID_FILE=/var/run/rabbitmq/pid" | 138 | "RABBITMQ_PID_FILE=/var/run/rabbitmq/pid" |
| 125 | "RABBITMQ_CONF_ENV_FILE=/run/current-system/profile/etc/rabbitmq/rabbitmq-env.conf" | ||
| 126 | (string-append | 139 | (string-append |
| 127 | "RABBITMQ_ENABLED_PLUGINS_FILE=" | 140 | "RABBITMQ_ENABLED_PLUGINS_FILE=" |
| 128 | #$data-directory | 141 | #$data-directory |
diff --git a/gnu/tests/high-availability.scm b/gnu/tests/high-availability.scm index 591e5f5bc23..6eb13d1a068 100644 --- a/gnu/tests/high-availability.scm +++ b/gnu/tests/high-availability.scm | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net> | 2 | ;;; Copyright © 2017 Christopher Baines <mail@cbaines.net> |
| 3 | ;;; Copyright © 2025 Artur Wroblewski <wrobell@riseup.net> | 3 | ;;; Copyright © 2025-2026 Artur Wroblewski <wrobell@riseup.net> |
| 4 | ;;; | 4 | ;;; |
| 5 | ;;; This file is part of GNU Guix. | 5 | ;;; This file is part of GNU Guix. |
| 6 | ;;; | 6 | ;;; |
| @@ -19,6 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | (define-module (gnu tests high-availability) | 20 | (define-module (gnu tests high-availability) |
| 21 | #:use-module (gnu tests) | 21 | #:use-module (gnu tests) |
| 22 | #:use-module (gnu packages high-availability) | ||
| 22 | #:use-module (gnu system) | 23 | #:use-module (gnu system) |
| 23 | #:use-module (gnu system file-systems) | 24 | #:use-module (gnu system file-systems) |
| 24 | #:use-module (gnu system shadow) | 25 | #:use-module (gnu system shadow) |
| @@ -34,12 +35,15 @@ | |||
| 34 | (plain-file "rabbitmq.conf" " | 35 | (plain-file "rabbitmq.conf" " |
| 35 | listeners.tcp.1 = 127.0.0.1:15672 | 36 | listeners.tcp.1 = 127.0.0.1:15672 |
| 36 | listeners.tcp.2 = ::1:15672 | 37 | listeners.tcp.2 = ::1:15672 |
| 38 | |||
| 39 | distribution.listener.interface = 127.0.0.1 | ||
| 37 | ")) | 40 | ")) |
| 38 | 41 | ||
| 39 | (define %rabbitmq-os | 42 | (define %rabbitmq-os |
| 40 | (simple-operating-system | 43 | (simple-operating-system |
| 41 | (service rabbitmq-service-type | 44 | (service rabbitmq-service-type |
| 42 | (rabbitmq-configuration (config-file %rabbitmq-config-file))))) | 45 | (rabbitmq-configuration (node-name "rabbit@komputilo") |
| 46 | (config-file %rabbitmq-config-file))))) | ||
| 43 | 47 | ||
| 44 | (define* (run-rabbitmq-test #:key (rabbitmq-port 15672)) | 48 | (define* (run-rabbitmq-test #:key (rabbitmq-port 15672)) |
| 45 | "Run tests in %RABBITMQ-OS, forwarding PORT." | 49 | "Run tests in %RABBITMQ-OS, forwarding PORT." |
| @@ -94,6 +98,29 @@ listeners.tcp.2 = ::1:15672 | |||
| 94 | '(file-exists? "/var/log/rabbitmq/rabbit@komputilo.log") | 98 | '(file-exists? "/var/log/rabbitmq/rabbit@komputilo.log") |
| 95 | marionette)) | 99 | marionette)) |
| 96 | 100 | ||
| 101 | (test-assert "RabbitMQ await startup command is successful" | ||
| 102 | (marionette-eval | ||
| 103 | '(begin | ||
| 104 | (use-modules (guix build utils)) | ||
| 105 | |||
| 106 | (current-output-port (open-file "/dev/console" "w0")) | ||
| 107 | (invoke #$(file-append rabbitmq "/sbin/rabbitmqctl") | ||
| 108 | "await_startup" | ||
| 109 | "-n" | ||
| 110 | "rabbit@komputilo")) | ||
| 111 | marionette)) | ||
| 112 | |||
| 113 | (test-assert "RabbitMQ status command is successful" | ||
| 114 | (marionette-eval | ||
| 115 | '(begin | ||
| 116 | (use-modules (guix build utils)) | ||
| 117 | |||
| 118 | (current-output-port (open-file "/dev/console" "w0")) | ||
| 119 | (invoke #$(file-append rabbitmq "/sbin/rabbitmqctl") | ||
| 120 | "status" | ||
| 121 | "-n" | ||
| 122 | "rabbit@komputilo")) | ||
| 123 | marionette)) | ||
| 97 | (test-end)))) | 124 | (test-end)))) |
| 98 | 125 | ||
| 99 | (gexp->derivation "rabbitmq-test" test)) | 126 | (gexp->derivation "rabbitmq-test" test)) |
