Hi list,
I have rewritten the pure-ftpd resurce agent to a proftpd resource agent. In my
first tests it runs well. In one week the system will be productive, and if I
find any bug until then, I will post the diffs here.
Actually it does the same thing as the pure-ftpd script, except monitoring. It
is possible to configure in cib.xml an OCF_CHECK_LEVEL greater zero. The script
will not check anymore for the pid, but it will perform a login to the ftp
server on localhost with curl.
So far as I can see the pure-ftpd script was published under the GPL, and I
would like to contribute that script under the GPL as well. Could anyone commit
that code, please?
One Question is left:
<actions>
...
<action name="monitor" depth="10" timeout="20s" interval="60s" start-delay="1s"
/>
...
</actions>
What I have to write here? Any docs?
Achim
Achim Stumpf wrote:
Hi List,
Is there somewhere already in the sources a ocf script for proftpd
available?
If not I will rewrite the pure-ftpd script from:
http://hg.linux-ha.org/dev/file/7a6da7261070/resources/OCF/Pure-FTPd
Thanks,
Achim
#!/bin/sh
#
# Resource script for Proftpd
#
# Description: Manages Proftpd as an OCF resource in
# an Active-Passive High Availability setup.
#
# Author: Rajat Upadhyaya <[EMAIL PROTECTED]> : Pure-FTPd script
# Author: Achim Stumpf <[EMAIL PROTECTED]> : Rewrite as Proftpd
# License: GNU General Public License (GPL)
#
#
# usage: $0 {start|stop|status|monitor|validate-all|meta-data}
#
# The "start" arg starts Proftpd.
#
# The "stop" arg stops it.
#
# OCF parameters:
# OCF_RESKEY_binary
# OCF_RESKEY_conffile
# OCF_RESKEY_pidfile
# OCF_RESKEY_curl_binary
# OCF_RESKEY_test_user
# OCF_RESKEY_test_pass
# OCF_RESKEY_connect_timeout
# OCF_RESKEY_max_time
#
##########################################################################
# Initialization:
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
: ${OCF_RESKEY_binary="/usr/sbin/proftpd"}
: ${OCF_RESKEY_conffile="/etc/proftpd.conf"}
: ${OCF_RESKEY_pidfile="/var/run/proftpd.pid"}
: ${OCF_RESKEY_curl_binary="/usr/bin/curl"}
: ${OCF_RESKEY_test_user="test"}
: ${OCF_RESKEY_test_pass=""}
: ${OCF_RESKEY_connect_timeout="50"}
: ${OCF_RESKEY_max_time="55"}
USAGE="Usage: $0 {start|stop|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="proftpd">
<version>1.0</version>
<longdesc lang="en">
This script manages Proftpd in an Active-Passive setup
</longdesc>
<shortdesc lang="en">OCF Resource Agent compliant FTP script.</shortdesc>
<parameters>
<parameter name="binary" unique="0" required="0">
<longdesc lang="en">The Proftpd binary</longdesc>
<shortdesc lang="en">The Proftpd binary</shortdesc>
<content type="string" default="/usr/sbin/proftpd" />
</parameter>
<parameter name="conffile" unique="0" required="0">
<longdesc lang="en">
The Proftpd configuration file name with full path.
For example, "/etc/proftpd.conf"
</longdesc>
<shortdesc lang="en">Configuration file name with full path</shortdesc>
<content type="string" default="/etc/proftpd.conf" />
</parameter>
<parameter name="pidfile" unique="0" required="0">
<longdesc lang="en">The Proftpd PID file. The location of the PID file is
configured in the Proftpd configuration file.</longdesc>
<shortdesc lang="en">PID file</shortdesc>
<content type="string" default="/var/run/proftpd.pid" />
</parameter>
<parameter name="curl_binary" unique="0" required="0">
<longdesc lang="en">The absolut path to the curl binary for monitoring with
OCF_CHECK_LEVEL greater zero.</longdesc>
<shortdesc lang="en">The absolut path to the curl binary</shortdesc>
<content type="string" default="/usr/bin/curl" />
</parameter>
<parameter name="test_user" unique="0" required="0">
<longdesc lang="en">The name of the ftp user for monitoring with
OCF_CHECK_LEVEL greater zero.</longdesc>
<shortdesc lang="en">The name of the ftp user</shortdesc>
<content type="string" default="test" />
</parameter>
<parameter name="test_pass" unique="0" required="0">
<longdesc lang="en">The password of the ftp user for monitoring with
OCF_CHECK_LEVEL greater zero.</longdesc>
<shortdesc lang="en">The password of the ftp user</shortdesc>
<content type="string" default="" />
</parameter>
<parameter name="connect_timeout" unique="0" required="0">
<longdesc lang="en">The connect timeout of curl for monitoring with
OCF_CHECK_LEVEL greater zero. See man curl.</longdesc>
<shortdesc lang="en">The connect timeout of curl</shortdesc>
<content type="string" default="50" />
</parameter>
<parameter name="max_time" unique="0" required="0">
<longdesc lang="en">The maximum time of curl for monitoring with
OCF_CHECK_LEVEL greater zero. See man curl.</longdesc>
<shortdesc lang="en">The maximum time of curl</shortdesc>
<content type="string" default="55" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="90" />
<action name="stop" timeout="100" />
<action name="monitor" depth="10" timeout="20s" interval="60s"
start-delay="1s" />
<action name="validate-all" timeout="30s" />
<action name="meta-data" timeout="5s" />
</actions>
</resource-agent>
END
exit $OCF_SUCCESS
}
isRunning()
{
kill -0 "$1" > /dev/null
}
proftpd_status()
{
if [ -f $OCF_RESKEY_pidfile ]
then
# Proftpd is probably running
PID=`head -n 1 $OCF_RESKEY_pidfile`
if [ ! -z $PID ] ; then
isRunning "$PID" && [ `ps -p $PID | grep proftpd | wc
-l` -eq 1 ]
return $?
fi
fi
# Proftpd is not running
return $OCF_NOT_RUNNING;
}
proftpd_start()
{
#
# make a few checks and start Proftpd
#
if ocf_is_root ; then : ; else
ocf_log err "You must be root"
exit $OCF_ERR_PERM
fi
# if Proftpd is running return success
if proftpd_status ; then
ocf_log info "Poftpd is running already"
exit $OCF_SUCCESS
fi
# check that the Proftpd config file exist
if [ ! -f "$OCF_RESKEY_conffile" ]; then
ocf_log err "Proftpd config file '$OCF_RESKEY_conffile' does
not exist"
exit $OCF_ERR_GENERIC
fi
# starting Proftpd
${OCF_RESKEY_binary} --config ${OCF_RESKEY_conffile} 2>/dev/null
if [ $? -ne 0 ]; then
ocf_log err "Proftpd returned error" $?
exit $OCF_ERR_GENERIC
fi
exit $OCF_SUCCESS
}
proftpd_stop()
{
if proftpd_status ; then
PID=`head -n 1 $OCF_RESKEY_pidfile`
if [ ! -z $PID ] ; then
kill $PID
if [ $? -ne 0 ]; then
ocf_log err "Proftpd couldn't be stopped"
return $OCF_ERR_GENERIC
fi
fi
fi
exit $OCF_SUCCESS
}
proftpd_monitor()
{
if [ $OCF_CHECK_LEVEL -eq 0 ]; then
if proftpd_status ; then
ocf_log debug "Proftpd monitor succeded"
return $OCF_SUCCESS
fi
else
${OCF_RESKEY_curl_binary} -sS --connect-timeout
${OCF_RESKEY_connect_timeout} --max-time ${OCF_RESKEY_max_time} -u
"${OCF_RESKEY_test_user}:${OCF_RESKEY_test_pass}" ftp://localhost/ > /dev/null
2>&1
if [ $? -eq 0 ] ; then
ocf_log debug "Proftpd monitor succeded"
return $OCF_SUCCESS
fi
fi
ocf_log err "Proftpd monitor failed"
return $OCF_NOT_RUNNING
}
proftpd_validate_all()
{
return $OCF_SUCCESS
}
#
# Main
#
if [ $# -ne 1 ]
then
usage
exit $OCF_ERR_ARGS
fi
case $1 in
start) proftpd_start
;;
stop) proftpd_stop
;;
status) if proftpd_status
then
ocf_log info "Proftpd is running"
exit $OCF_SUCCESS
else
ocf_log info "Proftpd is stopped"
exit $OCF_NOT_RUNNING
fi
;;
monitor) proftpd_monitor
exit $?
;;
validate-all) proftpd_validate_all
exit $?
;;
meta-data) meta_data
;;
usage) usage
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/