rabbitmq-server/scripts/rabbitmq-server.ocf

394 lines
11 KiB
Plaintext
Raw Normal View History

#!/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
URL Cleanup This commit updates URLs to prefer the https protocol. Redirects are not followed to avoid accidentally expanding intentionally shortened URLs (i.e. if using a URL shortener). # HTTP URLs that Could Not Be Fixed These URLs were unable to be fixed. Please review them to see if they can be manually resolved. * http://blog.listincomprehension.com/search/label/procket (200) with 1 occurrences could not be migrated: ([https](https://blog.listincomprehension.com/search/label/procket) result ClosedChannelException). * http://dozzie.jarowit.net/trac/wiki/TOML (200) with 1 occurrences could not be migrated: ([https](https://dozzie.jarowit.net/trac/wiki/TOML) result SSLHandshakeException). * http://dozzie.jarowit.net/trac/wiki/subproc (200) with 1 occurrences could not be migrated: ([https](https://dozzie.jarowit.net/trac/wiki/subproc) result SSLHandshakeException). * http://e2project.org (200) with 1 occurrences could not be migrated: ([https](https://e2project.org) result AnnotatedConnectException). * http://nitrogenproject.com/ (200) with 2 occurrences could not be migrated: ([https](https://nitrogenproject.com/) result ConnectTimeoutException). * http://proper.softlab.ntua.gr (200) with 1 occurrences could not be migrated: ([https](https://proper.softlab.ntua.gr) result SSLHandshakeException). * http://yaws.hyber.org (200) with 1 occurrences could not be migrated: ([https](https://yaws.hyber.org) result AnnotatedConnectException). * http://httpredir.debian.org/debian (302) with 1 occurrences could not be migrated: ([https](https://httpredir.debian.org/debian) result AnnotatedConnectException). * http://choven.ca (503) with 1 occurrences could not be migrated: ([https](https://choven.ca) result ConnectTimeoutException). # Fixed URLs ## Fixed But Review Recommended These URLs were fixed, but the https status was not OK. However, the https status was the same as the http request or http redirected to an https URL, so they were migrated. Your review is recommended. * http://fixprotocol.org/ (301) with 1 occurrences migrated to: https://fixtrading.org ([https](https://fixprotocol.org/) result SSLHandshakeException). * http://nsis.sourceforge.net/Setting_Environment_Variables (301) with 1 occurrences migrated to: https://nsis.sourceforge.io/Setting_Environment_Variables ([https](https://nsis.sourceforge.net/Setting_Environment_Variables) result AnnotatedConnectException). * http://erldb.org (UnknownHostException) with 1 occurrences migrated to: https://erldb.org ([https](https://erldb.org) result UnknownHostException). * http://www.rabbitmq.com/releases/rabbitmq-server/v (404) with 1 occurrences migrated to: https://www.rabbitmq.com/releases/rabbitmq-server/v ([https](https://www.rabbitmq.com/releases/rabbitmq-server/v) result 404). * http://www.rabbitmq.com/releases/rabbitmq-server/v% (404) with 1 occurrences migrated to: https://www.rabbitmq.com/releases/rabbitmq-server/v% ([https](https://www.rabbitmq.com/releases/rabbitmq-server/v%) result 404). ## Fixed Success These URLs were switched to an https URL with a 2xx status. While the status was successful, your review is still recommended. * http://cloudi.org/ with 27 occurrences migrated to: https://cloudi.org/ ([https](https://cloudi.org/) result 200). * http://erlware.org/ with 1 occurrences migrated to: https://erlware.org/ ([https](https://erlware.org/) result 200). * http://inaka.github.io/cowboy-trails/ with 1 occurrences migrated to: https://inaka.github.io/cowboy-trails/ ([https](https://inaka.github.io/cowboy-trails/) result 200). * http://ninenines.eu with 6 occurrences migrated to: https://ninenines.eu ([https](https://ninenines.eu) result 200). * http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html with 1 occurrences migrated to: https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html ([https](https://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html) result 200). * http://www.actordb.com/ with 2 occurrences migrated to: https://www.actordb.com/ ([https](https://www.actordb.com/) result 200). * http://www.cs.kent.ac.uk/projects/wrangler/Home.html with 1 occurrences migrated to: https://www.cs.kent.ac.uk/projects/wrangler/Home.html ([https](https://www.cs.kent.ac.uk/projects/wrangler/Home.html) result 200). * http://www.debian.org/doc/debian-policy/ with 2 occurrences migrated to: https://www.debian.org/doc/debian-policy/ ([https](https://www.debian.org/doc/debian-policy/) result 200). * http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ with 1 occurrences migrated to: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ ([https](https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/) result 200). * http://www.rabbitmq.com/ with 2 occurrences migrated to: https://www.rabbitmq.com/ ([https](https://www.rabbitmq.com/) result 200). * http://www.rabbitmq.com/debian/ with 3 occurrences migrated to: https://www.rabbitmq.com/debian/ ([https](https://www.rabbitmq.com/debian/) result 200). * http://www.rabbitmq.com/monitoring.html with 2 occurrences migrated to: https://www.rabbitmq.com/monitoring.html ([https](https://www.rabbitmq.com/monitoring.html) result 200). * http://www.rebar3.org with 1 occurrences migrated to: https://www.rebar3.org ([https](https://www.rebar3.org) result 200). * http://contributor-covenant.org with 1 occurrences migrated to: https://contributor-covenant.org ([https](https://contributor-covenant.org) result 301). * http://contributor-covenant.org/version/1/3/0/ with 1 occurrences migrated to: https://contributor-covenant.org/version/1/3/0/ ([https](https://contributor-covenant.org/version/1/3/0/) result 301). * http://inaka.github.com/apns4erl with 1 occurrences migrated to: https://inaka.github.com/apns4erl ([https](https://inaka.github.com/apns4erl) result 301). * http://inaka.github.com/edis/ with 1 occurrences migrated to: https://inaka.github.com/edis/ ([https](https://inaka.github.com/edis/) result 301). * http://lasp-lang.org/ with 1 occurrences migrated to: https://lasp-lang.org/ ([https](https://lasp-lang.org/) result 301). * http://saleyn.github.com/erlexec with 1 occurrences migrated to: https://saleyn.github.com/erlexec ([https](https://saleyn.github.com/erlexec) result 301). * http://www.debian-administration.org/articles/286 with 1 occurrences migrated to: https://www.debian-administration.org/articles/286 ([https](https://www.debian-administration.org/articles/286) result 301). * http://www.erlang.org/download.html with 1 occurrences migrated to: https://www.erlang.org/download.html ([https](https://www.erlang.org/download.html) result 301). * http://www.mozilla.org/MPL/ with 5 occurrences migrated to: https://www.mozilla.org/MPL/ ([https](https://www.mozilla.org/MPL/) result 301). * http://zhongwencool.github.io/observer_cli with 1 occurrences migrated to: https://zhongwencool.github.io/observer_cli ([https](https://zhongwencool.github.io/observer_cli) result 301).
2019-03-20 16:22:38 +08:00
## at https://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 GoPivotal, Inc.
2020-03-10 23:49:26 +08:00
## Copyright (c) 2007-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 <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="rabbitmq-server">
<version>1.0</version>
<longdesc lang="en">
Resource agent for RabbitMQ-server
</longdesc>
<shortdesc lang="en">Resource agent for RabbitMQ-server</shortdesc>
<parameters>
<parameter name="server" unique="0" required="0">
<longdesc lang="en">
The path to the rabbitmq-server script
</longdesc>
<shortdesc lang="en">Path to rabbitmq-server</shortdesc>
<content type="string" default="${OCF_RESKEY_server_default}" />
</parameter>
<parameter name="ctl" unique="0" required="0">
<longdesc lang="en">
The path to the rabbitmqctl script
</longdesc>
<shortdesc lang="en">Path to rabbitmqctl</shortdesc>
<content type="string" default="${OCF_RESKEY_ctl_default}" />
</parameter>
<parameter name="nodename" unique="0" required="0">
<longdesc lang="en">
The node name for rabbitmq-server
</longdesc>
<shortdesc lang="en">Node name</shortdesc>
<content type="string" default="${OCF_RESKEY_nodename_default}" />
</parameter>
<parameter name="ip" unique="0" required="0">
<longdesc lang="en">
The IP address for rabbitmq-server to listen on
</longdesc>
<shortdesc lang="en">IP Address</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="port" unique="0" required="0">
<longdesc lang="en">
The IP Port for rabbitmq-server to listen on
</longdesc>
<shortdesc lang="en">IP Port</shortdesc>
<content type="integer" default="" />
</parameter>
<parameter name="config_file" unique="0" required="0">
<longdesc lang="en">
Location of the config file (without the .config suffix)
</longdesc>
<shortdesc lang="en">Config file path (without the .config suffix)</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="log_base" unique="0" required="0">
<longdesc lang="en">
Location of the directory under which logs will be created
</longdesc>
<shortdesc lang="en">Log base path</shortdesc>
<content type="string" default="${OCF_RESKEY_log_base_default}" />
</parameter>
<parameter name="mnesia_base" unique="0" required="0">
<longdesc lang="en">
Location of the directory under which mnesia will store data
</longdesc>
<shortdesc lang="en">Mnesia base path</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="server_start_args" unique="0" required="0">
<longdesc lang="en">
Additional arguments provided to the server on startup
</longdesc>
<shortdesc lang="en">Server start arguments</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="pid_file" unique="0" required="0">
<longdesc lang="en">
Location of the file in which the pid will be stored
</longdesc>
<shortdesc lang="en">Pid file path</shortdesc>
<content type="string" default="${OCF_RESKEY_pid_file_default}" />
</parameter>
<parameter name="limit_nofile" unique="0" required="0">
<longdesc lang="en">
Soft and hard limit for NOFILE
</longdesc>
<shortdesc lang="en">NOFILE limit</shortdesc>
<content type="string" default="${OCF_RESKEY_limit_nofile_default}" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="600" />
<action name="stop" timeout="120" />
<action name="status" timeout="20" interval="10" />
<action name="monitor" timeout="20" interval="10" />
<action name="validate-all" timeout="30" />
<action name="meta-data" timeout="5" />
</actions>
</resource-agent>
END
}
rabbit_usage() {
cat <<END
usage: $0 {start|stop|status|monitor|validate-all|meta-data}
Expects to have a fully populated OCF RA-compliant environment set.
END
}
RABBITMQ_SERVER=$OCF_RESKEY_server
RABBITMQ_CTL=$OCF_RESKEY_ctl
RABBITMQ_NODENAME=$OCF_RESKEY_nodename
RABBITMQ_NODE_IP_ADDRESS=$OCF_RESKEY_ip
RABBITMQ_NODE_PORT=$OCF_RESKEY_port
RABBITMQ_CONFIG_FILE=$OCF_RESKEY_config_file
RABBITMQ_LOG_BASE=$OCF_RESKEY_log_base
RABBITMQ_MNESIA_BASE=$OCF_RESKEY_mnesia_base
RABBITMQ_SERVER_START_ARGS=$OCF_RESKEY_server_start_args
RABBITMQ_PID_FILE=$OCF_RESKEY_pid_file
RABBITMQ_LIMIT_NOFILE=$OCF_RESKEY_limit_nofile
[ ! -z $RABBITMQ_NODENAME ] && NODENAME_ARG="-n $RABBITMQ_NODENAME"
[ ! -z $RABBITMQ_NODENAME ] && export RABBITMQ_NODENAME
ensure_pid_dir () {
PID_DIR=`dirname ${RABBITMQ_PID_FILE}`
if [ ! -d ${PID_DIR} ] ; then
mkdir -p ${PID_DIR}
chown -R rabbitmq:rabbitmq ${PID_DIR}
chmod 755 ${PID_DIR}
fi
return $OCF_SUCCESS
}
remove_pid () {
rm -f ${RABBITMQ_PID_FILE}
rmdir `dirname ${RABBITMQ_PID_FILE}` || :
}
export_vars() {
[ ! -z $RABBITMQ_NODE_IP_ADDRESS ] && export RABBITMQ_NODE_IP_ADDRESS
[ ! -z $RABBITMQ_NODE_PORT ] && export RABBITMQ_NODE_PORT
[ ! -z $RABBITMQ_CONFIG_FILE ] && export RABBITMQ_CONFIG_FILE
[ ! -z $RABBITMQ_LOG_BASE ] && export RABBITMQ_LOG_BASE
[ ! -z $RABBITMQ_MNESIA_BASE ] && export RABBITMQ_MNESIA_BASE
[ ! -z $RABBITMQ_SERVER_START_ARGS ] && export RABBITMQ_SERVER_START_ARGS
[ ! -z $RABBITMQ_PID_FILE ] && ensure_pid_dir && export RABBITMQ_PID_FILE
}
set_limits() {
local current_limit=$(su rabbitmq -s /bin/sh -c "ulimit -n")
if [ ! -z $RABBITMQ_LIMIT_NOFILE -a $RABBITMQ_LIMIT_NOFILE -gt $current_limit ] ; then
ulimit -n $RABBITMQ_LIMIT_NOFILE
fi
}
rabbit_validate_partial() {
if [ ! -x $RABBITMQ_SERVER ]; then
ocf_log err "rabbitmq-server server $RABBITMQ_SERVER does not exist or is not executable";
exit $OCF_ERR_INSTALLED;
fi
if [ ! -x $RABBITMQ_CTL ]; then
ocf_log err "rabbitmq-server ctl $RABBITMQ_CTL does not exist or is not executable";
exit $OCF_ERR_INSTALLED;
fi
}
rabbit_validate_full() {
if [ ! -z $RABBITMQ_CONFIG_FILE ] && [ ! -e "${RABBITMQ_CONFIG_FILE}.config" ]; then
ocf_log err "rabbitmq-server config_file ${RABBITMQ_CONFIG_FILE}.config does not exist or is not a file";
exit $OCF_ERR_INSTALLED;
fi
if [ ! -z $RABBITMQ_LOG_BASE ] && [ ! -d $RABBITMQ_LOG_BASE ]; then
ocf_log err "rabbitmq-server log_base $RABBITMQ_LOG_BASE does not exist or is not a directory";
exit $OCF_ERR_INSTALLED;
fi
if [ ! -z $RABBITMQ_MNESIA_BASE ] && [ ! -d $RABBITMQ_MNESIA_BASE ]; then
ocf_log err "rabbitmq-server mnesia_base $RABBITMQ_MNESIA_BASE does not exist or is not a directory";
exit $OCF_ERR_INSTALLED;
fi
rabbit_validate_partial
return $OCF_SUCCESS
}
rabbit_status() {
rabbitmqctl_action "status"
}
rabbit_wait() {
rabbitmqctl_action "wait" $1
}
rabbitmqctl_action() {
local rc
local action
action=$@
ocf_run -q -info $RABBITMQ_CTL $NODENAME_ARG $action
rc=$?
case "$rc" in
0)
ocf_log debug "RabbitMQ server is running normally"
return $OCF_SUCCESS
;;
1|2|69)
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
# RabbitMQ requires high soft and hard limits for NOFILE
set_limits
setsid sh -c "$RABBITMQ_SERVER > ${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 $?