blob: 3c485e42c77322592c8a6f323506d19b862137df [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
Dean Troyercc6b4432013-04-08 15:38:03 -050020
21# Functions
22# ---------
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090023
Matthieu Huin7a7a4662013-04-15 17:13:41 +020024
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090025# Make sure we only have one rpc backend enabled.
26# Also check the specified rpc backend is available on your platform.
27function check_rpc_backend() {
Matthieu Huin7a7a4662013-04-15 17:13:41 +020028 local rpc_needed=1
29 # We rely on the fact that filenames in lib/* match the service names
30 # that can be passed as arguments to is_service_enabled.
31 # We check for a call to iniset_rpc_backend in these files, meaning
32 # the service needs a backend.
33 rpc_candidates=$(grep -rl iniset_rpc_backend . | awk -F/ '{print $NF}')
34 for c in ${rpc_candidates}; do
35 if is_service_enabled $c; then
36 rpc_needed=0
37 break
38 fi
39 done
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090040 local rpc_backend_cnt=0
41 for svc in qpid zeromq rabbit; do
42 is_service_enabled $svc &&
43 ((rpc_backend_cnt++))
44 done
45 if [ "$rpc_backend_cnt" -gt 1 ]; then
46 echo "ERROR: only one rpc backend may be enabled,"
47 echo " set only one of 'rabbit', 'qpid', 'zeromq'"
48 echo " via ENABLED_SERVICES."
Matthieu Huin7a7a4662013-04-15 17:13:41 +020049 elif [ "$rpc_backend_cnt" == 0 ] && [ "$rpc_needed" == 0 ]; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090050 echo "ERROR: at least one rpc backend must be enabled,"
51 echo " set one of 'rabbit', 'qpid', 'zeromq'"
52 echo " via ENABLED_SERVICES."
53 fi
54
55 if is_service_enabled qpid && ! qpid_is_supported; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080056 die $LINENO "Qpid support is not available for this version of your distribution."
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090057 fi
58}
59
Dean Troyer995eb922013-03-07 16:11:40 -060060# clean up after rpc backend - eradicate all traces so changing backends
61# produces a clean switch
62function cleanup_rpc_backend {
63 if is_service_enabled rabbit; then
64 # Obliterate rabbitmq-server
65 uninstall_package rabbitmq-server
66 sudo killall epmd
67 if is_ubuntu; then
68 # And the Erlang runtime too
69 sudo aptitude purge -y ~nerlang
70 fi
71 elif is_service_enabled qpid; then
72 if is_fedora; then
Ian Wienand64dd03d2013-04-11 12:01:09 +100073 if [[ $DISTRO =~ (rhel6) ]]; then
74 uninstall_package qpid-cpp-server
75 else
76 uninstall_package qpid-cpp-server-daemon
77 fi
Dean Troyer995eb922013-03-07 16:11:40 -060078 elif is_ubuntu; then
79 uninstall_package qpidd
80 else
81 exit_distro_not_supported "qpid installation"
82 fi
83 elif is_service_enabled zeromq; then
84 if is_fedora; then
85 uninstall_package zeromq python-zmq
86 elif is_ubuntu; then
87 uninstall_package libzmq1 python-zmq
88 elif is_suse; then
89 uninstall_package libzmq1 python-pyzmq
90 else
91 exit_distro_not_supported "zeromq installation"
92 fi
93 fi
94}
95
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090096# install rpc backend
97function install_rpc_backend() {
98 if is_service_enabled rabbit; then
99 # Install rabbitmq-server
100 # the temp file is necessary due to LP: #878600
101 tfile=$(mktemp)
102 install_package rabbitmq-server > "$tfile" 2>&1
103 cat "$tfile"
104 rm -f "$tfile"
105 elif is_service_enabled qpid; then
106 if is_fedora; then
Ian Wienand64dd03d2013-04-11 12:01:09 +1000107 if [[ $DISTRO =~ (rhel6) ]]; then
108 install_package qpid-cpp-server
109
110 # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to
111 # be no or you get GSS authentication errors as it
112 # attempts to default to this.
113 sudo sed -i.bak 's/^auth=yes$/auth=no/' /etc/qpidd.conf
114 else
115 install_package qpid-cpp-server-daemon
116 fi
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900117 elif is_ubuntu; then
118 install_package qpidd
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000119 sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf
120 sudo chmod o+r /etc/qpid/qpidd.sasldb
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900121 else
122 exit_distro_not_supported "qpid installation"
123 fi
124 elif is_service_enabled zeromq; then
125 if is_fedora; then
126 install_package zeromq python-zmq
127 elif is_ubuntu; then
128 install_package libzmq1 python-zmq
129 elif is_suse; then
130 install_package libzmq1 python-pyzmq
131 else
132 exit_distro_not_supported "zeromq installation"
133 fi
134 fi
135}
136
137# restart the rpc backend
138function restart_rpc_backend() {
139 if is_service_enabled rabbit; then
140 # Start rabbitmq-server
141 echo_summary "Starting RabbitMQ"
142 if is_fedora || is_suse; then
143 # service is not started by default
144 restart_service rabbitmq-server
145 fi
146 # change the rabbit password since the default is "guest"
147 sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
148 elif is_service_enabled qpid; then
149 echo_summary "Starting qpid"
150 restart_service qpidd
151 fi
152}
153
154# iniset cofiguration
155function iniset_rpc_backend() {
156 local package=$1
157 local file=$2
158 local section=$3
159 if is_service_enabled zeromq; then
160 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
161 elif is_service_enabled qpid; then
162 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000163 if is_ubuntu; then
164 QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1`
165 iniset $file $section qpid_password $QPID_PASSWORD
166 iniset $file $section qpid_username admin
167 fi
jiajun xu4a30b842013-01-22 11:49:03 +0800168 elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900169 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
170 iniset $file $section rabbit_host $RABBIT_HOST
171 iniset $file $section rabbit_password $RABBIT_PASSWORD
172 fi
173}
174
175# Check if qpid can be used on the current distro.
176# qpid_is_supported
177function qpid_is_supported() {
178 if [[ -z "$DISTRO" ]]; then
179 GetDistro
180 fi
181
182 # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is
183 # not in openSUSE either right now.
184 ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) )
185}
186
Dean Troyercc6b4432013-04-08 15:38:03 -0500187
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900188# Restore xtrace
189$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400190
191# Local variables:
192# mode: shell-script
193# End: