From 0a93dca147a5efbe7e5d6c6925873d7c99cfc1a7 Mon Sep 17 00:00:00 2001 From: Alberto Planas Date: Wed, 29 Mar 2017 22:10:53 +0200 Subject: [PATCH 1/3] OCF RA: Add new limit_nofile parameter to rabbitmq-server OCF RA This enables to change the limit of open files, as the default on distributions is usually too low for rabbitmq. Default is 65535. --- scripts/rabbitmq-server.ocf | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/scripts/rabbitmq-server.ocf b/scripts/rabbitmq-server.ocf index 804e654..7190d65 100755 --- a/scripts/rabbitmq-server.ocf +++ b/scripts/rabbitmq-server.ocf @@ -30,6 +30,7 @@ ## OCF_RESKEY_mnesia_base ## OCF_RESKEY_server_start_args ## OCF_RESKEY_pid_file +## OCF_RESKEY_limit_nofile ####################################################################### # Initialization: @@ -44,11 +45,13 @@ 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 < + + +Soft and hard limit for NOFILE + +NOFILE limit + + + @@ -176,6 +187,7 @@ 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 @@ -204,6 +216,10 @@ export_vars() { [ ! -z $RABBITMQ_PID_FILE ] && ensure_pid_dir && export RABBITMQ_PID_FILE } +set_limits() { + [ ! -z $RABBITMQ_LIMIT_NOFILE ] && ulimit -n $RABBITMQ_LIMIT_NOFILE +} + rabbit_validate_partial() { if [ ! -x $RABBITMQ_SERVER ]; then ocf_log err "rabbitmq-server server $RABBITMQ_SERVER does not exist or is not executable"; @@ -276,6 +292,9 @@ rabbit_start() { 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. From 89d65b51aa7232207c29dd3010d669d4b54901f4 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Wed, 29 Mar 2017 22:20:25 +0200 Subject: [PATCH 2/3] OCF RA: Add new limit_nofile parameter to rabbitmq-server-ha OCF RA This enables to change the limit of open files, as the default on distributions is usually too low for rabbitmq. Default is 65535. --- scripts/rabbitmq-server-ha.ocf | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/scripts/rabbitmq-server-ha.ocf b/scripts/rabbitmq-server-ha.ocf index 49f3af7..2d5d660 100755 --- a/scripts/rabbitmq-server-ha.ocf +++ b/scripts/rabbitmq-server-ha.ocf @@ -50,6 +50,7 @@ OCF_RESKEY_max_rabbitmqctl_timeouts_default=3 OCF_RESKEY_policy_file_default="/usr/local/sbin/set_rabbitmq_policy" OCF_RESKEY_rmq_feature_health_check_default=true OCF_RESKEY_rmq_feature_local_list_queues_default=true +OCF_RESKEY_limit_nofile_default=65535 : ${HA_LOGTAG="lrmd"} : ${HA_LOGFACILITY="daemon"} @@ -74,6 +75,7 @@ OCF_RESKEY_rmq_feature_local_list_queues_default=true : ${OCF_RESKEY_policy_file=${OCF_RESKEY_policy_file_default}} : ${OCF_RESKEY_rmq_feature_health_check=${OCF_RESKEY_rmq_feature_health_check_default}} : ${OCF_RESKEY_rmq_feature_local_list_queues=${OCF_RESKEY_rmq_feature_local_list_queues_default}} +: ${OCF_RESKEY_limit_nofile=${OCF_RESKEY_limit_nofile_default}} ####################################################################### @@ -332,6 +334,14 @@ stopped/demoted. + + +Soft and hard limit for NOFILE + +NOFILE limit + + + $EXTENDED_OCF_PARAMS @@ -556,6 +566,10 @@ now() { date -u +%s } +set_limits() { + [ ! -z $OCF_RESKEY_limit_nofile ] && ulimit -n $OCF_RESKEY_limit_nofile +} + master_score() { local LH="${LL} master_score():" local score=$1 @@ -1166,6 +1180,9 @@ start_beam_process() { [ -f /etc/default/rabbitmq-server ] && . /etc/default/rabbitmq-server + # RabbitMQ requires high soft and hard limits for NOFILE + set_limits + # run beam process command="${OCF_RESKEY_binary} >> \"${OCF_RESKEY_log_dir}/startup_log\" 2>/dev/null" RABBITMQ_NODE_ONLY=1 su rabbitmq -s /bin/sh -c "${command}"& From 73080ac78348916635e45c2f62aa7d86c0765b42 Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Tue, 4 Apr 2017 15:13:52 +0200 Subject: [PATCH 3/3] OCF RA: Only set limit for open files when higher than current value This allows to set the limit via some other way. --- scripts/rabbitmq-server-ha.ocf | 5 ++++- scripts/rabbitmq-server.ocf | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/scripts/rabbitmq-server-ha.ocf b/scripts/rabbitmq-server-ha.ocf index 2d5d660..ea07916 100755 --- a/scripts/rabbitmq-server-ha.ocf +++ b/scripts/rabbitmq-server-ha.ocf @@ -567,7 +567,10 @@ now() { } set_limits() { - [ ! -z $OCF_RESKEY_limit_nofile ] && ulimit -n $OCF_RESKEY_limit_nofile + local current_limit=$(su $OCF_RESKEY_username -s /bin/sh -c "ulimit -n") + if [ ! -z $OCF_RESKEY_limit_nofile -a $OCF_RESKEY_limit_nofile -gt $current_limit ] ; then + ulimit -n $OCF_RESKEY_limit_nofile + fi } master_score() { diff --git a/scripts/rabbitmq-server.ocf b/scripts/rabbitmq-server.ocf index 7190d65..dbca06f 100755 --- a/scripts/rabbitmq-server.ocf +++ b/scripts/rabbitmq-server.ocf @@ -217,7 +217,10 @@ export_vars() { } set_limits() { - [ ! -z $RABBITMQ_LIMIT_NOFILE ] && ulimit -n $RABBITMQ_LIMIT_NOFILE + 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() {