Hi all,
I've written a Resource Agent for Firebird 2.5 Superclassic Server. The
RA has the common switches meta-data, start, stop, monitor, reload,
validate-all, usage|help. I've written the RA with the default values as
if you would install Firebird 2.5 manually using the packages available
at http://www.firebirdsql.org/index.php?op=files&id=engine_250 . I've
chosen these defaults as there are no debian/ubuntu packages that I know
of of Firebird 2.5 so far.
OCF_RESKEY_binary_default="/opt/firebird/bin/fbguard"
OCF_RESKEY_pid_default="/var/run/firebird/firebird.pid"
OCF_RESKEY_user_default="firebird"
For the RA to work all you need to do is to create a folder called
firebird readable/writeable by OCF_RESKEY_user in /var/run.
I hope that the RA meets the requirements, and does the job as
convenient as possible for most people.
Thanks
#!/bin/sh
#
#
# Firebird 2.5 OCF RA. Start Firebird 2.5 Superclassic server
#
#
# Author: Frank Lazzarini
#
# Support: [email protected]
# License: GNU General Public License (GPL)
# Copyright: (C) 2010 SitaSoftware S.A.
#
# See usage() function below for more details...
#
# OCF instance parameters:
# OCF_RESKEY_binary
# OCF_RESKEY_pid
# OCF_RESKEY_user
#
#######################################################################
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat}
. ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs
#######################################################################
OCF_RESKEY_binary_default="/opt/firebird/bin/fbguard"
OCF_RESKEY_pid_default="/var/run/firebird/firebird.pid"
OCF_RESKEY_user_default="firebird"
: ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}
: ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}
: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}}
meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="firebird25" version="0.1">
<version>1.0</version>
<longdesc lang="en">
This is a Resource Agent for Firebird 2.5 Superclassic server. The resource
agent
simply starts fbguard with a few options. Fbguard is a process which starts the
Firebird 2.5 Superclassic server namely fb_snmp_server process and guards this
process.
</longdesc>
<shortdesc lang="en">Firebird 2.5 Superclassic Server Resource
Agent.</shortdesc>
<parameters>
<parameter name="binary" unique="0" required="0">
<shortdesc lang="en">Firebird 2.5 Guardian binary</shortdesc>
<longdesc lang="en">Destination of the Firebird 2.5 Superclassic
Guardian binary. (default: /opt/firebird/bin/fb_snmp_server)</longdesc>
<content type="string" default="$OCF_RESKEY_binary_default" />
</parameter>
<parameter name="pid" unique="0" required="0">
<shortdesc lang="en">Firebird pid file</shortdesc>
<longdesc lang="en">The pidfile to be used for fbguard (default:
/var/run/firebird/firebird.pid)</longdesc>
<content type="string" default="$OCF_RESKEY_pid_default" />
</parameter>
<parameter name="user" unique="0" required="0">
<shortdesc lang="en">Firebird User</shortdesc>
<longdesc lang="en">User running Firebird daemon (default:
firebird)</longdesc>
<content type="string" default="$OCF_RESKEY_user_default" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="20" />
<action name="stop" timeout="20" />
<action name="monitor" timeout="20" interval="10" depth="0" />
<action name="reload" timeout="20" />
<action name="migrate_to" timeout="20" />
<action name="migrate_from" timeout="20" />
<action name="meta-data" timeout="5" />
<action name="validate-all" timeout="20" />
</actions>
</resource-agent>
END
exit $OCF_SUCCESS
}
#######################################################################
firebird25_usage() {
cat <<END
usage: $0 {start|stop|monitor|meta-data}
END
}
firebird25_start() {
# exit immediately if configuration is not valid
firebird25_validate_all || exit $?
# if resource is already running, bail out early
if firebird25_monitor; then
ocf_log info "Resource is already running"
fi
start-stop-daemon --start --quiet --oknodo --chuid $OCF_RESKEY_user
--exec $OCF_RESKEY_binary -- -pidfile $OCF_RESKEY_pid -daemon -forever
return $OCF_SUCCESS
}
firebird25_stop() {
local rc
# exit immediately if configuration is not valid
firebird25_validate_all || exit $?
# check if firebird is running
firebird25_monitor
rc=$?
case "$rc" in
"$OCF_SUCCESS")
ocf_log debug "Resource is currently running"
;;
"$OCF_NOT_RUNNING")
ocf_log info "Resource is already stopped"
;;
esac
if [ -f $OCF_RESKEY_pid ]
then
kill `cat $OCF_RESKEY_pid`
if [ $? = 0 ]; then
return $OCF_SUCCESS
fi
fi
while firebird25_monitor; do
ocf_log debug "Resource has not stopped yet, waiting"
sleep 1
done
return $OCF_SUCCESS
}
firebird25_monitor() {
local rc
firebird25_validate_all
# Return OCF_NOT_RUNNING if no pid was found
if [ ! -e $OCF_RESKEY_pid ]; then
ocf_log debug "Firebird is not running"
return $OCF_NOT_RUNNING
fi
# Check if firebird is running
# first get the pid from the pidfile and check with
# kill -0 pid if the process is running with the right pid
pid=`cat $OCF_RESKEY_pid`
kill -0 $pid >/dev/null 2>&1
rc=$?
# Return OCF_SUCCESS if process is running
# Return OCF_NOT_RUNNING if process is not running but pid exists
if [ $rc -eq 0 ]; then
return $OCF_SUCCESS
else
ocf_log debug "Firebird is not running: removing old PID file"
rm -f $OCF_RESKEY_pid
return $OCF_NOT_RUNNING
fi
}
firebird25_validate_all() {
# Checking the parameters
# check if binary exists and is executable
if [ ! -x $OCF_RESKEY_binary ]; then
ocf_log err "fbguard binary $OCF_RESKEY_binary does not exist
or is not executable"
return $OCF_ERR_INSTALLED
fi
# check if user exits
getent passwd $OCF_RESKEY_user >/dev/null 2>&1
if [ ! $? -eq 0 ]; then
ocf_log err "User $OCF_RESKEY_user doesn't exist"
return $OCF_ERR_INSTALLED
fi
true
}
case $__OCF_ACTION in
meta-data) meta_data
exit $OCF_SUCCESS
;;
start) firebird25_start;;
stop) firebird25_stop;;
monitor) firebird25_monitor;;
reload) ocf_log err "Reloading..."
firebird25_start
;;
validate-all) firebird25_validate_all;;
usage|help) firebird25_usage
exit $OCF_SUCCESS
;;
*) firebird25_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc
_______________________________________________________
Linux-HA-Dev: [email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/