blob: 70acfb0155f0e95a8099b26dc57f59cc56edcf78 [file] [log] [blame]
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +09001# lib/rpc_backend
2# Interface for interactig with different rpc backend
3# rpc backend settings
4
5# Dependencies:
6# ``functions`` file
7# ``RABBIT_{HOST|PASSWORD}`` must be defined when RabbitMQ is used
8
9# ``stack.sh`` calls the entry points in this order:
10#
11# check_rpc_backend
12# install_rpc_backend
13# restart_rpc_backend
14# iniset_rpc_backend
15
16# Save trace setting
17XTRACE=$(set +o | grep xtrace)
18set +o xtrace
19
20# Entry Points
21# ------------
22
23# Make sure we only have one rpc backend enabled.
24# Also check the specified rpc backend is available on your platform.
25function check_rpc_backend() {
26 local rpc_backend_cnt=0
27 for svc in qpid zeromq rabbit; do
28 is_service_enabled $svc &&
29 ((rpc_backend_cnt++))
30 done
31 if [ "$rpc_backend_cnt" -gt 1 ]; then
32 echo "ERROR: only one rpc backend may be enabled,"
33 echo " set only one of 'rabbit', 'qpid', 'zeromq'"
34 echo " via ENABLED_SERVICES."
35 elif [ "$rpc_backend_cnt" == 0 ]; then
36 echo "ERROR: at least one rpc backend must be enabled,"
37 echo " set one of 'rabbit', 'qpid', 'zeromq'"
38 echo " via ENABLED_SERVICES."
39 fi
40
41 if is_service_enabled qpid && ! qpid_is_supported; then
42 echo "Qpid support is not available for this version of your distribution."
43 exit 1
44 fi
45}
46
47# install rpc backend
48function install_rpc_backend() {
49 if is_service_enabled rabbit; then
50 # Install rabbitmq-server
51 # the temp file is necessary due to LP: #878600
52 tfile=$(mktemp)
53 install_package rabbitmq-server > "$tfile" 2>&1
54 cat "$tfile"
55 rm -f "$tfile"
56 elif is_service_enabled qpid; then
57 if is_fedora; then
58 install_package qpid-cpp-server-daemon
59 elif is_ubuntu; then
60 install_package qpidd
Eoghan Glynn8c11f562013-03-01 12:09:01 +000061 sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf
62 sudo chmod o+r /etc/qpid/qpidd.sasldb
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090063 else
64 exit_distro_not_supported "qpid installation"
65 fi
66 elif is_service_enabled zeromq; then
67 if is_fedora; then
68 install_package zeromq python-zmq
69 elif is_ubuntu; then
70 install_package libzmq1 python-zmq
71 elif is_suse; then
72 install_package libzmq1 python-pyzmq
73 else
74 exit_distro_not_supported "zeromq installation"
75 fi
76 fi
77}
78
79# restart the rpc backend
80function restart_rpc_backend() {
81 if is_service_enabled rabbit; then
82 # Start rabbitmq-server
83 echo_summary "Starting RabbitMQ"
84 if is_fedora || is_suse; then
85 # service is not started by default
86 restart_service rabbitmq-server
87 fi
88 # change the rabbit password since the default is "guest"
89 sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
90 elif is_service_enabled qpid; then
91 echo_summary "Starting qpid"
92 restart_service qpidd
93 fi
94}
95
96# iniset cofiguration
97function iniset_rpc_backend() {
98 local package=$1
99 local file=$2
100 local section=$3
101 if is_service_enabled zeromq; then
102 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
103 elif is_service_enabled qpid; then
104 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000105 if is_ubuntu; then
106 QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1`
107 iniset $file $section qpid_password $QPID_PASSWORD
108 iniset $file $section qpid_username admin
109 fi
jiajun xu4a30b842013-01-22 11:49:03 +0800110 elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900111 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
112 iniset $file $section rabbit_host $RABBIT_HOST
113 iniset $file $section rabbit_password $RABBIT_PASSWORD
114 fi
115}
116
117# Check if qpid can be used on the current distro.
118# qpid_is_supported
119function qpid_is_supported() {
120 if [[ -z "$DISTRO" ]]; then
121 GetDistro
122 fi
123
124 # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is
125 # not in openSUSE either right now.
126 ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) )
127}
128
129# Restore xtrace
130$XTRACE