blob: 7d165a47b1e9eac56a167219abf7e792d49d4283 [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
24# Make sure we only have one rpc backend enabled.
25# Also check the specified rpc backend is available on your platform.
26function check_rpc_backend() {
27 local rpc_backend_cnt=0
28 for svc in qpid zeromq rabbit; do
29 is_service_enabled $svc &&
30 ((rpc_backend_cnt++))
31 done
32 if [ "$rpc_backend_cnt" -gt 1 ]; then
33 echo "ERROR: only one rpc backend may be enabled,"
34 echo " set only one of 'rabbit', 'qpid', 'zeromq'"
35 echo " via ENABLED_SERVICES."
36 elif [ "$rpc_backend_cnt" == 0 ]; then
37 echo "ERROR: at least one rpc backend must be enabled,"
38 echo " set one of 'rabbit', 'qpid', 'zeromq'"
39 echo " via ENABLED_SERVICES."
40 fi
41
42 if is_service_enabled qpid && ! qpid_is_supported; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080043 die $LINENO "Qpid support is not available for this version of your distribution."
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090044 fi
45}
46
Dean Troyer995eb922013-03-07 16:11:40 -060047# clean up after rpc backend - eradicate all traces so changing backends
48# produces a clean switch
49function cleanup_rpc_backend {
50 if is_service_enabled rabbit; then
51 # Obliterate rabbitmq-server
52 uninstall_package rabbitmq-server
53 sudo killall epmd
54 if is_ubuntu; then
55 # And the Erlang runtime too
56 sudo aptitude purge -y ~nerlang
57 fi
58 elif is_service_enabled qpid; then
59 if is_fedora; then
60 uninstall_package qpid-cpp-server-daemon
61 elif is_ubuntu; then
62 uninstall_package qpidd
63 else
64 exit_distro_not_supported "qpid installation"
65 fi
66 elif is_service_enabled zeromq; then
67 if is_fedora; then
68 uninstall_package zeromq python-zmq
69 elif is_ubuntu; then
70 uninstall_package libzmq1 python-zmq
71 elif is_suse; then
72 uninstall_package libzmq1 python-pyzmq
73 else
74 exit_distro_not_supported "zeromq installation"
75 fi
76 fi
77}
78
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090079# install rpc backend
80function install_rpc_backend() {
81 if is_service_enabled rabbit; then
82 # Install rabbitmq-server
83 # the temp file is necessary due to LP: #878600
84 tfile=$(mktemp)
85 install_package rabbitmq-server > "$tfile" 2>&1
86 cat "$tfile"
87 rm -f "$tfile"
88 elif is_service_enabled qpid; then
89 if is_fedora; then
90 install_package qpid-cpp-server-daemon
91 elif is_ubuntu; then
92 install_package qpidd
Eoghan Glynn8c11f562013-03-01 12:09:01 +000093 sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf
94 sudo chmod o+r /etc/qpid/qpidd.sasldb
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090095 else
96 exit_distro_not_supported "qpid installation"
97 fi
98 elif is_service_enabled zeromq; then
99 if is_fedora; then
100 install_package zeromq python-zmq
101 elif is_ubuntu; then
102 install_package libzmq1 python-zmq
103 elif is_suse; then
104 install_package libzmq1 python-pyzmq
105 else
106 exit_distro_not_supported "zeromq installation"
107 fi
108 fi
109}
110
111# restart the rpc backend
112function restart_rpc_backend() {
113 if is_service_enabled rabbit; then
114 # Start rabbitmq-server
115 echo_summary "Starting RabbitMQ"
116 if is_fedora || is_suse; then
117 # service is not started by default
118 restart_service rabbitmq-server
119 fi
120 # change the rabbit password since the default is "guest"
121 sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
122 elif is_service_enabled qpid; then
123 echo_summary "Starting qpid"
124 restart_service qpidd
125 fi
126}
127
128# iniset cofiguration
129function iniset_rpc_backend() {
130 local package=$1
131 local file=$2
132 local section=$3
133 if is_service_enabled zeromq; then
134 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
135 elif is_service_enabled qpid; then
136 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000137 if is_ubuntu; then
138 QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1`
139 iniset $file $section qpid_password $QPID_PASSWORD
140 iniset $file $section qpid_username admin
141 fi
jiajun xu4a30b842013-01-22 11:49:03 +0800142 elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900143 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
144 iniset $file $section rabbit_host $RABBIT_HOST
145 iniset $file $section rabbit_password $RABBIT_PASSWORD
146 fi
147}
148
149# Check if qpid can be used on the current distro.
150# qpid_is_supported
151function qpid_is_supported() {
152 if [[ -z "$DISTRO" ]]; then
153 GetDistro
154 fi
155
156 # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is
157 # not in openSUSE either right now.
158 ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) )
159}
160
Dean Troyercc6b4432013-04-08 15:38:03 -0500161
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900162# Restore xtrace
163$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400164
165# Local variables:
166# mode: shell-script
167# End: