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)
feedback is appreciated! cheers, raoul -- ____________________________________________________________________ DI (FH) Raoul Bhatia M.Sc. email. r.bha...@ipax.at Technischer Leiter IPAX - Aloy Bhatia Hava OEG web. http://www.ipax.at Barawitzkagasse 10/2/2/11 email. off...@ipax.at 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 OCF resource agent. # # Author: Raoul Bhatia <r.bha...@ipax.at> : Original Author # License: GNU General Public License (GPL) # Note: if you want to run multiple postfix instances, plese see # # 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 exit $OCF_SUCCESS } 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=$(sed 's/ //g' ${queue}/pid/master.pid) # what directory does the executable live in. stupid prelink systems. dir=$(ls -l /proc/$pid/exe 2>/dev/null | sed 's/.* -> //; s/\/[^\/]*$//') if [ "X$dir" = "X/usr/lib/postfix" ]; then if isRunning $pid; then # @TODO why does "true" not work here? #true return 0 fi 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." exit $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 exit $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." exit $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 exit $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 exit $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 if [ -d "$config_dir" ]; then # save OPTION_CONFIG_DIR seperatly OPTION_CONFIG_DIR="-c $config_dir" OPTIONS=$OPTION_CONFIG_DIR else ocf_log err "Postfix configuration directory '$config_dir' does not exist." exit $OCF_ERR_GENERIC fi fi if [ "x$parameters" != "x" ]; then OPTIONS="$OPTIONS $parameters" fi case $1 in start) postfix_validate_all postfix_start ;; stop) postfix_validate_all postfix_stop ;; reload) postfix_validate_all postfix_reload ;; status) postfix_validate_all 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_validate_all postfix_monitor exit $? ;; validate-all) postfix_validate_all exit $? ;; meta-data) meta_data ;; usage) usage exit $OCF_SUCCESS ;; *) usage exit $OCF_ERR_UNIMPLEMENTED ;; esac
_______________________________________________________ Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev Home Page: http://linux-ha.org/