Skip to content

Commit

Permalink
feat(cluster): join state with erlang_cookie
Browse files Browse the repository at this point in the history
  • Loading branch information
noelmcloughlin committed Jun 5, 2021
1 parent ad7591f commit ce0fcb8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
10 changes: 8 additions & 2 deletions docs/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ now ``pre-commit`` will run automatically on each ``git commit``. ::
Special notes
-------------

None
The main state ``rabbitmq`` excludes ``rabbitmq.config.cluster`` (initial cluster setup) state.

Available states
----------------
Expand Down Expand Up @@ -99,7 +99,13 @@ This state will install the rabbitmqadmin package only.
^^^^^^^^^^^^^^^^^^^

This state will configure the rabbitmq service and has a dependency on ``rabbitmq.install``
via include list. See ``pillar.example``.
via include list. It excludes ``rabbitmq.config.cluster`` state

``rabbitmq.config.cluster``
^^^^^^^^^^^^^^^^^^^^^^^^^

For initial setup this state writes the erlang cookie, joins cluster, and restarts service.
The erlang cookie comes from pillar data and must the identical for all cluster members

``rabbitmq.service``
^^^^^^^^^^^^^^^^^^^^
Expand Down
18 changes: 10 additions & 8 deletions pillar.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
# vim: ft=yaml
---
rabbitmq:
cluster:
rabbitmq@locahost:
user: rabbitmq
host: rabbitmq # short hostname of node to join to, not fqdn
ram_node: None
runas: rabbitmq
erlang_cookie:
name: /var/lib/rabbitmq/.erlang_cookie
value: shared-value-for-all-cluster-members

pkg:
# https://github.com/rabbitmq/rabbitmq-server/releases/tag/v3.8.14
use_upstream: repo # if available (i.e. packagecloud)
service:
enabled: true
running: true

config:
# see rabbitmq.conf.example from rabbitmq-server github docs
context: {}
Expand Down Expand Up @@ -59,13 +68,6 @@ rabbitmq:
- 'alternate-**exchange': 'amq.fanout'
- 'test-header': 'testing'

cluster:
rabbit@locahost:
- user: rabbit
- host: localhost
- ram_node: None
- runas: root

plugin:
rabbitmq_management:
runas: root
Expand Down
31 changes: 24 additions & 7 deletions rabbitmq/config/cluster/install.sls
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,32 @@ include:
- {{ sls_service_running }}
- {{ sls_config_user }}
{% for name, cluster in salt["pillar.get"]("rabbitmq:cluster", {}).items() %}
{%- for name, cluster in salt["pillar.get"]("rabbitmq:cluster", {}).items() %}
{%- if 'erlang_cookie' in cluster and cluster.erlang_cookie is mapping %}
rabbitmq-config-cluster-join-{{ name }}:
rabbitmq_cluster.join:
{% for value in cluster %}
- {{ value | json }}
{% endfor %}
file.managed:
- name: {{ cluster.erlang_cookie.name }}
- contents: {{ cluster.erlang_cookie.value }}
- mode: 400
- user: {{ cluster.user }}
- group: root
- makedirs: True
- watch_in:
- service: rabbitmq-service-running-service-running
{%- if 'host' in grains and grains.host not in cluster.host %}
rabbitmq_cluster.joined:
- user: {{ cluster.user }}
- host: {{ cluster.host }}
- ram_node: {{ cluster.ram_node }}
- runas: {{ cluster.runas }}
- require:
- service: {{ rabbitmq.service.name }}
- file: rabbitmq-config-cluster-join-{{ name }}
- sls: {{ sls_config_user }}
- service: rabbitmq-service-running-service-running
{% endfor %}
{%- endif %}
{%- endif %}
{%- endfor %}
2 changes: 1 addition & 1 deletion rabbitmq/config/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ include:
- .policy
- .plugin
- .upstream
# .cluster
# .cluster should be run once, not always
1 change: 0 additions & 1 deletion rabbitmq/package/repo/clean.sls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ rabbitmq-package-repo-erlang-clean:
pkgrepo.absent:
- names:
- rabbitmq-rabbitmq-erlang
- rabbitmq_rabbitmq-erlang
- rabbitmq-rabbitmq
- rabbitmq_rabbitmq-server
- deb https://dl.bintray.com/rabbitmq-erlang/debian {{ salt['grains.get']('oscodename') }} erlang
Expand Down
11 changes: 2 additions & 9 deletions rabbitmq/service/running.sls
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,8 @@ rabbitmq-service-running-service-running:
- enable: True
- watch:
- sls: {{ sls_config_file }}
- onfail_in:
- cmd: rabbitmq-service-running-service-running
cmd.run:
- names:
- localectl || true
- journalctl -xe -u {{ rabbitmq.service.name }} || true
- systemctl status {{ rabbitmq.service.name }} || true
- systemd-analyze blame || true
- hostname
- hostname -s
- hostname -A
- ip addr
- onfail:
- service: rabbitmq-service-running-service-running

0 comments on commit ce0fcb8

Please sign in to comment.