#!/bin/sh ## The contents of this file are subject to the Mozilla Public License ## Version 1.1 (the "License"); you may not use this file except in ## compliance with the License. You may obtain a copy of the License ## at http://www.mozilla.org/MPL/ ## ## Software distributed under the License is distributed on an "AS IS" ## basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See ## the License for the specific language governing rights and ## limitations under the License. ## ## The Original Code is RabbitMQ. ## ## The Initial Developer of the Original Code is VMware, Inc. ## Copyright (c) 2007-2013 VMware, Inc. All rights reserved. ## ## ## OCF Resource Agent compliant rabbitmq-server resource script. ## ## OCF instance parameters ## OCF_RESKEY_server ## OCF_RESKEY_ctl ## OCF_RESKEY_nodename ## OCF_RESKEY_ip ## OCF_RESKEY_port ## OCF_RESKEY_config_file ## OCF_RESKEY_log_base ## OCF_RESKEY_mnesia_base ## OCF_RESKEY_server_start_args ## OCF_RESKEY_pid_file ## WRS # OCF_RESKEY_env_config_file # OCF_RESKEY_dist_port ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat} . ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs ####################################################################### . /etc/platform/platform.conf OCF_RESKEY_server_default="/usr/sbin/rabbitmq-server" OCF_RESKEY_ctl_default="/usr/sbin/rabbitmqctl" OCF_RESKEY_nodename_default="rabbit@localhost" OCF_RESKEY_log_base_default="/var/log/rabbitmq" OCF_RESKEY_pid_file_default="/var/run/rabbitmq/pid" : ${OCF_RESKEY_server=${OCF_RESKEY_server_default}} : ${OCF_RESKEY_ctl=${OCF_RESKEY_ctl_default}} : ${OCF_RESKEY_nodename=${OCF_RESKEY_nodename_default}} : ${OCF_RESKEY_log_base=${OCF_RESKEY_log_base_default}} : ${OCF_RESKEY_pid_file=${OCF_RESKEY_pid_file_default}} meta_data() { cat < 1.0 Resource agent for RabbitMQ-server Resource agent for RabbitMQ-server The path to the rabbitmq-server script Path to rabbitmq-server The path to the rabbitmqctl script Path to rabbitmqctl The node name for rabbitmq-server Node name The IP address for rabbitmq-server to listen on IP Address The IP Port for rabbitmq-server to listen on IP Port Location of the config file (without the .config suffix) Config file path (without the .config suffix) Location of the directory under which logs will be created Log base path Location of the directory under which mnesia will store data Mnesia base path Additional arguments provided to the server on startup Server start arguments Location of the file in which the pid will be stored Pid file path END } rabbit_usage() { cat < /dev/null 2> /dev/null rc=$? case "$rc" in 0) ocf_log debug "RabbitMQ server is running normally" return $OCF_SUCCESS ;; 2) ocf_log debug "RabbitMQ server is not running" return $OCF_NOT_RUNNING ;; *) ocf_log err "Unexpected return from rabbitmqctl $NODENAME_ARG $action: $rc" exit $OCF_ERR_GENERIC esac } rabbit_start() { local rc if rabbit_status; then ocf_log info "Resource already running." return $OCF_SUCCESS fi export_vars # Increase the maximum number of file descriptors that can be open at # once - required for large systems. ulimit -n 8192 if [ "${system_type}" = "All-in-one" ]; then # Rabbit/beam related tasks should be on platform cores from the get go. # If they are affined to all cores during initialization sequence of AIO, # the system will end up with many extra beam threads that are not in use. source /etc/init.d/cpumap_functions.sh PLATFORM_CPULIST=$(get_platform_cpu_list) setsid sh -c "exec taskset -c ${PLATFORM_CPULIST} $RABBITMQ_SERVER >> ${RABBITMQ_LOG_BASE}/startup_log 2>> ${RABBITMQ_LOG_BASE}/startup_err" & else setsid sh -c "$RABBITMQ_SERVER >> ${RABBITMQ_LOG_BASE}/startup_log 2>> ${RABBITMQ_LOG_BASE}/startup_err" & fi # Wait for the server to come up. # Let the CRM/LRM time us out if required rabbit_wait $RABBITMQ_PID_FILE rc=$? if [ "$rc" != $OCF_SUCCESS ]; then remove_pid ocf_log info "rabbitmq-server start failed: $rc" exit $OCF_ERR_GENERIC fi return $OCF_SUCCESS } rabbit_stop() { local rc if ! rabbit_status; then ocf_log info "Resource not running." return $OCF_SUCCESS fi $RABBITMQ_CTL stop rc=$? if [ "$rc" != 0 ]; then ocf_log err "rabbitmq-server stop command failed: $RABBITMQ_CTL stop, $rc" return $rc fi # Spin waiting for the server to shut down. # Let the CRM/LRM time us out if required stop_wait=1 while [ $stop_wait = 1 ]; do rabbit_status rc=$? if [ "$rc" = $OCF_NOT_RUNNING ]; then remove_pid stop_wait=0 break elif [ "$rc" != $OCF_SUCCESS ]; then ocf_log info "rabbitmq-server stop failed: $rc" exit $OCF_ERR_GENERIC fi sleep 1 done return $OCF_SUCCESS } rabbit_monitor() { rabbit_status return $? } case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; usage|help) rabbit_usage exit $OCF_SUCCESS ;; esac if ocf_is_probe; then rabbit_validate_partial else rabbit_validate_full fi export_vars case $__OCF_ACTION in start) rabbit_start ;; stop) rabbit_stop ;; status|monitor) rabbit_monitor ;; validate-all) exit $OCF_SUCCESS ;; *) rabbit_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac exit $?