New resource type
"Martin Bene" <[email protected]> Mon, 5 Aug 2002 17:03:56 +0200
| Newsgroups | gmane.linux.failsafe |
|---|---|
| Message-ID | <[email protected]> |
Hi Lars, I've been playing with a generic resource type that might be interesting: it's just a wrapper for LSB compliant Sys V init scripts requirements: * scripts must reside in /etc/init.d * scripts must support start/stop/status parameters * status must return 0 when running, != 0 when not running The resource doesn't take any parameters, the name of the resource is the name of the actual initscript. minimal monitoring is done using the justification: the number of supported resoure types in failsafe is still limited; on the other hand, practically ANY conceivable resource will have a matching sys V init script. This wrapper allows you to use these existing initscripts. Also makes it easier to migrate from an existing heartbeat configuration - you can continue using the same scripts used by heartbeat. Patch is for current cvs (1.0.4) version with postgres resource type <hint>which isn't yet in CVS I believe :-)</hint>. Bye, Martin ******************************************************** Martin Bene, CTO icomedias GmbH, A-8020 Graz, Entenplatz 1b t +43 (316) 721671-14, f +43 (316) 721671-26 e [email protected], i http://www.icomedias.com ********************************************************
rescource_initscript.patch
(application/octet-stream, 12.1 KB)
diff -u -r --new-file FailSafe_old/build/spec FailSafe/build/spec
--- FailSafe_old/build/spec Thu Aug 1 18:51:10 2002
+++ FailSafe/build/spec Mon Aug 5 15:18:45 2002
@@ -622,6 +622,16 @@
%attr(755, root, root) $(DIST_PREFIX)/resource_types/postgres/start
%attr(755, root, root) $(DIST_PREFIX)/resource_types/postgres/stop
+#CI/cmd/srm/scripts/initscript
+%attr(755, root, root) $(DIST_PREFIX)/resource_types/initscript/control
+%attr(755, root, root) $(DIST_PREFIX)/resource_types/initscript/create_resource_type
+%attr(755, root, root) $(DIST_PREFIX)/resource_types/initscript/exclusive
+%attr(755, root, root) $(DIST_PREFIX)/resource_types/initscript/monitor
+%attr(755, root, root) $(DIST_PREFIX)/resource_types/initscript/postgres
+%attr(755, root, root) $(DIST_PREFIX)/resource_types/initscript/restart
+%attr(755, root, root) $(DIST_PREFIX)/resource_types/initscript/start
+%attr(755, root, root) $(DIST_PREFIX)/resource_types/initscript/stop
+
#CI/cmd/srm/scripts/sapdb
%attr(755, root, root) %dir /usr/lib/failsafe/resource_types/sapdb
%attr(755, root, root) /usr/lib/failsafe/resource_types/sapdb/exclusive
diff -u -r --new-file FailSafe_old/cluster_services/cmd/srm/scripts/Makefile FailSafe/cluster_services/cmd/srm/scripts/Makefile
--- FailSafe_old/cluster_services/cmd/srm/scripts/Makefile Thu Aug 1 18:52:06 2002
+++ FailSafe/cluster_services/cmd/srm/scripts/Makefile Mon Aug 5 15:19:27 2002
@@ -66,6 +66,7 @@
ICP_volume \
LVM_volume \
postgres \
+ initscript \
$(NULL)
# All targets descend into the subdirectories listed in $(SUBDIRS).
diff -u -r --new-file FailSafe_old/cluster_services/cmd/srm/scripts/initscript/Makefile FailSafe/cluster_services/cmd/srm/scripts/initscript/Makefile
--- FailSafe_old/cluster_services/cmd/srm/scripts/initscript/Makefile Thu Jan 1 01:00:00 1970
+++ FailSafe/cluster_services/cmd/srm/scripts/initscript/Makefile Mon Aug 5 15:17:17 2002
@@ -0,0 +1,59 @@
+#!gmake
+#
+# Makefile for CI/cmd/srm/scripts/postgres
+#
+# Copyright (c) 2001 SuSE Linux AG.
+#
+# 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.
+#
+# Contact information: Lars Marowsky-Bree <[email protected]>
+
+#
+# Every Makefile must define TOPDIR to be the path to the top of
+# the ISM. In this case the top is one directory up. The include/builddefs file
+# must then be included.
+#
+
+TOPDIR = ../../../../..
+include $(TOPDIR)/include/builddefs
+
+AGENT = initscript
+SCRIPTS = control create_resource_type
+
+LSOURCES = $(SCRIPTS) $(AGENT)
+
+all headers exports:
+
+install:
+ $(INSTALL) -d $(CI_RESOURSE_DIR)/$(AGENT)
+ $(INSTALL) -m 755 $(SCRIPTS) $(CI_RESOURSE_DIR)/$(AGENT)
+ $(INSTALL) $(AGENT) $(CI_RESOURSE_DIR)/$(AGENT)
+ $(INSTALL) -S control $(CI_RESOURSE_DIR)/$(AGENT)/start
+ $(INSTALL) -S control $(CI_RESOURSE_DIR)/$(AGENT)/stop
+ $(INSTALL) -S control $(CI_RESOURSE_DIR)/$(AGENT)/restart
+ $(INSTALL) -S control $(CI_RESOURSE_DIR)/$(AGENT)/monitor
+ $(INSTALL) -S control $(CI_RESOURSE_DIR)/$(AGENT)/exclusive
+
+#
+# Always include ismrules using the $(BUILDRULES) macro anywhere after
+# the first target is defined.
+#
+include $(BUILDRULES)
+
diff -u -r --new-file FailSafe_old/cluster_services/cmd/srm/scripts/initscript/control FailSafe/cluster_services/cmd/srm/scripts/initscript/control
--- FailSafe_old/cluster_services/cmd/srm/scripts/initscript/control Thu Jan 1 01:00:00 1970
+++ FailSafe/cluster_services/cmd/srm/scripts/initscript/control Mon Aug 5 15:16:11 2002
@@ -0,0 +1,145 @@
+#!/bin/bash
+
+# This program starts/stops/monitors a system startup script.
+#
+# Author: Martin Bene <[email protected]>
+# shamelessly copied from: Joshua Rodman <[email protected]>
+#
+# Copyright (C) 2002 SuSE Inc.
+#
+# 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
+#
+#
+########################################################################
+
+# set some global variables
+test -z "$FAILSAFE_DIR" && FAILSAFE_DIR=/usr/lib/failsafe
+test -z "$SCRIPTLIB" && SCRIPTLIB=$FAILSAFE_DIR/common_scripts/scriptlib2.sh
+
+# load the common lib
+. $SCRIPTLIB || exit -1
+
+SCRIPTDIR=/etc/init.d
+HA_CURRENT_LOGLEVEL=$HA_DBGLVL
+
+is_resource_running()
+{
+ # use resource script to check if resource is running
+ s2_log_debug "Check if $resource_name is running"
+ if ! $FAILSAFE_DIR/bin/ha_exec2 30 0 "$scriptname status > /dev/null" > /dev/null; then
+ s2_log_debug "Resource $resource_name not running"
+ return 1
+ else
+ s2_log_debug "Resource $resource_name is running"
+ return 0
+ fi
+}
+
+start_resource()
+{
+ s2_log_debug "starting resource $resource_name using script $scriptname"
+ s2_run_command -t 60 "$scriptname start > /dev/null" "starting resource $resource_name"
+
+ local exit_status
+ if is_resource_running ; then
+ s2_log_debug "Resource $resource_name started"
+ exit_status=0
+ else
+ s2_log "Resource $resource_name startup failed"
+ exit_status=1
+ fi
+
+ return $exit_status
+}
+
+# Function which processes a resource
+process_resource()
+{
+ action=$1
+ resource_name=$2
+ resource_attributes=$3
+
+ scriptname="$SCRIPTDIR/$2"
+ if [ ! -x $scriptname ]; then
+ s2_log "system script $scriptname not found, aborting"
+ s2_write_resource_status $HA_CMD_FAILED $resource_name
+ return
+ fi
+
+ exit_status=0
+
+ case $action in
+
+ start)
+ if ! is_resource_running ; then
+ start_resource
+ exit_status=$?
+ else
+ s2_log "resource $resource_name already running."
+ fi
+ ;;
+
+ stop)
+ if is_resource_running ; then
+ s2_log_debug "stopping $resource_name"
+ s2_run_command -t 30 "$scriptname stop > /dev/null"
+ if is_resource_running; then
+ exit_status=1
+ else
+ s2_log "Resource $resource_name stopped"
+ fi
+ else
+ s2_log "Resource $resource_name not running"
+ fi
+ ;;
+
+ restart)
+ if ! is_resource_running ; then
+ start_resource
+ exit_status=$?
+ else
+ s2_log "Resource $resource_name already running"
+ fi
+ ;;
+
+ monitor)
+ is_resource_running
+ exit_status=$?
+ ;;
+
+ exclusive)
+ if is_resource_running ; then
+ s2_log "Resource $resource_name running on node"
+ exit_status=1
+ fi
+ ;;
+
+ *)
+ s2_log "unknown action $action, for resource $resource_name, don't know what to do"
+ exit_status=1
+ ;;
+
+ esac
+
+ if [ $exit_status -eq 0 ]; then
+ s2_write_resource_status $HA_SUCCESS $resource_name
+ else
+ s2_write_resource_status $HA_CMD_FAILED $resource_name
+ fi
+}
+
+# Do the work
+s2_execute
diff -u -r --new-file FailSafe_old/cluster_services/cmd/srm/scripts/initscript/create_resource_type FailSafe/cluster_services/cmd/srm/scripts/initscript/create_resource_type
--- FailSafe_old/cluster_services/cmd/srm/scripts/initscript/create_resource_type Thu Jan 1 01:00:00 1970
+++ FailSafe/cluster_services/cmd/srm/scripts/initscript/create_resource_type Mon Aug 5 15:16:22 2002
@@ -0,0 +1,96 @@
+#!/bin/sh
+#
+# Copyright (c) 2000 Silicon Graphics, Inc. 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.
+#
+# Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
+# Mountain View, CA 94043, or:
+#
+# http://www.sgi.com
+#
+# For further information regarding this notice, see:
+#
+# http://oss.sgi.com/projects/GenInfo/NoticeExplan
+
+# Resource type: init_script
+# Create resource type script.
+#
+
+#
+# This script takes two parameters
+# $1 - Configuration database name
+# $2 - Cluster name
+#
+# Use resourceModify to create template resource type in the
+# configuration database. A cluster-wide resource type definition
+# is created.
+#
+
+#
+# Check arguments
+#
+if [ $# -ne 2 ]; then
+ echo "create-resource-type called with invalid number of arguments";
+ echo "create-resource-type <database file> <cluster name>"
+ exit 1
+fi
+
+DBFILE=$1
+CLUSTERNAME=$2
+RESTYPENAME=initscript
+
+#
+# Call restypeModify to create volumes resource type
+#
+/usr/lib/sysadm/privbin/restypeModify _CDB_DB=$DBFILE \
+_RESOURCE_TYPE=$RESTYPENAME _CLUSTER=$CLUSTERNAME \
+_CREATE=true _RESOURCE_TYPE_ORDER=100 \
+_RESOURCE_TYPE_PREDEFINED=true \
+_RESOURCE_TYPE_RESTART_MODE=0 _RESOURCE_TYPE_RESTART_COUNT=0 \
+_NUM_ACTIONS=5 \
+_ACTION_0=start \
+_ACTION_MAXEXECTIME_0=400000 \
+_ACTION_MONINTERVAL_0=0 \
+_ACTION_STARTMONTIME_0=0 \
+_ACTION_1=stop \
+_ACTION_MAXEXECTIME_1=400000 \
+_ACTION_MONINTERVAL_1=0 \
+_ACTION_STARTMONTIME_1=0 \
+_ACTION_2=monitor \
+_ACTION_MAXEXECTIME_2=400000 \
+_ACTION_MONINTERVAL_2=20000 \
+_ACTION_STARTMONTIME_2=50000 \
+_ACTION_3=exclusive \
+_ACTION_MAXEXECTIME_3=500000 \
+_ACTION_MONINTERVAL_3=0 \
+_ACTION_STARTMONTIME_3=0 \
+_ACTION_4=restart \
+_ACTION_MAXEXECTIME_4=400000 \
+_ACTION_MONINTERVAL_4=0 \
+_ACTION_STARTMONTIME_4=0 \
+_NUM_RESOURCE_KEYS=0
+
+if [ $? -ne 0 ]; then
+ echo "restypeModify command failed"
+ exit 1;
+else
+ exit 0;
+fi
diff -u -r --new-file FailSafe_old/cluster_services/cmd/srm/scripts/initscript/initscript FailSafe/cluster_services/cmd/srm/scripts/initscript/initscript
--- FailSafe_old/cluster_services/cmd/srm/scripts/initscript/initscript Thu Jan 1 01:00:00 1970
+++ FailSafe/cluster_services/cmd/srm/scripts/initscript/initscript Mon Aug 5 15:16:16 2002
@@ -0,0 +1,10 @@
+# initscript
+
+initscript.properFormat = \
+This is a generic resource type that can be used for \
+resources controlled by system initscript-style scripts. \
+The scripts must reside in /etc/init.d and support the \
+parameters start/stop/status.<p>\
+status should return exit code 0 when running, anything else \
+when down / not running. The resource name must match the \
+name of the corresponding system startup script in /etc/init.d.