lib/rpc_backend
b0f1c38b
 # lib/rpc_backend
 # Interface for interactig with different rpc backend
 # rpc backend settings
 
 # Dependencies:
6a5aa7c6
 #
 # - ``functions`` file
 # - ``RABBIT_{HOST|PASSWORD}`` must be defined when RabbitMQ is used
b0f1c38b
 
 # ``stack.sh`` calls the entry points in this order:
 #
6a5aa7c6
 # - check_rpc_backend
 # - install_rpc_backend
 # - restart_rpc_backend
 # - iniset_rpc_backend
b0f1c38b
 
 # Save trace setting
 XTRACE=$(set +o | grep xtrace)
 set +o xtrace
 
cc6b4435
 
 # Functions
 # ---------
b0f1c38b
 
7a7a4667
 
b0f1c38b
 # Make sure we only have one rpc backend enabled.
 # Also check the specified rpc backend is available on your platform.
aee18c74
 function check_rpc_backend {
3ef23bce
     local c svc
 
7a7a4667
     local rpc_needed=1
     # We rely on the fact that filenames in lib/* match the service names
     # that can be passed as arguments to is_service_enabled.
     # We check for a call to iniset_rpc_backend in these files, meaning
     # the service needs a backend.
78a53d92
     rpc_candidates=$(grep -rl iniset_rpc_backend $TOP_DIR/lib/ | awk -F/ '{print $NF}')
7a7a4667
     for c in ${rpc_candidates}; do
         if is_service_enabled $c; then
             rpc_needed=0
             break
         fi
     done
b0f1c38b
     local rpc_backend_cnt=0
     for svc in qpid zeromq rabbit; do
         is_service_enabled $svc &&
         ((rpc_backend_cnt++))
     done
     if [ "$rpc_backend_cnt" -gt 1 ]; then
         echo "ERROR: only one rpc backend may be enabled,"
         echo "       set only one of 'rabbit', 'qpid', 'zeromq'"
         echo "       via ENABLED_SERVICES."
7a7a4667
     elif [ "$rpc_backend_cnt" == 0 ] && [ "$rpc_needed" == 0 ]; then
b0f1c38b
         echo "ERROR: at least one rpc backend must be enabled,"
         echo "       set one of 'rabbit', 'qpid', 'zeromq'"
         echo "       via ENABLED_SERVICES."
     fi
 
     if is_service_enabled qpid && ! qpid_is_supported; then
07115eb5
         die $LINENO "Qpid support is not available for this version of your distribution."
b0f1c38b
     fi
 }
 
995eb927
 # clean up after rpc backend - eradicate all traces so changing backends
 # produces a clean switch
 function cleanup_rpc_backend {
     if is_service_enabled rabbit; then
         # Obliterate rabbitmq-server
         uninstall_package rabbitmq-server
557744fa
         sudo killall epmd || sudo killall -9 epmd
995eb927
         if is_ubuntu; then
             # And the Erlang runtime too
e9648276
             apt_get purge -y erlang*
995eb927
         fi
     elif is_service_enabled qpid; then
         if is_fedora; then
5595fdc2
             uninstall_package qpid-cpp-server
995eb927
         elif is_ubuntu; then
             uninstall_package qpidd
         else
             exit_distro_not_supported "qpid installation"
         fi
     elif is_service_enabled zeromq; then
         if is_fedora; then
800bf387
             uninstall_package zeromq python-zmq redis
995eb927
         elif is_ubuntu; then
800bf387
             uninstall_package libzmq1 python-zmq redis-server
995eb927
         elif is_suse; then
800bf387
             uninstall_package libzmq1 python-pyzmq redis
995eb927
         else
             exit_distro_not_supported "zeromq installation"
         fi
     fi
 }
 
b0f1c38b
 # install rpc backend
aee18c74
 function install_rpc_backend {
b0f1c38b
     if is_service_enabled rabbit; then
         # Install rabbitmq-server
7ccf4e02
         install_package rabbitmq-server
b0f1c38b
     elif is_service_enabled qpid; then
         if is_fedora; then
5595fdc2
             install_package qpid-cpp-server
64dd03dd
             if [[ $DISTRO =~ (rhel6) ]]; then
101b4248
                 # RHEL6 leaves "auth=yes" in /etc/qpidd.conf, it needs to
                 # be no or you get GSS authentication errors as it
                 # attempts to default to this.
64dd03dd
                 sudo sed -i.bak 's/^auth=yes$/auth=no/' /etc/qpidd.conf
             fi
b0f1c38b
         elif is_ubuntu; then
             install_package qpidd
8c11f561
             sudo sed -i '/PLAIN/!s/mech_list: /mech_list: PLAIN /' /etc/sasl2/qpidd.conf
             sudo chmod o+r /etc/qpid/qpidd.sasldb
b0f1c38b
         else
             exit_distro_not_supported "qpid installation"
         fi
     elif is_service_enabled zeromq; then
800bf387
         # NOTE(ewindisch): Redis is not strictly necessary
         # but there is a matchmaker driver that works
         # really well & out of the box for multi-node.
b0f1c38b
         if is_fedora; then
800bf387
             install_package zeromq python-zmq redis
b0f1c38b
         elif is_ubuntu; then
800bf387
             install_package libzmq1 python-zmq redis-server
b0f1c38b
         elif is_suse; then
800bf387
             install_package libzmq1 python-pyzmq redis
b0f1c38b
         else
             exit_distro_not_supported "zeromq installation"
         fi
93a7a50c
         # Necessary directory for socket location.
         sudo mkdir -p /var/run/openstack
         sudo chown $STACK_USER /var/run/openstack
b0f1c38b
     fi
 }
 
 # restart the rpc backend
aee18c74
 function restart_rpc_backend {
b0f1c38b
     if is_service_enabled rabbit; then
         # Start rabbitmq-server
         echo_summary "Starting RabbitMQ"
ec5918f2
         # NOTE(bnemec): Retry initial rabbitmq configuration to deal with
         # the fact that sometimes it fails to start properly.
         # Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1059028
3ef23bce
         local i
ec5918f2
         for i in `seq 10`; do
             if is_fedora || is_suse; then
                 # service is not started by default
                 restart_service rabbitmq-server
             fi
             # change the rabbit password since the default is "guest"
             sudo rabbitmqctl change_password guest $RABBIT_PASSWORD && break
             [[ $i -eq "10" ]] && die $LINENO "Failed to set rabbitmq password"
         done
fb2a3ae3
         if is_service_enabled n-cell; then
             # Add partitioned access for the child cell
             if [ -z `sudo rabbitmqctl list_vhosts | grep child_cell` ]; then
                 sudo rabbitmqctl add_vhost child_cell
                 sudo rabbitmqctl set_permissions -p child_cell guest ".*" ".*" ".*"
             fi
         fi
b0f1c38b
     elif is_service_enabled qpid; then
         echo_summary "Starting qpid"
         restart_service qpidd
     fi
 }
 
 # iniset cofiguration
aee18c74
 function iniset_rpc_backend {
b0f1c38b
     local package=$1
     local file=$2
     local section=$3
     if is_service_enabled zeromq; then
         iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_zmq
800bf387
         iniset $file $section rpc_zmq_matchmaker \
             ${package}.openstack.common.rpc.matchmaker_redis.MatchMakerRedis
         # Set MATCHMAKER_REDIS_HOST if running multi-node.
         MATCHMAKER_REDIS_HOST=${MATCHMAKER_REDIS_HOST:-127.0.0.1}
         iniset $file matchmaker_redis host $MATCHMAKER_REDIS_HOST
056df827
     elif is_service_enabled qpid || [ -n "$QPID_HOST" ]; then
b0f1c38b
         iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_qpid
a3dc3999
         iniset $file $section qpid_hostname ${QPID_HOST:-$SERVICE_HOST}
8c11f561
         if is_ubuntu; then
             QPID_PASSWORD=`sudo strings /etc/qpid/qpidd.sasldb | grep -B1 admin | head -1`
             iniset $file $section qpid_password $QPID_PASSWORD
             iniset $file $section qpid_username admin
         fi
4a30b849
     elif is_service_enabled rabbit || { [ -n "$RABBIT_HOST" ] && [ -n "$RABBIT_PASSWORD" ]; }; then
b0f1c38b
         iniset $file $section rpc_backend ${package}.openstack.common.rpc.impl_kombu
8f084c6b
         iniset $file $section rabbit_hosts $RABBIT_HOST
b0f1c38b
         iniset $file $section rabbit_password $RABBIT_PASSWORD
     fi
 }
 
 # Check if qpid can be used on the current distro.
 # qpid_is_supported
aee18c74
 function qpid_is_supported {
b0f1c38b
     if [[ -z "$DISTRO" ]]; then
         GetDistro
     fi
 
2bb483d3
     # Qpid is not in openSUSE
     ( ! is_suse )
b0f1c38b
 }
 
cc6b4435
 
b0f1c38b
 # Restore xtrace
 $XTRACE
584d90ec
 
6a5aa7c6
 # Tell emacs to use shell-script-mode
 ## Local variables:
 ## mode: shell-script
 ## End: