diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am index 27326b824..c01488e74 100644 --- a/heartbeat/Makefile.am +++ b/heartbeat/Makefile.am @@ -1,106 +1,107 @@ # Makefile.am for OCF RAs # # Author: Sun Jing Dong # Copyright (C) 2004 IBM # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # MAINTAINERCLEANFILES = Makefile.in EXTRA_DIST = $(ocf_SCRIPTS) ra-api-1.dtd INCLUDES = -I$(top_srcdir)/include -I$(top_srcdir)/linux-ha dtddir = $(HA_NOARCHDATAHBDIR) ocfdir = @OCF_RA_DIR@/heartbeat dtd_SCRIPTS = ra-api-1.dtd gliblib = @GLIBLIB@ if USE_IPV6ADDR ocf_PROGRAMS = IPv6addr else ocf_PROGRAMS = endif IPv6addr_SOURCES = IPv6addr.c IPv6addr_LDADD = $(top_builddir)/lib/clplumbing/libplumb.la \ $(gliblib) @LIBNETLIBS@ ocf_SCRIPTS = ClusterMon \ Dummy \ IPaddr \ IPaddr2 \ drbd \ + anything \ apache \ AudibleAlarm \ db2 \ Delay \ drbd \ eDir88 \ EvmsSCC \ Evmsd \ Filesystem \ ids \ iscsi \ ICP \ IPsrcaddr \ LinuxSCSI \ LVM \ MailTo \ ManageRAID \ ManageVE \ mysql \ nfsserver \ oracle \ oralsnr \ pingd \ portblock \ pgsql \ Pure-FTPd \ Raid1 \ Route \ rsyncd \ SAPDatabase \ SAPInstance \ SendArp \ ServeRAID \ SphinxSearchDaemon \ Squid \ Stateful \ SysInfo \ scsi2reservation \ sfex \ tomcat \ VIPArip \ VirtualDomain \ vmware \ WAS \ WAS6 \ WinPopup \ Xen \ Xinetd \ .ocf-shellfuncs \ .ocf-binaries \ .ocf-directories \ .ocf-returncodes commondir = @HA_LIBHBDIR@ # Legacy locations common_SCRIPTS = ocf-shellfuncs ocf-returncodes diff --git a/heartbeat/anything b/heartbeat/anything new file mode 100755 index 000000000..63d14e37f --- /dev/null +++ b/heartbeat/anything @@ -0,0 +1,267 @@ +#!/bin/sh +# +# OCF Resource Agent compliant resource script. +# +# Copyright (c) 2009 IN-telegence GmbH & Co. KG, Dominik Klein +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# +# Further, this software is distributed without any warranty that it is +# free of the rightful claim of any third person regarding infringement +# or the like. Any license provided herein, whether implied or +# otherwise, applies only to this software file. Patent licenses, if +# any, provided herein do not apply to combinations of this program with +# other software, or any other product whatsoever. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. + +# OCF instance parameters +# OCF_RESKEY_binfile +# OCF_RESKEY_cmdline_options +# OCF_RESKEY_pidfile +# OCF_RESKEY_logfile +# OCF_RESKEY_errlogfile +# OCF_RESKEY_user +# OCF_RESKEY_monitor_hook +# +# This RA starts $binfile with $cmdline_options as $user and writes a $pidfile from that. +# If you want it to, it logs: +# - stdout to $logfile, stderr to $errlogfile or +# - stdout and stderr to $logfile +# - or to will be captured by lrmd if these options are omitted. +# Monitoring is done through $pidfile or your custom $monitor_hook script. +# The RA expects the program to keep running "daemon-like" and +# not just quit and exit. So this is NOT (yet - feel free to +# enhance) a way to just run a single one-shot command which just +# does something and then exits. + +# Initialization: +. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs + +getpid() { # make sure that the file contains a number + grep '^[0-9][0-9]*$' $1 +} + +anything_status() { + if test -f "$pidfile" && pid=`getpid $pidfile` && kill -0 $pid + then + return $OCF_RUNNING + else + return $OCF_NOT_RUNNING + fi +} + +anything_start() { + if ! anything_status + then + if [ -n "$logfile" -a -n "$errlogfile" ] + then + # We have logfile and errlogfile, so redirect STDOUT und STDERR to different files + cmd="su - $user -c \"nohup $binfile $cmdline_options >> $logfile 2>> $errlogfile & \"'echo \$!' " + else if [ -n "$logfile" ] + then + # We only have logfile so redirect STDOUT and STDERR to the same file + cmd="su - $user -c \"nohup $binfile $cmdline_options >> $logfile 2>&1 & \"'echo \$!' " + else + # We have neither logfile nor errlogfile, so we're not going to redirect anything + cmd="su - $user -c \"nohup $binfile $cmdline_options & \"'echo \$!'" + fi + fi + ocf_log debug "Starting $process: $cmd" + # Execute the command as created above + eval $cmd > $pidfile + if anything_status + then + ocf_log debug "$process: $cmd started successfully" + return $OCF_SUCCESS + else + ocf_log err "$process: $cmd could not be started" + return $OCF_ERR_GENERIC + fi + else + # If already running, consider start successful + ocf_log debug "$process: $cmd is already running" + return $OCF_SUCCESS + fi +} + +anything_stop() { + if anything_status + then + pid=`getpid $pidfile` + kill $pid + i=0 + while sleep 1 + do + if ! anything_status + then + rm -f $pidfile > /dev/null 2>&1 + return $OCF_SUCCESS + fi + let "i++" + done + else + # was not running, so stop can be considered successful + rm -f $pidfile + return $OCF_SUCCESS + fi + return $OCF_ERR_GENERIC +} + +anything_monitor() { + anything_status + ret=$? + if [ $ret -eq $OCF_SUCCESS ] + then + # implement your deeper monitor operation here + if [ -n "$OCF_RESKEY_monitor_hook" ]; then + eval "$OCF_RESKEY_monitor_hook" + return + else + true + fi + else + return $ret + fi +} + +process="$OCF_RESOURCE_INSTANCE" +binfile="$OCF_RESKEY_binfile" +cmdline_options="$OCF_RESKEY_cmdline_options" +pidfile="$OCF_RESKEY_pidfile" +[ -z "$pidfile" -a -n "$binfile" ] && pidfile=${HA_VARRUN}/anything_${process}.pid +logfile="$OCF_RESKEY_logfile" +errlogfile="$OCF_RESKEY_errlogfile" +user="$OCF_RESKEY_user" +[ -z "$user" ] && user=root + +anything_validate() { + if [ ! -x "$binfile" ] + then + ocf_log err "binfile $binfile does not exist or is not executable." + exit $OCF_ERR_INSTALLED + fi + if ! getent passwd $user >/dev/null 2>&1 + then + ocf_log err "user $user does not exist." + exit $OCF_ERR_INSTALLED + fi + for logfilename in "$logfile" "$errlogfile" + do + if [ -n "$logfilename" ]; then + mkdir -p `dirname $logfilename` || { + ocf_log err "cannot create $(dirname $logfilename)" + exit $OCF_ERR_INSTALLED + } + fi + done + return $OCF_SUCCESS +} + +anything_meta() { +cat < + + +1.0 + +This is a generic OCF RA to manage almost anything. + +anything + + + + +The full name of the binary to be executed. This is expected to keep running with the same pid and not just do something and exit. + +Full path name of the binary to be executed + + + + +Command line options to pass to the binary + +Command line options + + + + +File to read/write the PID from/to. + +File to write STDOUT to + + + + +File to write STDOUT to + +File to write STDOUT to + + + + +File to write STDERR to + +File to write STDERR to + + + + +User to run the command as + +User to run the command as + + + + +Command to run in monitor operation + +Command to run in monitor operation + + + + + + + + + + + +END +exit 0 +} + +case "$1" in + meta-data|metadata|meta_data) + anything_meta + ;; + start) + anything_start + ;; + stop) + anything_stop + ;; + monitor) + anything_monitor + ;; + validate-all) + anything_validate + ;; + promote|demote|notify) + exit $OCF_SUCCESS + ;; + *) + ocf_log err "$0 was called with unsupported arguments: $*" + exit $OCF_ERR_GENERIC + ;; +esac