forked from tutumcloud/rabbitmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_rabbitmq_password.sh
executable file
·34 lines (28 loc) · 1.01 KB
/
set_rabbitmq_password.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
if [ -f /.rabbitmq_password_set ]; then
echo "RabbitMQ password already set!"
exit 0
fi
PASS=${RABBITMQ_PASS:-$(pwgen -s 12 1)}
USER=${RABBITMQ_USER:-"admin"}
_word=$( [ ${RABBITMQ_PASS} ] && echo "preset" || echo "random" )
echo "=> Securing RabbitMQ with a ${_word} password"
cat > /etc/rabbitmq/rabbitmq.config <<EOF
[
{rabbit, [{default_user, <<"$USER">>},{default_pass, <<"$PASS">>},{tcp_listeners, [{"0.0.0.0", 5672}]}]}
].
EOF
echo "=> Done!"
touch /.rabbitmq_password_set
echo "========================================================================"
echo "You can now connect to this RabbitMQ server using, for example:"
echo ""
if [ ${_word} == "random" ]; then
echo " curl --user $USER:$PASS http://<host>:<port>/api/vhosts"
echo ""
echo "Please remember to change the above password as soon as possible!"
else
echo " curl --user $USER:<RABBITMQ_PASS> http://<host>:<port>/api/vhosts"
echo ""
fi
echo "========================================================================"