components/rabbitmq/svc-rabbitmq
branchs11u3-sru
changeset 6035 c9748fcc32de
parent 6016 a477397bba8b
child 6054 b5ae16fb8526
equal deleted inserted replaced
6016:a477397bba8b 6035:c9748fcc32de
     1 #!/usr/sbin/sh
       
     2 #
       
     3 # CDDL HEADER START
       
     4 #
       
     5 # The contents of this file are subject to the terms of the
       
     6 # Common Development and Distribution License (the "License").
       
     7 # You may not use this file except in compliance with the License.
       
     8 #
       
     9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
       
    10 # or http://www.opensolaris.org/os/licensing.
       
    11 # See the License for the specific language governing permissions
       
    12 # and limitations under the License.
       
    13 #
       
    14 # When distributing Covered Code, include this CDDL HEADER in each
       
    15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
       
    16 # If applicable, add the following below this CDDL HEADER, with the
       
    17 # fields enclosed by brackets "[]" replaced with your own identifying
       
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
       
    19 #
       
    20 # CDDL HEADER END
       
    21 #
       
    22 
       
    23 #
       
    24 # Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
       
    25 #
       
    26 
       
    27 . /lib/svc/share/smf_include.sh
       
    28 
       
    29 RABBIT_SERVER=/usr/bin/rabbitmq-server
       
    30 RABBIT_CTL=/usr/bin/rabbitmqctl
       
    31 
       
    32 if [[ -z "$SMF_FMRI" ]]; then
       
    33 	echo "This script can only be invoked by smf(5)"
       
    34 	exit $SMF_EXIT_ERR_NOSMF
       
    35 fi
       
    36 
       
    37 # rabbitmq-env handles pulling in configuration from a number of sources.  Out
       
    38 # of that, the server builds more configuration variables if they haven't
       
    39 # already been set.  getenv() gives us the variable as the server would see it.
       
    40 # It's up to the caller to massage it as the server would.
       
    41 getenv() {
       
    42 	# Has the RABBITMQ_ version been set?  If so, that takes precedence.
       
    43 	r=$(eval print \$RABBITMQ_${1})
       
    44 	if [[ -n $r ]]; then
       
    45 		print $r
       
    46 	else
       
    47 		print $(
       
    48 			SCRIPT_DIR=/usr/lib/rabbitmq/bin;
       
    49 			. /usr/lib/rabbitmq/bin/rabbitmq-env;
       
    50 			eval print \${$1}
       
    51 		)
       
    52 	fi
       
    53 }
       
    54 
       
    55 # If RABBITMQ_NODENAME isn't set in the environment, then use the FMRI instance
       
    56 # name, unless the instance name is "default", in which case we use the default
       
    57 # from the configuration files.  If the instance name doesn't have an @ in it,
       
    58 # then append the hostname.
       
    59 if [[ -z $RABBITMQ_NODENAME ]]; then
       
    60 	INSTANCE=${SMF_FMRI##*:}
       
    61 	if [[ $INSTANCE == default ]]; then
       
    62 		INSTANCE=$(getenv NODENAME)
       
    63 	fi
       
    64 	if [[ $INSTANCE != *@* ]]; then
       
    65 		INSTANCE=$INSTANCE@$(hostname)
       
    66 	fi
       
    67 	export RABBITMQ_NODENAME=$INSTANCE
       
    68 fi
       
    69 
       
    70 # XXX Why isn't HOME set for us?
       
    71 export HOME=/var/lib/rabbitmq
       
    72 
       
    73 case "$1" in
       
    74 "start")
       
    75 	$RABBIT_SERVER -detached
       
    76 	;;
       
    77 
       
    78 "stop")
       
    79 	$RABBIT_CTL -n $RABBITMQ_NODENAME stop
       
    80 	# XXX epmd should be in a separate SMF service (16749936); for now,
       
    81 	# though, be sure to kill it here.
       
    82 	epmd_pid=$(pgrep -c $(svcs -H -o ctid $SMF_FMRI) epmd)
       
    83 	if [[ -n $epmd_pid ]]; then
       
    84 		sleep 2
       
    85 		epmd -kill
       
    86 	fi
       
    87 	;;
       
    88 
       
    89 *)
       
    90 	echo "Usage: $0 { start | stop }"
       
    91 	exit $SMF_EXIT_ERR_CONFIG
       
    92 	;;
       
    93 esac
       
    94 
       
    95 exit $SMF_EXIT_OK