blob: a62d4e71a8a227922e8fc3c7c9a7cfdbeb19b0dd [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 {
Matthieu Huin7a7a4662013-04-15 17:13:41 +020029 local rpc_needed=1
30 # We rely on the fact that filenames in lib/* match the service names
31 # that can be passed as arguments to is_service_enabled.
32 # We check for a call to iniset_rpc_backend in these files, meaning
33 # the service needs a backend.
Vishvananda Ishaya78a53d92013-05-09 17:20:31 -070034 rpc_candidates=$(grep -rl iniset_rpc_backend $TOP_DIR/lib/ | awk -F/ '{print $NF}')
Matthieu Huin7a7a4662013-04-15 17:13:41 +020035 for c in ${rpc_candidates}; do
36 if is_service_enabled $c; then
37 rpc_needed=0
38 break
39 fi
40 done
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090041 local rpc_backend_cnt=0
42 for svc in qpid zeromq rabbit; do
43 is_service_enabled $svc &&
44 ((rpc_backend_cnt++))
45 done
46 if [ "$rpc_backend_cnt" -gt 1 ]; then
47 echo "ERROR: only one rpc backend may be enabled,"
48 echo " set only one of 'rabbit', 'qpid', 'zeromq'"
49 echo " via ENABLED_SERVICES."
Matthieu Huin7a7a4662013-04-15 17:13:41 +020050 elif [ "$rpc_backend_cnt" == 0 ] && [ "$rpc_needed" == 0 ]; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090051 echo "ERROR: at least one rpc backend must be enabled,"
52 echo " set one of 'rabbit', 'qpid', 'zeromq'"
53 echo " via ENABLED_SERVICES."
54 fi
55
56 if is_service_enabled qpid && ! qpid_is_supported; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080057 die $LINENO "Qpid support is not available for this version of your distribution."
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090058 fi
59}
60
Dean Troyer995eb922013-03-07 16:11:40 -060061# clean up after rpc backend - eradicate all traces so changing backends
62# produces a clean switch
63function cleanup_rpc_backend {
64 if is_service_enabled rabbit; then
65 # Obliterate rabbitmq-server
66 uninstall_package rabbitmq-server
DennyZhang557744f2013-10-14 09:50:13 -050067 sudo killall epmd || sudo killall -9 epmd
Dean Troyer995eb922013-03-07 16:11:40 -060068 if is_ubuntu; then
69 # And the Erlang runtime too
Sahid Orentino Ferdjaouie9648272014-02-23 18:55:51 +010070 apt_get purge -y erlang*
Dean Troyer995eb922013-03-07 16:11:40 -060071 fi
72 elif is_service_enabled qpid; then
73 if is_fedora; then
zhhuabj5595fdc2013-05-08 18:27:20 +080074 uninstall_package qpid-cpp-server
Dean Troyer995eb922013-03-07 16:11:40 -060075 elif is_ubuntu; then
76 uninstall_package qpidd
77 else
78 exit_distro_not_supported "qpid installation"
79 fi
80 elif is_service_enabled zeromq; then
81 if is_fedora; then
Eric Windisch800bf382013-05-24 11:21:11 -040082 uninstall_package zeromq python-zmq redis
Dean Troyer995eb922013-03-07 16:11:40 -060083 elif is_ubuntu; then
Eric Windisch800bf382013-05-24 11:21:11 -040084 uninstall_package libzmq1 python-zmq redis-server
Dean Troyer995eb922013-03-07 16:11:40 -060085 elif is_suse; then
Eric Windisch800bf382013-05-24 11:21:11 -040086 uninstall_package libzmq1 python-pyzmq redis
Dean Troyer995eb922013-03-07 16:11:40 -060087 else
88 exit_distro_not_supported "zeromq installation"
89 fi
90 fi
91}
92
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090093# install rpc backend
Ian Wienandaee18c72014-02-21 15:35:08 +110094function install_rpc_backend {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090095 if is_service_enabled rabbit; then
96 # Install rabbitmq-server
Ian Wienand7ccf4e02014-07-23 14:24:11 +100097 install_package rabbitmq-server
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090098 elif is_service_enabled qpid; then
99 if is_fedora; then
zhhuabj5595fdc2013-05-08 18:27:20 +0800100 install_package qpid-cpp-server
Ian Wienand64dd03d2013-04-11 12:01:09 +1000101 if [[ $DISTRO =~ (rhel6) ]]; then
Sean Dague101b4242013-10-22 08:47:11 -0400102 # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to
103 # be no or you get GSS authentication errors as it
104 # attempts to default to this.
Ian Wienand64dd03d2013-04-11 12:01:09 +1000105 sudo sed -i.bak 's/^auth=yes$/auth=no/' /etc/qpidd.conf
Ian Wienand64dd03d2013-04-11 12:01:09 +1000106 fi
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900107 elif is_ubuntu; then
108 install_package qpidd
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000109 sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf
110 sudo chmod o+r /etc/qpid/qpidd.sasldb
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900111 else
112 exit_distro_not_supported "qpid installation"
113 fi
114 elif is_service_enabled zeromq; then
Eric Windisch800bf382013-05-24 11:21:11 -0400115 # NOTE(ewindisch): Redis is not strictly necessary
116 # but there is a matchmaker driver that works
117 # really well & out of the box for multi-node.
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900118 if is_fedora; then
Eric Windisch800bf382013-05-24 11:21:11 -0400119 install_package zeromq python-zmq redis
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900120 elif is_ubuntu; then
Eric Windisch800bf382013-05-24 11:21:11 -0400121 install_package libzmq1 python-zmq redis-server
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900122 elif is_suse; then
Eric Windisch800bf382013-05-24 11:21:11 -0400123 install_package libzmq1 python-pyzmq redis
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900124 else
125 exit_distro_not_supported "zeromq installation"
126 fi
Vincent Hou93a7a502013-09-27 06:16:54 -0400127 # Necessary directory for socket location.
128 sudo mkdir -p /var/run/openstack
129 sudo chown $STACK_USER /var/run/openstack
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900130 fi
131}
132
133# restart the rpc backend
Ian Wienandaee18c72014-02-21 15:35:08 +1100134function restart_rpc_backend {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900135 if is_service_enabled rabbit; then
136 # Start rabbitmq-server
137 echo_summary "Starting RabbitMQ"
Ben Nemecec5918f2014-01-30 16:07:23 +0000138 # NOTE(bnemec): Retry initial rabbitmq configuration to deal with
139 # the fact that sometimes it fails to start properly.
140 # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028
141 for i in `seq 10`; do
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 && break
148 [[ $i -eq "10" ]] && die $LINENO "Failed to set rabbitmq password"
149 done
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000150 if is_service_enabled n-cell; then
151 # Add partitioned access for the child cell
152 if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then
153 sudo rabbitmqctl add_vhost child_cell
154 sudo rabbitmqctl set_permissions -p child_cell guest ".*" ".*" ".*"
155 fi
156 fi
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900157 elif is_service_enabled qpid; then
158 echo_summary "Starting qpid"
159 restart_service qpidd
160 fi
161}
162
163# iniset cofiguration
Ian Wienandaee18c72014-02-21 15:35:08 +1100164function iniset_rpc_backend {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900165 local package=$1
166 local file=$2
167 local section=$3
168 if is_service_enabled zeromq; then
169 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
Eric Windisch800bf382013-05-24 11:21:11 -0400170 iniset $file $section rpc_zmq_matchmaker \
171 ${package}.openstack.common.rpc.matchmaker_redis.MatchMakerRedis
172 # Set MATCHMAKER_REDIS_HOST if running multi-node.
173 MATCHMAKER_REDIS_HOST=${MATCHMAKER_REDIS_HOST:-127.0.0.1}
174 iniset $file matchmaker_redis host $MATCHMAKER_REDIS_HOST
Jason Dillaman056df822013-07-01 08:52:13 -0400175 elif is_service_enabled qpid || [ -n "$QPID_HOST" ]; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900176 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
Attila Fazekasa3dc3992013-07-11 11:26:35 +0200177 iniset $file $section qpid_hostname ${QPID_HOST:-$SERVICE_HOST}
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000178 if is_ubuntu; then
179 QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1`
180 iniset $file $section qpid_password $QPID_PASSWORD
181 iniset $file $section qpid_username admin
182 fi
jiajun xu4a30b842013-01-22 11:49:03 +0800183 elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900184 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
Nicolas Simonds8f084c62014-02-28 17:01:41 -0800185 iniset $file $section rabbit_hosts $RABBIT_HOST
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900186 iniset $file $section rabbit_password $RABBIT_PASSWORD
187 fi
188}
189
190# Check if qpid can be used on the current distro.
191# qpid_is_supported
Ian Wienandaee18c72014-02-21 15:35:08 +1100192function qpid_is_supported {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900193 if [[ -z "$DISTRO" ]]; then
194 GetDistro
195 fi
196
Sean Dague2bb483d2014-01-03 09:41:27 -0500197 # Qpid is not in openSUSE
198 ( ! is_suse )
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900199}
200
Dean Troyercc6b4432013-04-08 15:38:03 -0500201
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900202# Restore xtrace
203$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400204
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100205# Tell emacs to use shell-script-mode
206## Local variables:
207## mode: shell-script
208## End: