blob: 7ea71ee1304e2696a19621eeae5c556287002402 [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
20# Entry Points
21# ------------
22
23# Make sure we only have one rpc backend enabled.
24# Also check the specified rpc backend is available on your platform.
25function check_rpc_backend() {
26 local rpc_backend_cnt=0
27 for svc in qpid zeromq rabbit; do
28 is_service_enabled $svc &&
29 ((rpc_backend_cnt++))
30 done
31 if [ "$rpc_backend_cnt" -gt 1 ]; then
32 echo "ERROR: only one rpc backend may be enabled,"
33 echo " set only one of 'rabbit', 'qpid', 'zeromq'"
34 echo " via ENABLED_SERVICES."
35 elif [ "$rpc_backend_cnt" == 0 ]; then
36 echo "ERROR: at least one rpc backend must be enabled,"
37 echo " set one of 'rabbit', 'qpid', 'zeromq'"
38 echo " via ENABLED_SERVICES."
39 fi
40
41 if is_service_enabled qpid && ! qpid_is_supported; then
Nachi Ueno07115eb2013-02-26 12:38:18 -080042 die $LINENO "Qpid support is not available for this version of your distribution."
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +090043 fi
44}
45
46# install rpc backend
47function install_rpc_backend() {
48 if is_service_enabled rabbit; then
49 # Install rabbitmq-server
50 # the temp file is necessary due to LP: #878600
51 tfile=$(mktemp)
52 install_package rabbitmq-server > "$tfile" 2>&1
53 cat "$tfile"
54 rm -f "$tfile"
55 elif is_service_enabled qpid; then
56 if is_fedora; then
57 install_package qpid-cpp-server-daemon
58 elif is_ubuntu; then
59 install_package qpidd
60 else
61 exit_distro_not_supported "qpid installation"
62 fi
63 elif is_service_enabled zeromq; then
64 if is_fedora; then
65 install_package zeromq python-zmq
66 elif is_ubuntu; then
67 install_package libzmq1 python-zmq
68 elif is_suse; then
69 install_package libzmq1 python-pyzmq
70 else
71 exit_distro_not_supported "zeromq installation"
72 fi
73 fi
74}
75
76# restart the rpc backend
77function restart_rpc_backend() {
78 if is_service_enabled rabbit; then
79 # Start rabbitmq-server
80 echo_summary "Starting RabbitMQ"
81 if is_fedora || is_suse; then
82 # service is not started by default
83 restart_service rabbitmq-server
84 fi
85 # change the rabbit password since the default is "guest"
86 sudo rabbitmqctl change_password guest $RABBIT_PASSWORD
87 elif is_service_enabled qpid; then
88 echo_summary "Starting qpid"
89 restart_service qpidd
90 fi
91}
92
93# iniset cofiguration
94function iniset_rpc_backend() {
95 local package=$1
96 local file=$2
97 local section=$3
98 if is_service_enabled zeromq; then
99 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
100 elif is_service_enabled qpid; then
101 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
jiajun xu4a30b842013-01-22 11:49:03 +0800102 elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
Akihiro MOTOKIb0f1c382013-01-13 17:58:12 +0900103 iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
104 iniset $file $section rabbit_host $RABBIT_HOST
105 iniset $file $section rabbit_password $RABBIT_PASSWORD
106 fi
107}
108
109# Check if qpid can be used on the current distro.
110# qpid_is_supported
111function qpid_is_supported() {
112 if [[ -z "$DISTRO" ]]; then
113 GetDistro
114 fi
115
116 # Qpid was introduced to Ubuntu in precise, disallow it on oneiric; it is
117 # not in openSUSE either right now.
118 ( ! ([[ "$DISTRO" = "oneiric" ]] || is_suse) )
119}
120
121# Restore xtrace
122$XTRACE