Page MenuHomeClusterLabs Projects

No OneTemporary

diff --git a/heartbeat/postfix b/heartbeat/postfix
index 427734cd5..c88393b78 100755
--- a/heartbeat/postfix
+++ b/heartbeat/postfix
@@ -1,382 +1,382 @@
#!/bin/sh
#
# Resource script for Postfix
#
# Description: Manages Postfix as an OCF resource in
# an high-availability setup.
#
# Author: Raoul Bhatia <r.bhatia@ipax.at> : Original Author
# License: GNU General Public License (GPL)
# Note: If you want to run multiple Postfix instances, please see
# http://amd.co.at/adminwiki/Postfix#Adding_a_Second_Postfix_Instance_on_one_Server
# http://www.postfix.org/postconf.5.html
#
#
# usage: $0 {start|stop|reload|status|monitor|validate-all|meta-data}
#
# The "start" arg starts a Postfix instance
#
# The "stop" arg stops it.
#
#
# Test via
# * /usr/sbin/ocf-tester -n post1 /usr/lib/ocf/resource.d/heartbeat/postfix; echo $?
# * /usr/sbin/ocf-tester -n post2 -o binary="/usr/sbin/postfix" \
# -o config_dir="" /usr/lib/ocf/resource.d/heartbeat/postfix; echo $?
# * /usr/sbin/ocf-tester -n post3 -o binary="/usr/sbin/postfix" \
# -o config_dir="/etc/postfix" /usr/lib/ocf/resource.d/heartbeat/postfix; echo $?
# * /usr/sbin/ocf-tester -n post4 -o binary="/usr/sbin/postfix" \
# -o config_dir="/root/postfix/" /usr/lib/ocf/resource.d/heartbeat/postfix; echo $?
#
#
# OCF parameters:
# OCF_RESKEY_binary
# OCF_RESKEY_config_dir
# OCF_RESKEY_parameters
#
##########################################################################
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
: ${OCF_RESKEY_binary="/usr/sbin/postfix"}
: ${OCF_RESKEY_config_dir=""}
: ${OCF_RESKEY_parameters=""}
USAGE="Usage: $0 {start|stop|reload|status|monitor|validate-all|meta-data}";
##########################################################################
usage() {
echo $USAGE >&2
}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="postfix">
<version>0.1</version>
<longdesc lang="en">
This script manages Postfix as an OCF resource in a high-availability setup.
</longdesc>
<shortdesc lang="en">Manages a highly available Postfix mail server instance</shortdesc>
<parameters>
<parameter name="binary" unique="0" required="0">
<longdesc lang="en">
Full path to the Postfix binary.
For example, "/usr/sbin/postfix".
</longdesc>
<shortdesc lang="en">Full path to Postfix binary</shortdesc>
<content type="string" default="/usr/sbin/postfix" />
</parameter>
<parameter name="config_dir" unique="1" required="0">
<longdesc lang="en">
Full path to a Postfix configuration directory.
For example, "/etc/postfix".
</longdesc>
<shortdesc lang="en">Full path to configuration directory</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="parameters" unique="0" required="0">
<longdesc lang="en">
The Postfix daemon may be called with additional parameters.
Specify any of them here.
</longdesc>
<shortdesc lang="en"></shortdesc>
<content type="string" default="" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="20s" />
<action name="stop" timeout="20s" />
<action name="reload" timeout="20s" />
<action name="monitor" depth="0" timeout="20s" interval="60s" />
<action name="validate-all" timeout="20s" />
<action name="meta-data" timeout="5s" />
</actions>
</resource-agent>
END
}
running() {
# run Postfix status
$binary $OPTION_CONFIG_DIR status >/dev/null 2>&1
}
postfix_status()
{
running
}
postfix_start()
{
# if Postfix is running return success
if postfix_status; then
ocf_log info "Postfix already running."
return $OCF_SUCCESS
fi
# start Postfix
$binary $OPTIONS start >/dev/null 2>&1
ret=$?
if [ $ret -ne 0 ]; then
ocf_log err "Postfix returned error." $ret
return $OCF_ERR_GENERIC
fi
# grant some time for startup/forking the sub processes
sleep 2
# initial monitoring action
OCF_CHECK_LEVEL=10
running
- rc=$?
- if [ $ret != $OCF_SUCCESS ]; then
+ ret=$?
+ if [ $ret -ne $OCF_SUCCESS ]; then
ocf_log err "Postfix failed initial monitor action." $ret
return $OCF_ERR_GENERIC
fi
ocf_log info "Postfix started."
return $OCF_SUCCESS
}
postfix_stop()
{
# if Postfix is not running return success
if ! postfix_status; then
ocf_log info "Postfix already stopped."
return $OCF_SUCCESS
fi
# stop Postfix
$binary $OPTIONS stop >/dev/null 2>&1
ret=$?
if [ $ret -ne 0 ]; then
ocf_log err "Postfix returned an error while stopping." $ret
return $OCF_ERR_GENERIC
fi
# grant some time for shutdown and recheck 5 times
for i in 1 2 3 4 5; do
if postfix_status; then
sleep 1
fi
done
# escalate to abort if we did not stop by now
# @TODO shall we loop here too?
if postfix_status; then
ocf_log err "Postfix failed to stop. Escalating to 'abort'."
$binary $OPTIONS abort >/dev/null 2>&1; ret=$?
sleep 5
# postfix abort did not succeed
if postfix_status; then
ocf_log err "Postfix failed to abort."
return $OCF_ERR_GENERIC
fi
fi
ocf_log info "Postfix stopped."
return $OCF_SUCCESS
}
postfix_reload()
{
if postfix_status; then
ocf_log info "Reloading Postfix."
$binary $OPTIONS reload
fi
}
postfix_monitor()
{
if postfix_status; then
return $OCF_SUCCESS
fi
return $OCF_NOT_RUNNING
}
postfix_validate_all()
{
# check that the Postfix binaries exist and can be executed
check_binary "$binary"
check_binary "postconf"
# check config_dir and alternate_config_directories parameter
if [ "x$config_dir" != "x" ]; then
if [ ! -d "$config_dir" ]; then
ocf_log err "Postfix configuration directory '$config_dir' does not exist." $ret
return $OCF_ERR_INSTALLED
fi
alternate_config_directories=`postconf -h alternate_config_directories 2>/dev/null | grep "$config_dir/\?"`
if [ "x$alternate_config_directories" = "x" ]; then
ocf_log err "Postfix main configuration must contain correct 'alternate_config_directories' parameter."
return $OCF_ERR_INSTALLED
fi
fi
# check spool/queue and data directories
# this is required because "postfix check" does not catch all errors
queue_dir=`postconf $OPTION_CONFIG_DIR -h queue_directory 2>/dev/null`
data_dir=`postconf $OPTION_CONFIG_DIR -h data_directory 2>/dev/null`
for dir in "$queue_dir" "$data_dir"; do
if [ ! -d "$dir" ]; then
ocf_log err "Postfix directory '$queue_dir' does not exist." $ret
return $OCF_ERR_INSTALLED
fi
done
# check permissions
user=`postconf $OPTION_CONFIG_DIR -h mail_owner 2>/dev/null`
for dir in "$data_dir"; do
if ! su -s /bin/sh - $user -c "test -w $dir"; then
ocf_log err "Directory '$dir' is not writable by user '$user'."
exit $OCF_ERR_PERM;
fi
done
# run Postfix internal check
$binary $OPTIONS check >/dev/null 2>&1
ret=$?
if [ $ret -ne 0 ]; then
ocf_log err "Postfix 'check' failed." $ret
return $OCF_ERR_GENERIC
fi
# grant some time for startup/forking the sub processes
sleep 2
# initial monitoring action
OCF_CHECK_LEVEL=10
running
- rc=$?
- if [ $ret != $OCF_SUCCESS ]; then
+ ret=$?
+ if [ $ret -ne $OCF_SUCCESS ]; then
ocf_log err "Postfix failed initial monitor action." $ret
return $OCF_ERR_GENERIC
fi
ocf_log info "Postfix started."
return $OCF_SUCCESS
}
#
# Main
#
if [ $# -ne 1 ]; then
usage
exit $OCF_ERR_ARGS
fi
binary=$OCF_RESKEY_binary
config_dir=$OCF_RESKEY_config_dir
parameters=$OCF_RESKEY_parameters
# debugging stuff
#echo OCF_RESKEY_binary=$OCF_RESKEY_binary >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_config_dir=$OCF_RESKEY_config_dir >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_parameters=$OCF_RESKEY_parameters >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
# build Postfix options string *outside* to access from each method
OPTIONS=''
OPTION_CONFIG_DIR=''
# check if the Postfix config_dir exist
if [ "x$config_dir" != "x" ]; then
# check for postconf binary
check_binary "postconf"
# remove all trailing slashes to ease "postconf alternate_config_directories" match
config_dir=`echo $config_dir | sed 's/\/*$//'`
# reset config_dir if it equals Postfix's default config_directory
postconf -h config_directory 2>/dev/null | grep "^$config_dir/\?$"
if [ $? -eq 0 ]; then
config_dir=""
fi
# set OPTIONS if config_dir is still set
# save OPTION_CONFIG_DIR seperatly
if [ "x$config_dir" != "x" ]; then
OPTION_CONFIG_DIR="-c $config_dir"
OPTIONS=$OPTION_CONFIG_DIR
fi
fi
if [ "x$parameters" != "x" ]; then
OPTIONS="$OPTIONS $parameters"
fi
case $1 in
meta-data) meta_data
exit $OCF_SUCCESS
;;
usage|help) usage
exit $OCF_SUCCESS
;;
esac
postfix_validate_all
ret=$?
#echo "debug[$1:$ret]"
LSB_STATUS_STOPPED=3
if [ $ret -ne $OCF_SUCCESS ]; then
case $1 in
stop) exit $OCF_SUCCESS ;;
monitor) exit $OCF_NOT_RUNNING;;
status) exit $LSB_STATUS_STOPPED;;
*) exit $ret;;
esac
fi
case $1 in
monitor) postfix_monitor
exit $?
;;
start) postfix_start
exit $?
;;
stop) postfix_stop
exit $?
;;
reload) postfix_reload
exit $?
;;
status) if postfix_status; then
ocf_log info "Postfix is running."
exit $OCF_SUCCESS
else
ocf_log info "Postfix is stopped."
exit $OCF_NOT_RUNNING
fi
;;
validate-all) exit $OCF_SUCCESS
;;
*) usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac

File Metadata

Mime Type
text/x-diff
Expires
Tue, Feb 25, 6:12 AM (1 d, 18 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1464702
Default Alt Text
(10 KB)

Event Timeline