Hello, I've tried to write an OCF ressource agent in order to manage by the heartbeat way a dovecot server. It seems to work fine.
This kind of script could be found in the directory on a CentOS release 5.2 : /usr/lib/ocf/resource.d/ If the attachement isn't working, I've cut and paste the script here : http://www-sop.inria.fr/members/Mathieu.Kretchner/dotclear/index.php/2008/12/19/5-heartbeat-dovecot
#!/bin/bash -p # # $Id: ha-dovecot,v 1.2 2008/12/19 09:32:27 mkretchn Exp $ #---+ Notes ## Cf: http://linux-ha.org/OCFResourceAgent ## http://www.opencf.org/cgi-bin/viewcvs.cgi/specs/ra/resource-agent-api.txt?rev=HEAD ## /usr/share/heartbeat/crm.dtd #---+ Contexte OCF # Pour execution (status monitor) hors controle de heartbeat if [ -z "$OCF_ROOT" ]; then OCF_ROOT=/usr/lib/ocf fi source ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs #---+ Actions usage () { echo "Usage: $0 {start|stop|monitor|meta-data|validate-all}" } meta_data () { local rev="$Revision: 1.2 $" rev=${rev#* }; rev=${rev% *} cat <<EOF <?xml version="1.0"?> <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd"> <resource-agent name="ha-dovecot"> <version>$rev</version> <longdesc lang="en"> dovecot </longdesc> <shortdesc lang="en">dovecot RA</shortdesc> <actions> <action name="start" timeout="1m"/> <action name="stop" timeout="1m"/> <action name="monitor" interval="30s" timeout="20s" start-delay="1m" /> <action name="validate-all" timeout="5s" /> <action name="meta-data" timeout="5s" /> </actions> </resource-agent> EOF } exec="/usr/sbin/dovecot" bin=$(basename $exec) config="/etc/dovecot.conf" start () { [ -x $exec ] || { echo >&2 "** $exec not executable" return $OCF_ERR_GENERIC } [ -f $config ] || { echo >&2 "** $config doesn't exist" return $OCF_ERR_GENERIC } local pid=$(dovecot_pid) if [ "$pid" ]; then echo >&2 "dovecot already running" return $OCF_SUCCESS elif $exec; then local pid=$(dovecot_pid) if [ "$pid" ]; then return $OCF_SUCCESS else echo >&2 "** no dovecot pid" return $OCF_ERR_GENERIC fi else echo >&2 "** $bin fails to start" return $OCF_ERR_GENERIC fi } stop () { local pid=$(dovecot_pid) echo $pid if [ "$pid" ]; then if killpid $pid; then return $OCF_SUCCESS else echo >&2 "** killpid $pid: fails" return $OCF_ERR_GENERIC fi else return $OCF_SUCCESS fi } status () { # Seems to not be used by heartbeat return } monitor () { local pid=$(dovecot_pid) if [ "$pid" ]; then MYSTATUS=`echo ". logout" | nc localhost 143 | grep "ready" | wc -l` if [ "$MYSTATUS" -eq "1" ]; then return $OCF_SUCCESS else return $OCF_ERR_GENERIC fi else return $OCF_NOT_RUNNING fi } validate_all () { return } #---+ Utilitaires dovecot_pid () { pidof $bin } # Check if $pid (could be plural) are running checkpid() { local i for i in $* ; do [ -d "/proc/$i" ] && return 0 done return 1 } killpid () { # Repris depuis /etc/init.d/functions:killproc # killpid <pid> [<delai en secondes>] # FIXME: faire faire ca par lps -k ou autre option? local pid=$1 local delay=${2:-3} # Succes si pas de process checkpid $pid || return 0 # TERM first, then KILL if not dead kill -TERM $pid usleep 100000 if checkpid $pid && sleep 1 && checkpid $pid && sleep $delay && checkpid $pid ; then kill -KILL $pid usleep 100000 fi if checkpid $pid; then return 1 else return 0 fi } #---+ Debug [[ $0 == *bash ]] && return #---+ Main if [ $# -eq 0 ] then usage exit $OCF_ERR_ARGS fi # PATH source /usr/local/bashutil/autoload_lib autoload_lib /usr/local/bashutil/lib/batch case $1 in start) start ;; stop) stop ;; status) status ;; monitor) monitor ;; meta-data) meta_data;; validate-all ) validate_all;; *) usage exit $OCF_ERR_UNIMPLEMENTED ;; esac
begin:vcard fn:Mathieu Kretchner n:Kretchner;Mathieu org:INRIA;Syslog adr;dom:;;2004 route des lucioles - BP93;Sophia Antipolis;;06902 CEDEX email;internet:mathieu.kretch...@sophia.inria.fr tel;work:04 92 38 76 67 x-mozilla-html:FALSE version:2.1 end:vcard