Dejan Muhamedagic wrote:
> Hi,
>
> On Thu, May 28, 2009 at 08:33:15PM +0200, Raoul Bhatia [IPAX] wrote:
>> Raoul Bhatia [IPAX] wrote:
>>> hi,
>>>
>>> Raoul Bhatia [IPAX] wrote:
>>>> hi,
>>>>
>>>> please find my postfix ocf ra attached. it is possible to use it
>>>> with multiple postfix instances, if the administrator honors all
>>>> pre-requirements (queue_directory, data_directory,
>>>> alternate_config_directories)
>>> i found some problems with this ra when you move data/config_dir/queue
>>> to a seperate partition that is also mounted by pacemaker.
>>>
>>> this are basically the same issues we encountered with the mysql ra,
>>> and therefore i used this ra as a basis for further improvements.
>>>
>>> i will resend the updated postfix ra within the next hour.
>> please find my current version attached.
>
> Darn. I knew I should've waited a while :)
ups ;) i currently use the "release fast, release often" paradigm.
i am too much of a perfectionist otherwise ;)
>> i also added a link to a page where i describe how to configure multiple
>> postfix instances on *one* server.
>
> That's great.
>
> Some comments (in a diff form):
>
> IsRunning()
> {
> + # Could the master process become zombie?
> kill -0 "$1" 2>/dev/null
> }
added in a more appropriate place. do not know about that thou. i'm just
doing the thing the initscript on debian 5.0 does.
> ...
> - dir=$(ls -l /proc/$pid/exe 2>/dev/null | sed 's/.* -> //;
> s/\/[^\/]*$//')
> - if [ "X$dir" = "X/usr/lib/postfix" ]; then
> + # Linux specific!
> + #dir=$(ls -l /proc/$pid/exe 2>/dev/null | sed 's/.* ->
> //; s/\/[^\/]*$/
> /')
> + # Is this 'if' necessary? What if the
> + # installation/package is different?
> + #if [ "X$dir" = "X/usr/lib/postfix" ]; then
that was simply a c/p. i removed this part now as i do not see what this
should help/do at this position.
> Also, most exits in validate_all should be OCF_ERR_INSTALLED. I
> think.
please feel free to change these values. i am not sure where (not) to
use OCF_ERR_INSTALLED.
> Otherwise, a very fine job.
thanks. updated version enclosed.
have a nice weekend,
raoul
--
____________________________________________________________________
DI (FH) Raoul Bhatia M.Sc. email. [email protected]
Technischer Leiter
IPAX - Aloy Bhatia Hava OEG web. http://www.ipax.at
Barawitzkagasse 10/2/2/11 email. [email protected]
1190 Wien tel. +43 1 3670030
FN 277995t HG Wien fax. +43 1 3670030 15
____________________________________________________________________
#!/bin/sh
#
# Resource script for Postfix
#
# Description: Manages Postfix as an OCF resource in
# an high-availability setup.
#
# Tested with postfix 2.5.5 on Debian 5.0.
# Based on the mysql-proxy and mysql OCF resource agents.
#
# Author: Raoul Bhatia <[email protected]> : 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
# * /usr/sbin/ocf-tester -n post1 -o binary="/usr/sbin/postfix"
# -o config_dir="" /usr/lib/ocf/resource.d/heartbeat/postfix
# * /usr/sbin/ocf-tester -n post1 -o binary="/usr/sbin/postfix"
# -o config_dir="/root/postfix/" /usr/lib/ocf/resource.d/heartbeat/postfix
#
#
# OCF parameters:
# OCF_RESKEY_binary
# OCF_RESKEY_config_dir
# OCF_RESKEY_parameters
#
##########################################################################
# Initialization:
. ${OCF_ROOT}/resource.d/heartbeat/.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.
Tested with Postfix 2.5.5 on Debian 5.0.
</longdesc>
<shortdesc lang="en">OCF Resource Agent compliant Postfix script.</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="90" />
<action name="stop" timeout="100" />
<action name="reload" timeout="100" />
<action name="monitor" depth="10" timeout="20s" interval="60s" start-delay="0"
/>
<action name="validate-all" timeout="30s" />
<action name="meta-data" timeout="5s" />
</actions>
</resource-agent>
END
}
isRunning()
{
kill -0 "$1" 2>/dev/null
}
# running() has been copied from debian's init script. we enhanced it a bit
running() {
queue=$(postconf $OPTION_CONFIG_DIR -h queue_directory 2>/dev/null || echo
/var/spool/postfix)
if [ -f ${queue}/pid/master.pid ]; then
pid_dir=$(postconf $OPTION_CONFIG_DIR -h process_id_directory
2>/dev/null)
pid=$(sed 's/ //g' ${queue}/${pid_dir}/master.pid)
# @TODO Could the master process become zombie?
if isRunning $pid; then
# @TODO why does "true" not work here?
#true
return $OCF_SUCCESS
fi
fi
# Postfix is not running
false
}
postfix_status()
{
running
}
postfix_start()
{
# if Postfix is running return success
if postfix_status; then
ocf_log info "Postfix already running."
exit $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
exit $OCF_ERR_GENERIC
fi
exit $OCF_SUCCESS
}
postfix_stop()
{
if postfix_status; then
$binary $OPTIONS stop >/dev/null 2>&1
ret=$?
if [ $ret -ne 0 ]; then
ocf_log err "Postfix returned an error while stopping." $ret
exit $OCF_ERR_GENERIC
fi
# grant some time for shutdown and recheck
sleep 1
if postfix_status; then
ocf_log err "Postfix failed to stop."
exit $OCF_ERR_GENERIC
fi
fi
exit $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 binary exists and can be executed
if [ ! -x "$binary" ]; then
ocf_log err "Postfix binary '$binary' does not exist or cannot be
executed."
return $OCF_ERR_GENERIC
fi
# 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_GENERIC
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_GENERIC
fi
fi
# check spool/queue directory
queue=$(postconf $OPTION_CONFIG_DIR -h queue_directory 2>/dev/null || echo
/var/spool/postfix)
if [ ! -d "$queue" ]; then
ocf_log err "Postfix spool/queue directory '$queue' does not exist."
$ret
return $OCF_ERR_GENERIC
fi
# 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
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
# save OPTION_CONFIG_DIR seperatly
OPTION_CONFIG_DIR="-c $config_dir"
OPTIONS=$OPTION_CONFIG_DIR
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
;;
stop) postfix_stop
;;
reload) postfix_reload
;;
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
;;
monitor) postfix_monitor
exit $?
;;
validate-all) exit $OCF_SUCCESS
;;
*) usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/