Skip to content

Instantly share code, notes, and snippets.

@skbly7
Created September 21, 2016 04:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skbly7/49d034c3db7aff635187e595c7a0eb5a to your computer and use it in GitHub Desktop.
Save skbly7/49d034c3db7aff635187e595c7a0eb5a to your computer and use it in GitHub Desktop.
Mirror for Zimbra HA pacemaker. (ocf::btactic:zimbra)
#!/bin/sh
#
# Resource script for Zimbra
#
# Description: Manages Zimbra as an OCF resource in
# an high-availability setup.
#
# Author: Adrian Gibanel
# <adrian.gibanel@btactic.com> : Original Author
# License: GNU General Public License (GPL)
# Note: Aimed at an active/passive cluster originally
# Inspired from postfix OCF script
# Inspired from Ubuntu LSB script.
# Not sure it will work
# for other distros without modifying
#
#
# usage: $0 {start|stop|reload|status
# |monitor|validate-all|meta-data}
#
# The "start" arg starts Zimbra
#
# The "stop" arg stops it.
#
# 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="zmcontrol"}
: ${OCF_RESKEY_zimbra_dir="/opt/zimbra"}
: ${OCF_RESKEY_zimbra_user="zimbra"}
: ${OCF_RESKEY_zimbra_group="zimbra"}
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="zimbra">
<version>0.1</version>
<longdesc lang="en">
This script manages Zimbra as an
OCF resource in a high-availability setup.
</longdesc>
<shortdesc lang="en">
Manages a highly available Zimbra mail server instance
</shortdesc>
<parameters>
<parameter name="binary" unique="0" required="0">
<longdesc lang="en">
Short name to the Zimbra control script.
For example, "zmcontrol".
</longdesc>
<shortdesc lang="en">
Short name to the Zimbra control script</shortdesc>
<content type="string" default="zmcontrol" />
</parameter>
<parameter name="zimbra_dir" unique="1" required="0">
<longdesc lang="en">
Full path to Zimbra directory.
For example, "/opt/zimbra".
</longdesc>
<shortdesc lang="en">
Full path to Zimbra directory</shortdesc>
<content type="string" default="/opt/zimbra" />
</parameter>
<parameter name="zimbra_user" unique="1" required="0">
<longdesc lang="en">
Zimbra username.
For example, "zimbra".
</longdesc>
<shortdesc lang="en">Zimbra username</shortdesc>
<content type="string" default="zimbra" />
</parameter>
<parameter name="zimbra_group"
unique="1" required="0">
<longdesc lang="en">
Zimbra group.
For example, "zimbra".
</longdesc>
<shortdesc lang="en">Zimbra group</shortdesc>
<content type="string" default="zimbra" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="360s" />
<action name="stop" timeout="360s" />
<action name="reload" timeout="360s" />
<action name="monitor" depth="0" timeout="40s"
interval="60s" />
<action name="validate-all" timeout="360s" />
<action name="meta-data" timeout="5s" />
</actions>
</resource-agent>
END
}
command()
{
if [ -f ${zimbra_dir}/redolog/redo.log ]; then
chown -f ${zimbra_user}:${zimbra_group} \
${zimbra_dir}/redolog/redo.log
fi
su - ${zimbra_user} -c "${binary} $1 </dev/null"
}
running() {
# run Zimbra status
command status
}
zimbra_status()
{
running
}
zimbra_start()
{
# if Zimbra is running return success
if zimbra_status; then
ocf_log info "Zimbra already running."
return $OCF_SUCCESS
fi
# start Zimbra
command startup
ret=$?
if [ -d /var/lock/subsys -a $ret -eq 0 ]; then
touch /var/lock/subsys/zimbra
fi
if [ $ret -ne 0 ]; then
ocf_log err "Zimbra returned error." $ret
return $OCF_ERR_GENERIC
fi
# grant some time for
# startup/forking the sub processes
sleep 2
# initial monitoring action
running
ret=$?
if [ $ret -ne $OCF_SUCCESS ]; then
ocf_log err "Zimbra failed \
initial monitor action." $ret
return $OCF_ERR_GENERIC
fi
ocf_log info "Zimbra started."
return $OCF_SUCCESS
}
zimbra_stop()
{
# if Zimbra is not running return success
if ! zimbra_status; then
ocf_log info "Zimbra already stopped."
return $OCF_SUCCESS
fi
# stop Zimbra
command shutdown
ret=$?
if [ -d /var/lock/subsys -a $ret -eq 0 ]; then
rm -f /var/lock/subsys/zimbra
fi
if [ $ret -ne 0 ]; then
ocf_log err "Zimbra 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 zimbra_status; then
sleep 1
fi
done
# escalate to abort if we did not stop by now
# @TODO shall we loop here too?
if zimbra_status; then
ocf_log err "Zimbra failed to stop. \
Escalating to 'abort'."
ORPHANED=`ps -u ${zimbra_user} -o \
"pid="` && kill -9 $ORPHANED 2>&1
ret=$?
sleep 10
# zimbra abort did not succeed
if zimbra_status; then
ocf_log err "Zimbra failed to abort."
return $OCF_ERR_GENERIC
fi
fi
ocf_log info "Zimbra stopped."
return $OCF_SUCCESS
}
zimbra_reload()
{
if zimbra_status; then
ocf_log info "Reloading Zimbra."
command reload
fi
}
zimbra_monitor()
{
if zimbra_status; then
return $OCF_SUCCESS
fi
return $OCF_NOT_RUNNING
}
zimbra_validate_all()
{
# check zimbra_dir parameter
if [ ! -d "$zimbra_dir" ]; then
ocf_log err "Zimbra directory \
'$config_dir' does not exist." $ret
return $OCF_ERR_INSTALLED
fi
# check that the Zimbra binaries
# exist and can be executed
if ! have_binary \
"${zimbra_dir}/bin/${binary}" ; then
return $OCF_ERR_INSTALLED
fi
# check permissions
user=${zimbra_user}
zimbra_writable_dirs="${zimbra_dir}/conf"
for dir in "$zimbra_writable_dirs"; 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
return $OCF_SUCCESS
}
#
# Main
#
if [ $# -ne 1 ]; then
usage
exit $OCF_ERR_ARGS
fi
binary=$OCF_RESKEY_binary
zimbra_dir=$OCF_RESKEY_zimbra_dir
zimbra_user=$OCF_RESKEY_zimbra_user
zimbra_group=$OCF_RESKEY_zimbra_group
parameters=$OCF_RESKEY_parameters
# debugging stuff
#echo OCF_RESKEY_binary=$OCF_RESKEY_binary \
# >> /tmp/prox_conf_$OCF_RESOURCE_INSTANCE
#echo OCF_RESKEY_binary=$OCF_RESKEY_zimbra_dir \
#>> /tmp/prox_conf_$OCF_RESKEY_zimbra_dir
#echo OCF_RESKEY_binary=$OCF_RESKEY_zimbra_user \
#>> /tmp/prox_conf_$OCF_RESKEY_zimbra_user
#echo OCF_RESKEY_binary=$OCF_RESKEY_zimbra_group \
#>> /tmp/prox_conf_$OCF_RESKEY_zimbra_group
#echo OCF_RESKEY_binary=$OCF_RESKEY_parameters \
#>> /tmp/prox_conf_$OCF_RESKEY_parameters
# build Zimbra options string
# *outside* to access from each method
OPTIONS=''
OPTION_CONFIG_DIR=''
# check if the Zimbra config_dir exist
if [ "x$config_dir" != "x" ]; then
# check for postconf binary
#check_binary "${zimbra_dir}/bin/${binary}"
# remove all trailing slashes
zimbra_dir=`echo $zimbra_dir | sed 's/\/*$//'`
fi
case $1 in
meta-data) meta_data
exit $OCF_SUCCESS
;;
usage|help) usage
exit $OCF_SUCCESS
;;
esac
zimbra_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) zimbra_monitor
exit $?
;;
start) zimbra_start
exit $?
;;
stop) zimbra_stop
exit $?
;;
reload) zimbra_reload
exit $?
;;
status) if zimbra_status; then
ocf_log info "Zimbra is running."
exit $OCF_SUCCESS
else
ocf_log info "Zimbra is stopped."
exit $OCF_NOT_RUNNING
fi
;;
validate-all) exit $OCF_SUCCESS
;;
*) usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
@alvian575
Copy link

hello,,

can you tell me where is the location of this scrip file, when i finished cluster, there was error on zimbra like this,

Online: [ node1 node2 ]

Full list of resources:

virtual_ip (ocf::heartbeat:IPaddr2): Started node1
MailIP (ocf::heartbeat:IPaddr2): Started node1
Master/Slave Set: opt_disk_manager [opt_disk]
Masters: [ node1 ]
Slaves: [ node2 ]
fs_res (ocf::heartbeat:Filesystem): Started node1
zimbra_start (ocf::btactic:zimbra): Stopped
mail_outgoing (ocf::heartbeat:IPsrcaddr): Started node1

Failed Actions:

  • fs_res_start_0 on node2 'unknown error' (1): call=29, status=complete, exitreason='Couldn't mount filesystem /dev/drbd0 on /opt',
    last-rc-change='Tue Jul 30 09:29:09 2019', queued=0ms, exec=93ms
  • zimbra_start_monitor_0 on node2 'unknown error' (1): call=23, status=Timed Out, exitreason='none',
    last-rc-change='Tue Jul 30 09:28:12 2019', queued=0ms, exec=20010ms
  • zimbra_start_start_0 on node1 'not installed' (5): call=160, status=complete, exitreason='none',
    last-rc-change='Tue Jul 30 09:27:03 2019', queued=0ms, exec=11ms

tnx, i hope you can help me....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment