blob: e64d098d3da5573ecbf0c154b882b40cd042e022 [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.
Vishvananda Ishaya78a53d92013-05-09 17:20:31 -070033 rpc_candidates=$(grep -rl iniset_rpc_backend $TOP_DIR/lib/ | awk -F/ '{print $NF}')
Matthieu Huin7a7a4662013-04-15 17:13:41 +020034 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
zhhuabj5595fdc2013-05-08 18:27:20 +080073 uninstall_package qpid-cpp-server
Dean Troyer995eb922013-03-07 16:11:40 -060074 elif is_ubuntu; then
75 uninstall_package qpidd
76 else
77 exit_distro_not_supported "qpid installation"
78 fi
79 elif is_service_enabled zeromq; then
80 if is_fedora; then
Eric Windisch800bf382013-05-24 11:21:11 -040081 uninstall_package zeromq python-zmq redis
Dean Troyer995eb922013-03-07 16:11:40 -060082 elif is_ubuntu; then
Eric Windisch800bf382013-05-24 11:21:11 -040083 uninstall_package libzmq1 python-zmq redis-server
Dean Troyer995eb922013-03-07 16:11:40 -060084 elif is_suse; then
Eric Windisch800bf382013-05-24 11:21:11 -040085 uninstall_package libzmq1 python-pyzmq redis
Dean Troyer995eb922013-03-07 16:11:40 -060086 else
87 exit_distro_not_supported "zeromq installation"
88 fi
89 fi
90}
91
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090092# install rpc backend
93function install_rpc_backend() {
94 if is_service_enabled rabbit; then
95 # Install rabbitmq-server
96 # the temp file is necessary due to LP: #878600
97 tfile=$(mktemp)
98 install_package rabbitmq-server > "$tfile" 2>&1
99 cat "$tfile"
100 rm -f "$tfile"
101 elif is_service_enabled qpid; then
102 if is_fedora; then
zhhuabj5595fdc2013-05-08 18:27:20 +0800103 install_package qpid-cpp-server
Ian Wienand64dd03d2013-04-11 12:01:09 +1000104 if [[ $DISTRO =~ (rhel6) ]]; then
Ian Wienand64dd03d2013-04-11 12:01:09 +1000105 # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to
106 # be no or you get GSS authentication errors as it
107 # attempts to default to this.
108 sudo sed -i.bak 's/^auth=yes$/auth=no/' /etc/qpidd.conf
Ian Wienand64dd03d2013-04-11 12:01:09 +1000109 fi
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900110 elif is_ubuntu; then
111 install_package qpidd
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000112 sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf
113 sudo chmod o+r /etc/qpid/qpidd.sasldb
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900114 else
115 exit_distro_not_supported "qpid installation"
116 fi
117 elif is_service_enabled zeromq; then
Eric Windisch800bf382013-05-24 11:21:11 -0400118 # NOTE(ewindisch): Redis is not strictly necessary
119 # but there is a matchmaker driver that works
120 # really well & out of the box for multi-node.
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900121 if is_fedora; then
Eric Windisch800bf382013-05-24 11:21:11 -0400122 install_package zeromq python-zmq redis
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900123 elif is_ubuntu; then
Eric Windisch800bf382013-05-24 11:21:11 -0400124 install_package libzmq1 python-zmq redis-server
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900125 elif is_suse; then
Eric Windisch800bf382013-05-24 11:21:11 -0400126 install_package libzmq1 python-pyzmq redis
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900127 else
128 exit_distro_not_supported "zeromq installation"
129 fi
130 fi
131}
132
133# restart the rpc backend
134function restart_rpc_backend() {
135 if is_service_enabled rabbit; then
136 # Start rabbitmq-server
137 echo_summary "Starting RabbitMQ"
138 if is_fedora || is_suse; then
139 # service is not started by default
140 restart_service rabbitmq-server
141 fi
142 # change the rabbit password since the default is "guest"
143 sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000144 if is_service_enabled n-cell; then
145 # Add partitioned access for the child cell
146 if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then
147 sudo rabbitmqctl add_vhost child_cell
148 sudo rabbitmqctl set_permissions -p child_cell guest ".*" ".*" ".*"
149 fi
150 fi
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900151 elif is_service_enabled qpid; then
152 echo_summary "Starting qpid"
153 restart_service qpidd
154 fi
155}
156
157# iniset cofiguration
158function iniset_rpc_backend() {
159 local package=$1
160 local file=$2
161 local section=$3
162 if is_service_enabled zeromq; then
163 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
Eric Windisch800bf382013-05-24 11:21:11 -0400164 iniset $file $section rpc_zmq_matchmaker \
165 ${package}.openstack.common.rpc.matchmaker_redis.MatchMakerRedis
166 # Set MATCHMAKER_REDIS_HOST if running multi-node.
167 MATCHMAKER_REDIS_HOST=${MATCHMAKER_REDIS_HOST:-127.0.0.1}
168 iniset $file matchmaker_redis host $MATCHMAKER_REDIS_HOST
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900169 elif is_service_enabled qpid; then
170 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000171 if is_ubuntu; then
172 QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1`
173 iniset $file $section qpid_password $QPID_PASSWORD
174 iniset $file $section qpid_username admin
175 fi
jiajun xu4a30b842013-01-22 11:49:03 +0800176 elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900177 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
178 iniset $file $section rabbit_host $RABBIT_HOST
179 iniset $file $section rabbit_password $RABBIT_PASSWORD
180 fi
181}
182
183# Check if qpid can be used on the current distro.
184# qpid_is_supported
185function qpid_is_supported() {
186 if [[ -z "$DISTRO" ]]; then
187 GetDistro
188 fi
189
190 # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is
191 # not in openSUSE either right now.
192 ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) )
193}
194
Dean Troyercc6b4432013-04-08 15:38:03 -0500195
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900196# Restore xtrace
197$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400198
199# Local variables:
200# mode: shell-script
201# End: