blob: e922daa0784e56e8376603185d5f4ae20a83e67e [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
97 # the temp file is necessary due to LP: #878600
98 tfile=$(mktemp)
99 install_package rabbitmq-server > "$tfile" 2>&1
100 cat "$tfile"
101 rm -f "$tfile"
102 elif is_service_enabled qpid; then
103 if is_fedora; then
zhhuabj5595fdc2013-05-08 18:27:20 +0800104 install_package qpid-cpp-server
Ian Wienand64dd03d2013-04-11 12:01:09 +1000105 if [[ $DISTRO =~ (rhel6) ]]; then
Sean Dague101b4242013-10-22 08:47:11 -0400106 # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to
107 # be no or you get GSS authentication errors as it
108 # attempts to default to this.
Ian Wienand64dd03d2013-04-11 12:01:09 +1000109 sudo sed -i.bak 's/^auth=yes$/auth=no/' /etc/qpidd.conf
Ian Wienand64dd03d2013-04-11 12:01:09 +1000110 fi
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900111 elif is_ubuntu; then
112 install_package qpidd
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000113 sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf
114 sudo chmod o+r /etc/qpid/qpidd.sasldb
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900115 else
116 exit_distro_not_supported "qpid installation"
117 fi
118 elif is_service_enabled zeromq; then
Eric Windisch800bf382013-05-24 11:21:11 -0400119 # NOTE(ewindisch): Redis is not strictly necessary
120 # but there is a matchmaker driver that works
121 # really well & out of the box for multi-node.
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900122 if is_fedora; then
Eric Windisch800bf382013-05-24 11:21:11 -0400123 install_package zeromq python-zmq redis
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900124 elif is_ubuntu; then
Eric Windisch800bf382013-05-24 11:21:11 -0400125 install_package libzmq1 python-zmq redis-server
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900126 elif is_suse; then
Eric Windisch800bf382013-05-24 11:21:11 -0400127 install_package libzmq1 python-pyzmq redis
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900128 else
129 exit_distro_not_supported "zeromq installation"
130 fi
Vincent Hou93a7a502013-09-27 06:16:54 -0400131 # Necessary directory for socket location.
132 sudo mkdir -p /var/run/openstack
133 sudo chown $STACK_USER /var/run/openstack
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900134 fi
135}
136
137# restart the rpc backend
Ian Wienandaee18c72014-02-21 15:35:08 +1100138function restart_rpc_backend {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900139 if is_service_enabled rabbit; then
140 # Start rabbitmq-server
141 echo_summary "Starting RabbitMQ"
Ben Nemecec5918f2014-01-30 16:07:23 +0000142 # NOTE(bnemec): Retry initial rabbitmq configuration to deal with
143 # the fact that sometimes it fails to start properly.
144 # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028
145 for i in `seq 10`; do
146 if is_fedora || is_suse; then
147 # service is not started by default
148 restart_service rabbitmq-server
149 fi
150 # change the rabbit password since the default is "guest"
151 sudo rabbitmqctl change_password guest $RABBIT_PASSWORD && break
152 [[ $i -eq "10" ]] && die $LINENO "Failed to set rabbitmq password"
153 done
Kieran Spearfb2a3ae2013-03-11 23:55:49 +0000154 if is_service_enabled n-cell; then
155 # Add partitioned access for the child cell
156 if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then
157 sudo rabbitmqctl add_vhost child_cell
158 sudo rabbitmqctl set_permissions -p child_cell guest ".*" ".*" ".*"
159 fi
160 fi
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900161 elif is_service_enabled qpid; then
162 echo_summary "Starting qpid"
163 restart_service qpidd
164 fi
165}
166
167# iniset cofiguration
Ian Wienandaee18c72014-02-21 15:35:08 +1100168function iniset_rpc_backend {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900169 local package=$1
170 local file=$2
171 local section=$3
172 if is_service_enabled zeromq; then
173 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
Eric Windisch800bf382013-05-24 11:21:11 -0400174 iniset $file $section rpc_zmq_matchmaker \
175 ${package}.openstack.common.rpc.matchmaker_redis.MatchMakerRedis
176 # Set MATCHMAKER_REDIS_HOST if running multi-node.
177 MATCHMAKER_REDIS_HOST=${MATCHMAKER_REDIS_HOST:-127.0.0.1}
178 iniset $file matchmaker_redis host $MATCHMAKER_REDIS_HOST
Jason Dillaman056df822013-07-01 08:52:13 -0400179 elif is_service_enabled qpid || [ -n "$QPID_HOST" ]; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900180 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
Attila Fazekasa3dc3992013-07-11 11:26:35 +0200181 iniset $file $section qpid_hostname ${QPID_HOST:-$SERVICE_HOST}
Eoghan Glynn8c11f562013-03-01 12:09:01 +0000182 if is_ubuntu; then
183 QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1`
184 iniset $file $section qpid_password $QPID_PASSWORD
185 iniset $file $section qpid_username admin
186 fi
jiajun xu4a30b842013-01-22 11:49:03 +0800187 elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900188 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
Nicolas Simonds8f084c62014-02-28 17:01:41 -0800189 iniset $file $section rabbit_hosts $RABBIT_HOST
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900190 iniset $file $section rabbit_password $RABBIT_PASSWORD
191 fi
192}
193
194# Check if qpid can be used on the current distro.
195# qpid_is_supported
Ian Wienandaee18c72014-02-21 15:35:08 +1100196function qpid_is_supported {
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900197 if [[ -z "$DISTRO" ]]; then
198 GetDistro
199 fi
200
Sean Dague2bb483d2014-01-03 09:41:27 -0500201 # Qpid is not in openSUSE
202 ( ! is_suse )
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900203}
204
Dean Troyercc6b4432013-04-08 15:38:03 -0500205
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900206# Restore xtrace
207$XTRACE
Sean Dague584d90e2013-03-29 14:34:53 -0400208
Adam Spiers6a5aa7c2013-10-24 11:27:02 +0100209# Tell emacs to use shell-script-mode
210## Local variables:
211## mode: shell-script
212## End: