#!/bin/sh ## This Source Code Form is subject to the terms of the Mozilla Public ## License, v. 2.0. If a copy of the MPL was not distributed with this ## file, You can obtain one at https://mozilla.org/MPL/2.0/. ## ## Copyright (c) 2018-2020 VMware, Inc. or its affiliates. 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 ## OCF_RESKEY_limit_nofile ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat} . ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs ####################################################################### 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_limit_nofile_default=65535 : ${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}} : ${OCF_RESKEY_limit_nofile=${OCF_RESKEY_limit_nofile_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 Soft and hard limit for NOFILE NOFILE limit END } rabbit_usage() { cat < ${RABBITMQ_LOG_BASE}/startup_log 2> ${RABBITMQ_LOG_BASE}/startup_err" & # 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 rabbitmqctl_action stop ${RABBITMQ_PID_FILE} 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 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 $?