#!/bin/sh
#
# Description: Manages a Tivoli Storage manager as an OCF High-Availability
# resource under Heartbeat/LinuxHA control
#
# Author: Christian Heim (christian.heim@barfoo.org)
# Copyright: (C) 2008 Christian Heim
# License: GNU General Public License (GPL)
#
# An example XML-entry for this resource would look like this:
#
# <primitive class="ocf" id="dsmserv" provider="heartbeat" type="dsmserv">
# <operations>
# <op id="dsmserv_mon" interval="5s" name="monitor" timeout="5s"/>
# </operations>
# <instance_attributes id="dsmserv_inst_attr">
# <attributes>
# <!--
# All attributes listed below are required.
# You are strongly advised to put them into your configuration,
# otherwise the resource agent is gonna fail horribly.
# -->
# <nvpair id="dsmserv_attr_0" name="prefix" value="/opt/tivoli/tsm/server" />
# <nvpair id="dsmserv_attr_1" name="instance" value="tsm1" />
# <nvpair id="dsmserv_attr_2" name="id" value="ha_client" />
# <nvpair id="dsmserv_attr_3" name="password" value="ha_client" />
# <nvpair id="dsmserv_attr_4" name="TCPAddress" value="10.0.0.10" />
# <nvpair id="dsmserv_attr_5" name="TCPPort" value="1500" />
# <!--
# All below attributes are optional, meaning if you are not putting
# anything into the configuration file, the resource agent is going
# to use the defaults.
# -->
# <nvpair id="dsmserv_attr_6" name="max_retries" value="2" />
# <nvpair id="dsmserv_attr_6" name="shutdown_timeout" value="10" />
# <nvpair id="dsmserv_attr_7" name="dsmserv_dir" value="/opt/tivoli/tsm/server/bin" />
# <nvpair id="dsmserv_attr_8" name="dsmclient_dir" value="/opt/tivoli/client/ba/bin" />
# <!--
# If you are unclear, what this agent set a certain variable to, change
# the below to "1" to enable the extended debugging to your ha.log.
# -->
# <nvpair id="dsmserv_attr_9" name="extended_debugging" value="0" />
# </attributes>
# </instance_attributes>
# </primitive>
#
# OCF parameters:
# OCF_RESKEY_prefix
# OCF_RESKEY_instance
# OCF_RESKEY_id
# OCF_RESKEY_password
# OCF_RESKEY_TCPAddress
# OCF_RESKEY_TCPPort
# OCF_RESKEY_max_retries
# OCF_RESKEY_shutdown_timeout
# OCF_RESKEY_dsmserv_dir
# OCF_RESKEY_dsmclient_dir
# OCF_RESKEY_extended_debugging
. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
unset LC_ALL; export LC_ALL
unset LANGUAGE; export LANGUAGE
dsmserv_metadata() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="dsmserv">
<version>1.0</version>
<longdesc lang="en">
This script manages the Tivoli Storage Manager server.
Please be aware, that in order to run your Tivoli Storage Manager Server via
Heartbeat you need to prepare the according to the Storage Manager Handbook.
</longdesc>
<shortdesc lang="en">OCF Resource Agent compilant dsmserv script.</shortdesc>
<parameters>
<parameter name="prefix">
<longdesc lang="en">
Where all your Tivoli Storage Manager Server instances are going to show up.
This is adjustable to your wishes, just make sure the directory exists on all
possible owners of this resource.
</longdesc>
<shortdesc lang="en">Prefix for all Tivoli Storage Manager Server instances.</shortdesc>
<content type="string" />
</parameter>
<parameter name="instance">
<longdesc lang="en">
The Tivoli Storage Manager Server named instance. This is the path to the named
instance, which is located on a single file system.
</longdesc>
<shortdesc lang="en">Name of a single dsmserv instance located in your Prefix.</shortdesc>
<content type="string" />
</parameter>
<parameter name="TCPAddress">
<longdesc lang="en">
The Tivoli Storage Manager Server instance IP-Address. This is needed for the
shutdown command to "nicely" halt the server instead of just sending a kill -9.
</longdesc>
<shortdesc lang="en">The Tivoli Storage Manager Server IP-Address.</shortdesc>
<content type="string" />
</parameter>
<parameter name="TCPPort" unique="1">
<longdesc lang="en">
The Tivoli Storage Manager Server instance Port. This is needed for the
shutdown command to "nicely" halt the server instead of just sending a kill -9.
</longdesc>
<shortdesc lang="en">The Tivoli Storage Manager Server Port.</shortdesc>
<content type="string" />
</parameter>
<parameter name="id">
<longdesc lang="en">
This needs to be an account with ADMIN privileges, in order to correctly halt
the server.
</longdesc>
<shortdesc lang="en">An administrative user (CLASS=SYSTEM) on the TSM server.</shortdesc>
<content type="string" />
</parameter>
<parameter name="password">
<longdesc lang="en">
The password for the specified user account.
</longdesc>
<shortdesc lang="en">The password for the specified account on the TSM server.</shortdesc>
<content type="string" />
</parameter>
<parameter name="max_retries">
<longdesc lang="en">
This defines the amount of retries the script is going to do before continuing.
This is useful on busy servers, where you would end up with new sessions before
shutting down the server.
</longdesc>
<shortdesc lang="en">Amount of retries before shutting down the server.</shortdesc>
<content type="string" default="2" />
</parameter>
<parameter name="shutdown_timeout">
<longdesc lang="en">
Time to wait (in seconds) before killing (as in running kill -9) the server instance.
</longdesc>
<shortdesc lang="en">Timeout before killing the server instance.</shortdesc>
<content type="string" default="5" />
</parameter>
<parameter name="dsmserv_dir">
<longdesc lang="en">
Path to the Tivoli Storage Manager Server binaries. This is a feature for multiple purposes.
First, its a way to run instances with different versions on the same physical server.
Second, if you had to customize the path where your version of Tivoli Storage Manager Server
is installed, then use this to adjust the used path.
</longdesc>
<shortdesc lang="en">Path to the TSM server binaries.</shortdesc>
<content type="string" default="/opt/tivoli/tsm/server/bin" />
</parameter>
<parameter name="dsmclient_dir">
<longdesc lang="en">
Path to the Tivoli Storage Manager Administrative Console binary.
This is a feature for multiple purposes. First, its a way to run instances with
different versions on the same physical server. Second, if you had to customize
the path where your version of Tivoli Storage Manager Administrative Console
is installed, then use this to adjust the used path.
</longdesc>
<shortdesc lang="en">Path to the TSM Administrative Console binary.</shortdesc>
<content type="string" default="/opt/tivoli/tsm/client/ba/bin" />
</parameter>
<parameter name="extended_debugging">
<longdesc lang="en">
Enables the somewhat extensive debugging features in this OCF Resource Agent.
This is coming in handy, if you suspect that either this Agent or something
other is screwing up.
</longdesc>
<shortdesc lang="en">Enables the extended debugging.</shortdesc>
<content type="string" default="0" />
</parameter>
</parameters>
<actions>
<action name="start" timeout="90" />
<action name="stop" timeout="100" />
<action name="monitor" depth="10" timeout="30s" interval="60s" start-delay="1s" />
<action name="validate-all" timeout="30s" />
<action name="meta-data" timeout="5s" />
<action name="status" timeout="30s" />
</actions>
</resource-agent>
END
exit $OCF_SUCCESS
}
dsmserv_settings() {
# Settings the above mentioned defaults.
: ${OCF_RESKEY_max_retries:=2}
: ${OCF_RESKEY_shutdown_timeout:=5}
: ${OCF_RESKEY_dsmserv_dir:=/opt/tivoli/tsm/server/bin}
: ${OCF_RESKEY_dsmclient_dir:=/opt/tivoli/tsm/client/ba/bin}
: ${OCF_RESKEY_extended_debugging:=0}
: ${DSMSERV_DIR:=$OCF_RESKEY_dsmserv_dir}
: ${DSMSERV_CONFIG:=$OCF_RESKEY_prefix/$OCF_RESKEY_instance/dsmserv.opt}
: ${DSMADMC:=$OCF_RESKEY_dsmclient_dir/dsmadmc}
# Make sure we put a note into the log about unconfigured
# $OCF_RESKEY_TCPAddress and $OCF_RESKEY_TCPPort.
if $TEST -z "$OCF_RESKEY_TCPAddress" -o -z "$OCF_RESKEY_TCPPort" ; then
ocf_log info "Either $OCF_RESKEY_TCPAddress or $OCF_RESKEY_TCPPort are not configured."
ocf_log info "This isn't a major fault (if you are only running a single instance"
ocf_log info "for high-availibility), but it is gonna make this script fail if you are having"
ocf_log info "multiple instances running on different ports."
fi
}
dsmserv_checkstatus() {
kill -0 "$1" >/dev/null 2>&1
}
dsmserv_getpid() {
$AWK --source '{print $4}' $OCF_RESKEY_prefix/$OCF_RESKEY_instance/dsmserv.lock 2>/dev/null
}
dsmserv_debuginfo() {
if $TEST $OCF_RESKEY_extended_debugging ; then
# Some debug information, makes it easier finding configuration mistakes.
ocf_log debug " "
ocf_log debug "$OCF_RESKEY_prefix: "$OCF_RESKEY_prefix""
ocf_log debug "$OCF_RESKEY_instance: "$OCF_RESKEY_instance""
ocf_log debug "$OCF_RESKEY_id: "$OCF_RESKEY_id""
ocf_log debug "$OCF_RESKEY_TCPAddress: "$OCF_RESKEY_TCPAddress""
ocf_log debug "$OCF_RESKEY_TCPPort: "$OCF_RESKEY_TCPPort""
ocf_log debug "$OCF_RESKEY_max_retries: "$OCF_RESKEY_max_retries""
ocf_log debug "$OCF_RESKEY_shutdown_timeout: "$OCF_RESKEY_shutdown_timeout""
ocf_log debug "$OCF_RESKEY_dsmserv_dir: "$OCF_RESKEY_dsmserv_dir""
ocf_log debug "$OCF_RESKEY_dsmclient_dir: "$OCF_RESKEY_dsmclient_dir""
ocf_log debug " "
ocf_log debug "$DSMSERV_DIR: "$DSMSERV_DIR""
ocf_log debug "$DSMSERV_CONFIG: "$DSMSERV_CONFIG""
ocf_log debug "$DSMADMC: "$DSMADMC""
ocf_log debug " "
fi
}
dsmserv_checksetup() {
# Move the checks for dsmserv/dsmadmc binaries and dsmserv.opt/dsmserv.dsk
# into a single function.
dsmserv_settings
local EXIT=""
case "$1" in
start)
EXIT="$OCF_NOT_RUNNING"
;;
validate)
EXIT="$OCF_ERR_ARGS"
;;
esac
dsmserv_debuginfo
# Terminate rather here than later with a half-hanging dsmserv instance, due to
# main configuration values not being set properly.
ocf_log debug "Probing whether or not $OCF_RESKEY_prefix, $OCF_RESKEY_instance, $OCF_RESKEY_id"
ocf_log debug "and $OCF_RESKEY_password are set."
if $TEST -z "$OCF_RESKEY_prefix" -o -z "$OCF_RESKEY_instance" -o
-z "$OCF_RESKEY_id" -o -z "$OCF_RESKEY_password" ; then
ocf_log err "Your configuration is missing the most important settings."
ocf_log err "Please check whether you missed either of the following:"
ocf_log err "$OCF_RESKEY_prefix, $OCF_RESKEY_instance, $OCF_RESKEY_id or $OCF_RESKEY_password."
ocf_log err "This is a non-recoverable, fatal error!"
exit $EXIT
fi
# Check for the 'dsmserv' binary from TIVsm-server
ocf_log debug "Probing for existance of $DSMSERV_DIR/dsmserv."
if $TEST ! -x $DSMSERV_DIR/dsmserv ; then
ocf_log err "You are lacking a version of IBMs Tivoli Storage Manager Server."
ocf_log err "Make sure you have the TIVsm-server RPM installed. Please check the debug log for further information."
ocf_log err "This is a non-recoverable, fatal error!"
exit $EXIT
fi
# Check for the 'dsmadmc' binary from TIVsm-BA
ocf_log debug "Probing for existance of $DSMADMC."
if $TEST ! -x $DSMADMC ; then
ocf_log err "You are lacking a version of IBMs Tivoli Storage Manager Client."
ocf_log err "Make sure you have the TIVsm-BA RPM installed. Please check the debug log for further information."
ocf_log err "This is a non-recoverable, fatal error!"
exit $EXIT
fi
# Check for 'dsmserv.opt' and 'dsmserv.dsk' in $OCF_RESKEY_prefix/$OCF_RESKEY_instance.
if $TEST ! -f $DSMSERV_CONFIG -o ! -f ${DSMSERV_CONFIG%/*}/dsmserv.dsk ; then
ocf_log err "Either $DSMSERV_CONFIG or ${DSMSERV_CONFIG%/*}/dsmserv.dsk for dsmserv instance "$OCF_RESKEY_instance""
ocf_log err "could not be found, thus exiting. The Tivoli Storage Manager Instance you are trying to run, needs"
ocf_log err "to be prepared in order to be run by Heartbeat! Also, please check the debug log for further information."
ocf_log err "This is a non-recoverable, fatal error!"
exit $EXIT
fi
return $OCF_SUCCESS
}
dsmserv_start() {
if ocf_is_root ; then : ; else
ocf_log err "You must be root."
exit $OCF_ERR_PERM
fi
if dsmserv_status ; then
ocf_log info "dsmserv instance "$OCF_RESKEY_instance" is already running."
exit $OCF_SUCCESS
fi
dsmserv_checksetup "start"
export DSMSERV_CONFIG=$DSMSERV_CONFIG
export DSMSERV_DIR=$DSMSERV_DIR
# May be removed, still need to test it.
cd ${DSMSERV_CONFIG%/*}
$DSMSERV_DIR/dsmserv >>/var/log/dsmserv_$OCF_RESKEY_instance.log 2>&1 &
unset DSMSERV_CONFIG
unset DSMSERV_DIR
if $TEST $? -ne 0 ; then
ocf_log err "Error. dsmserv instance "$OCF_RESKEY_instance" returned error $?."
exit $OCF_ERR_GENERIC
fi
ocf_log info "Started dsmserv instance "$OCF_RESKEY_instance"."
exit $OCF_SUCCESS
}
dsmserv_stop() {
if dsmserv_status ; then
PID="$( dsmserv_getpid )"
dsmserv_settings
dsmserv_debuginfo
local CMD="$DSMADMC -id=$OCF_RESKEY_id -password=$OCF_RESKEY_password
-noconfirm
-displaymode=list
-tcpserveraddress=$OCF_RESKEY_TCPAddress
-tcpport=$OCF_RESKEY_TCPPort"
local i=1
while $TEST $i -le $OCF_RESKEY_max_retries; do
# Check whether or not we need to terminate any running processes first.
PROCESSES="$( $CMD query process | $EGREP 'Process Number: .*' | $AWK -F ': ' '{ print $2 }' )"
ocf_log debug "Try #$i: Processing shutdown tests 1/2 (running processes) for dsmserv instance "$OCF_RESKEY_instance""
ocf_log debug "Executing "$CMD query process | $EGREP 'Process Number: .*' | $AWK -F ': ' '{ print $2 }'""
ocf_log debug "Process list: '$PROCESSES'"
if $TEST -n $PROCESSES ; then
ocf_log debug "Try #$i: Processing shutdown steps 1/2 (running processes) for dsmserv instance "$OCF_RESKEY_instance""
ocf_log info "Try #$i: Canceling all active processes."
for process in $PROCESSES; do
ocf_log debug "Executing "$CMD cancel process $process""
$CMD cancel process $process >>/var/log/dsmadmc.log 2>&1
done
fi
# Check whether or not we need to unmount the drives first.
VOLUMES="$( $CMD query mount | $EGREP 'LTO volume .* is mounted' | $AWK -F ' ' '{ print $4 }' )"
ocf_log debug "Try #$i: Processing shutdown tests 2/2 (volume mounts) for dsmserv instance "$OCF_RESKEY_instance""
ocf_log debug "Executing "$CMD query mount | $EGREP 'LTO volume .* is mounted' | $AWK -F ' ' '{ print $4 }'""
ocf_log debug "Mounted volumes: '$VOLUMES'"
if $TEST -n "$VOLUMES" ; then
ocf_log debug "Try #$i: Processing shutdown steps 2/2 (volume mounts) for dsmserv instance "$OCF_RESKEY_instance""
ocf_log info "Try #$i: Dismounting all mounted volumes."
for tape in $VOLUMES; do
ocf_log debug "Executing "$CMD dismount volume $tape""
$CMD dismount volume $tape >>/var/log/dsmadmc.log 2>&1
done
fi
i=$(($i+1))
done
# Now, halt the server instance
ocf_log info "Trying to send the 'HALT' command to the dsmserv instance "$OCF_RESKEY_instance"."
ocf_log debug "Executing "$CMD halt""
$CMD halt >>/var/log/dsmadmc.log 2>&1
local i=1
while $TEST $i -le $OCF_RESKEY_max_retries; do
ocf_log debug "Try #$i: Waiting for $OCF_RESKEY_shutdown_timeout seconds."
sleep $OCF_RESKEY_shutdown_timeout
i=$(($i+1))
done
if dsmserv_checkstatus "$PID" ; then
ocf_log err "Sending the 'HALT' command to the dsmserv instance "$OCF_RESKEY_instance" failed."
ocf_log debug "The server might still be shutting down, try increasing $OCF_RESKEY_shutdown_timeout."
ocf_log info "Proceeding with a SIGTERM."
kill $PID
if $TEST $? -ne 0 ; then
ocf_log err "Ending the dsmserv instance "$OCF_RESKEY_instance" with SIGTERM failed."
ocf_log info "Proceeding with a SIGKILL."
kill -SIGKILL $PID
if $TEST $? -ne 0 ; then
ocf_log err "Ending the dsmserv instance "$OCF_RESKEY_instance" with SIGKILL failed."
ocf_log err "Failed ending the process, giving up. User intervention is required."
return $OCF_ERR_GENERIC
fi
fi
fi
fi
ocf_log info "Stopped dsmserv instance "$OCF_RESKEY_instance"."
exit $OCF_SUCCESS
}
dsmserv_status() {
if $TEST -f $OCF_RESKEY_prefix/$OCF_RESKEY_instance/dsmserv.lock ; then
# dsmserv is probably still running
PID="$( dsmserv_getpid )"
if $TEST -n $PID ; then
dsmserv_checkstatus "$PID" >/dev/null && [ `ps -p $PID | grep dsmserv | wc -l` -eq 1 ]
return $?
fi
fi
false
}
dsmserv_monitor() {
if dsmserv_status ; then
return $OCF_SUCCESS
else
return $OCF_NOT_RUNNING
fi
}
dsmserv_usage() {
echo "Usage: $0 {start|stop|status|monitor|validate-all}" >&2
exit $OCF_SUCCESS
}
case "$1" in
start)
dsmserv_start
;;
stop)
dsmserv_stop
;;
status)
dsmserv_status
;;
monitor)
dsmserv_monitor
;;
validate-all)
dsmserv_checksetup "validate"
;;
meta-data)
dsmserv_metadata
;;
usage)
dsmserv_usage
;;
notify|demote|promote|migrate_to|migrate_from|reload|recover)
exit $OCF_ERR_UNIMPLEMENTED
;;
*)
dsmserv_usage
exit $OCF_ERR_UNIMPLEMENTED
;;
esac