Files

22 lines
1.1 KiB
Bash
Executable File

#!/bin/sh
# Runs as a one-shot sidecar against rabbit@broker. The broker data volume is
# mounted read-only only to share the Erlang cookie; no queue data is modified.
set -eu
password=$(cat /run/secrets/broker_worker_password)
configure='^(attachments\.jobs|attachments\.process|attachments\.dlx|attachments\.process\.dlq)$'
write='^attachments\.(jobs|process|dlx|process\.dlq)$'
all_read='^attachments\.(jobs|process|dlx|process\.dlq)$'
api_read='^attachments\.(jobs|dlx)$'
if ! rabbitmqctl -n rabbit@broker -p messenger add_user messenger-worker "$password" 2>/dev/null; then
rabbitmqctl -n rabbit@broker -q -p messenger change_password messenger-worker "$password"
fi
rabbitmqctl -n rabbit@broker -q -p messenger set_permissions messenger-worker \
"$configure" "$write" "$all_read"
# The API may publish and declare the topology, but must not consume the job
# queue. The worker identity is used by the worker process.
rabbitmqctl -n rabbit@broker -q -p messenger set_permissions messenger \
"$configure" "$write" "$api_read"
echo "broker init ok: publisher and consumer identities separated"