blob: 38da50c4f862d7cb4a6a6fa46868a11e51281aef [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:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01006#
7# - ``functions`` file
8# - ``RABBIT_{HOST|PASSWORD}`` must be defined when RabbitMQ is used
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +09009
10# ``stack.sh`` calls the entry points in this order:
11#
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010012# - check_rpc_backend
13# - install_rpc_backend
14# - restart_rpc_backend
15# - iniset_rpc_backend
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090016
17# Save trace setting
18XTRACE=$(set +o | grep xtrace)
19set +o xtrace
20
Dean Troyercc6b4432013-04-08 15:38:03 -050021
22# Functions
23# ---------
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090024
Matthieu Huin7a7a4662013-04-15 17:13:41 +020025
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090026# Make sure we only have one rpc backend enabled.
27# Also check the specified rpc backend is available on your platform.
Ian Wienandaee18c72014-02-21 15:35:08 +110028function check_rpc_backend {
Dean Troyer3ef23bc2014-07-25 14:56:22 -050029 local c svc
30
Matthieu Huin7a7a4662013-04-15 17:13:41 +020031 local rpc_needed=1
32 # We rely on the fact that filenames in lib/* match the service names
33 # that can be passed as arguments to is_service_enabled.
34 # We check for a call to iniset_rpc_backend in these files, meaning
35 # the service needs a backend.
Vishvananda Ishaya78a53d92013-05-09 17:20:31 -070036 rpc_candidates=$(grep -rl iniset_rpc_backend $TOP_DIR/lib/ | awk -F/ '{print $NF}')
Matthieu Huin7a7a4662013-04-15 17:13:41 +020037 for c in ${rpc_candidates}; do
38 if is_service_enabled $c; then
39 rpc_needed=0
40 break
41 fi
42 done
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090043 local rpc_backend_cnt=0
44 for svc in qpid zeromq rabbit; do
45 is_service_enabled $svc &&
46 ((rpc_backend_cnt++))
47 done
48 if [ "$rpc_backend_cnt" -gt 1 ]; then
49 echo "ERROR: only one rpc backend may be enabled,"
50 echo " set only one of 'rabbit', 'qpid', 'zeromq'"
51 echo " via ENABLED_SERVICES."
Matthieu Huin7a7a4662013-04-15 17:13:41 +020052 elif [ "$rpc_backend_cnt" == 0 ] && [ "$rpc_needed" == 0 ]; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090053 echo "ERROR: at least one rpc backend must be enabled,"
54 echo " set one of 'rabbit', 'qpid', 'zeromq'"
55 echo " via ENABLED_SERVICES."
56 fi
57
58 if is_service_enabled qpid && ! qpid_is_supported; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080059 die $LINENO "Qpid support is not available for this version of your distribution."
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090060 fi
61}
62
Dean Troyer995eb922013-03-07 16:11:40 -060063# clean up after rpc backend - eradicate all traces so changing backends
64# produces a clean switch
65function cleanup_rpc_backend {
66 if is_service_enabled rabbit; then
67 # Obliterate rabbitmq-server
68 uninstall_package rabbitmq-server
DennyZhang557744f2013-10-14 09:50:13 -050069 sudo killall epmd || sudo killall -9 epmd
Dean Troyer995eb922013-03-07 16:11:40 -060070 if is_ubuntu; then
71 # And the Erlang runtime too
Sahid Orentino Ferdjaouie9648272014-02-23 18:55:51 +010072 apt_get purge -y erlang*
Dean Troyer995eb922013-03-07 16:11:40 -060073 fi
74 elif is_service_enabled qpid; then
75 if is_fedora; then
zhhuabj5595fdc2013-05-08 18:27:20 +080076 uninstall_package qpid-cpp-server
Dean Troyer995eb922013-03-07 16:11:40 -060077 elif is_ubuntu; then
78 uninstall_package qpidd
79 else
80 exit_distro_not_supported "qpid installation"
81 fi
82 elif is_service_enabled zeromq; then
83 if is_fedora; then
Eric Windisch800bf382013-05-24 11:21:11 -040084 uninstall_package zeromq python-zmq redis
Dean Troyer995eb922013-03-07 16:11:40 -060085 elif is_ubuntu; then
Eric Windisch800bf382013-05-24 11:21:11 -040086 uninstall_package libzmq1 python-zmq redis-server
Dean Troyer995eb922013-03-07 16:11:40 -060087 elif is_suse; then
Eric Windisch800bf382013-05-24 11:21:11 -040088 uninstall_package libzmq1 python-pyzmq redis
Dean Troyer995eb922013-03-07 16:11:40 -060089 else
90 exit_distro_not_supported "zeromq installation"
91 fi
92 fi
93}
94
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090095# install rpc backend
Ian Wienandaee18c72014-02-21 15:35:08 +110096function install_rpc_backend {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090097 if is_service_enabled rabbit; then
98 # Install rabbitmq-server
Ian Wienand7ccf4e02014-07-23 14:24:11 +100099 install_package rabbitmq-server
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900100 elif is_service_enabled qpid; then
101 if is_fedora; then
zhhuabj5595fdc2013-05-08 18:27:20 +0800102 install_package qpid-cpp-server
Ian Wienand64dd03d2013-04-11 12:01:09 +1000103 if [[ $DISTRO =~ (rhel6) ]]; then
Sean Dague101b4242013-10-22 08:47:11 -0400104 # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to
105 # be no or you get GSS authentication errors as it
106 # attempts to default to this.
Ian Wienand64dd03d2013-04-11 12:01:09 +1000107 sudo sed -i.bak 's/^auth=yes$/auth=no/' /etc/qpidd.conf
Ian Wienand64dd03d2013-04-11 12:01:09 +1000108 fi
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900109 elif is_ubuntu; then
110 install_package qpidd
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000111 sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf
112 sudo chmod o+r /etc/qpid/qpidd.sasldb
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900113 else
114 exit_distro_not_supported "qpid installation"
115 fi
116 elif is_service_enabled zeromq; then
Eric Windisch800bf382013-05-24 11:21:11 -0400117 # NOTE(ewindisch): Redis is not strictly necessary
118 # but there is a matchmaker driver that works
119 # really well & out of the box for multi-node.
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900120 if is_fedora; then
Eric Windisch800bf382013-05-24 11:21:11 -0400121 install_package zeromq python-zmq redis
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900122 elif is_ubuntu; then
Eric Windisch800bf382013-05-24 11:21:11 -0400123 install_package libzmq1 python-zmq redis-server
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900124 elif is_suse; then
Eric Windisch800bf382013-05-24 11:21:11 -0400125 install_package libzmq1 python-pyzmq redis
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900126 else
127 exit_distro_not_supported "zeromq installation"
128 fi
Vincent Hou93a7a502013-09-27 06:16:54 -0400129 # Necessary directory for socket location.
130 sudo mkdir -p /var/run/openstack
131 sudo chown $STACK_USER /var/run/openstack
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900132 fi
133}
134
135# restart the rpc backend
Ian Wienandaee18c72014-02-21 15:35:08 +1100136function restart_rpc_backend {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900137 if is_service_enabled rabbit; then
138 # Start rabbitmq-server
139 echo_summary "Starting RabbitMQ"
Ben Nemecec5918f2014-01-30 16:07:23 +0000140 # NOTE(bnemec): Retry initial rabbitmq configuration to deal with
141 # the fact that sometimes it fails to start properly.
142 # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028
Dean Troyer3ef23bc2014-07-25 14:56:22 -0500143 local i
Ben Nemecec5918f2014-01-30 16:07:23 +0000144 for i in `seq 10`; do
145 if is_fedora || is_suse; then
146 # service is not started by default
147 restart_service rabbitmq-server
148 fi
149 # change the rabbit password since the default is "guest"
150 sudo rabbitmqctl change_password guest $RABBIT_PASSWORD && break
151 [[ $i -eq "10" ]] && die $LINENO "Failed to set rabbitmq password"
152 done
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000153 if is_service_enabled n-cell; then
154 # Add partitioned access for the child cell
155 if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then
156 sudo rabbitmqctl add_vhost child_cell
157 sudo rabbitmqctl set_permissions -p child_cell guest ".*" ".*" ".*"
158 fi
159 fi
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900160 elif is_service_enabled qpid; then
161 echo_summary "Starting qpid"
162 restart_service qpidd
163 fi
164}
165
166# iniset cofiguration
Ian Wienandaee18c72014-02-21 15:35:08 +1100167function iniset_rpc_backend {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900168 local package=$1
169 local file=$2
170 local section=$3
171 if is_service_enabled zeromq; then
172 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
Eric Windisch800bf382013-05-24 11:21:11 -0400173 iniset $file $section rpc_zmq_matchmaker \
174 ${package}.openstack.common.rpc.matchmaker_redis.MatchMakerRedis
175 # Set MATCHMAKER_REDIS_HOST if running multi-node.
176 MATCHMAKER_REDIS_HOST=${MATCHMAKER_REDIS_HOST:-127.0.0.1}
177 iniset $file matchmaker_redis host $MATCHMAKER_REDIS_HOST
Jason Dillaman056df822013-07-01 08:52:13 -0400178 elif is_service_enabled qpid || [ -n "$QPID_HOST" ]; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900179 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
Attila Fazekasa3dc3992013-07-11 11:26:35 +0200180 iniset $file $section qpid_hostname ${QPID_HOST:-$SERVICE_HOST}
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000181 if is_ubuntu; then
182 QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1`
183 iniset $file $section qpid_password $QPID_PASSWORD
184 iniset $file $section qpid_username admin
185 fi
jiajun xu4a30b842013-01-22 11:49:03 +0800186 elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900187 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
Nicolas Simonds8f084c62014-02-28 17:01:41 -0800188 iniset $file $section rabbit_hosts $RABBIT_HOST
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900189 iniset $file $section rabbit_password $RABBIT_PASSWORD
190 fi
191}
192
193# Check if qpid can be used on the current distro.
194# qpid_is_supported
Ian Wienandaee18c72014-02-21 15:35:08 +1100195function qpid_is_supported {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900196 if [[ -z "$DISTRO" ]]; then
197 GetDistro
198 fi
199
Sean Dague2bb483d2014-01-03 09:41:27 -0500200 # Qpid is not in openSUSE
201 ( ! is_suse )
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900202}
203
Dean Troyercc6b4432013-04-08 15:38:03 -0500204
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900205# Restore xtrace
206$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400207
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100208# Tell emacs to use shell-script-mode
209## Local variables:
210## mode: shell-script
211## End: