5403N/A#!/usr/bin/bash
2035N/A#
2035N/A# CDDL HEADER START
2035N/A#
2035N/A# The contents of this file are subject to the terms of the
2035N/A# Common Development and Distribution License (the "License").
2035N/A# You may not use this file except in compliance with the License.
2035N/A#
2035N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2035N/A# or http://www.opensolaris.org/os/licensing.
2035N/A# See the License for the specific language governing permissions
2035N/A# and limitations under the License.
2035N/A#
2035N/A# When distributing Covered Code, include this CDDL HEADER in each
2035N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2035N/A# If applicable, add the following below this CDDL HEADER, with the
2035N/A# fields enclosed by brackets "[]" replaced with your own identifying
2035N/A# information: Portions Copyright [yyyy] [name of copyright owner]
2035N/A#
2035N/A# CDDL HEADER END
2035N/A#
2035N/A
2035N/A#
5774N/A# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
2035N/A#
2035N/A
2035N/A. /lib/svc/share/smf_include.sh
2035N/A
2035N/ARABBIT_SERVER=/usr/bin/rabbitmq-server
2035N/ARABBIT_CTL=/usr/bin/rabbitmqctl
2035N/A
2035N/Aif [[ -z "$SMF_FMRI" ]]; then
2035N/A echo "This script can only be invoked by smf(5)"
2035N/A exit $SMF_EXIT_ERR_NOSMF
2035N/Afi
2035N/A
2035N/A# rabbitmq-env handles pulling in configuration from a number of sources. Out
2035N/A# of that, the server builds more configuration variables if they haven't
2035N/A# already been set. getenv() gives us the variable as the server would see it.
2035N/A# It's up to the caller to massage it as the server would.
2035N/Agetenv() {
2035N/A # Has the RABBITMQ_ version been set? If so, that takes precedence.
2035N/A r=$(eval print \$RABBITMQ_${1})
2035N/A if [[ -n $r ]]; then
2035N/A print $r
2035N/A else
2035N/A print $(
5774N/A RABBITMQ_SCRIPTS_DIR=/usr/lib/rabbitmq/sbin;
5774N/A . /usr/lib/rabbitmq/sbin/rabbitmq-env;
2035N/A eval print \${$1}
2035N/A )
2035N/A fi
2035N/A}
2035N/A
2035N/A# If RABBITMQ_NODENAME isn't set in the environment, then use the FMRI instance
2035N/A# name, unless the instance name is "default", in which case we use the default
2035N/A# from the configuration files. If the instance name doesn't have an @ in it,
2035N/A# then append the hostname.
2035N/Aif [[ -z $RABBITMQ_NODENAME ]]; then
2035N/A INSTANCE=${SMF_FMRI##*:}
2035N/A if [[ $INSTANCE == default ]]; then
2035N/A INSTANCE=$(getenv NODENAME)
2035N/A fi
2035N/A if [[ $INSTANCE != *@* ]]; then
2035N/A INSTANCE=$INSTANCE@$(hostname)
2035N/A fi
2035N/A export RABBITMQ_NODENAME=$INSTANCE
2035N/Afi
2035N/A
2035N/A# XXX Why isn't HOME set for us?
2035N/Aexport HOME=/var/lib/rabbitmq
2035N/A
2035N/Acase "$1" in
2035N/A"start")
2035N/A $RABBIT_SERVER -detached
5403N/A
5403N/A # make sure the service is actually up before returning
5403N/A while true; do
5403N/A /usr/bin/rabbitmqctl list_users > /dev/null 2>&1
5403N/A if [[ $? -ne 0 ]]; then
5403N/A sleep 1
5403N/A else
5403N/A break
5403N/A fi
5403N/A done
2035N/A ;;
2035N/A"stop")
2035N/A $RABBIT_CTL -n $RABBITMQ_NODENAME stop
2035N/A # XXX epmd should be in a separate SMF service (16749936); for now,
2035N/A # though, be sure to kill it here.
2035N/A epmd_pid=$(pgrep -c $(svcs -H -o ctid $SMF_FMRI) epmd)
2035N/A if [[ -n $epmd_pid ]]; then
2035N/A sleep 2
2035N/A epmd -kill
2035N/A fi
2035N/A ;;
2035N/A
2035N/A*)
2035N/A echo "Usage: $0 { start | stop }"
2035N/A exit $SMF_EXIT_ERR_CONFIG
2035N/A ;;
2035N/Aesac
2035N/A
2035N/Aexit $SMF_EXIT_OK