1204076Spjd#!/bin/sh 2204076Spjd# 3204076Spjd# Copyright (c) 2010 The FreeBSD Foundation 4204076Spjd# All rights reserved. 5204076Spjd# 6204076Spjd# This software was developed by Pawel Jakub Dawidek under sponsorship from 7204076Spjd# the FreeBSD Foundation. 8204076Spjd# 9204076Spjd# Redistribution and use in source and binary forms, with or without 10204076Spjd# modification, are permitted provided that the following conditions 11204076Spjd# are met: 12204076Spjd# 1. Redistributions of source code must retain the above copyright 13204076Spjd# notice, this list of conditions and the following disclaimer. 14204076Spjd# 2. Redistributions in binary form must reproduce the above copyright 15204076Spjd# notice, this list of conditions and the following disclaimer in the 16204076Spjd# documentation and/or other materials provided with the distribution. 17204076Spjd# 18204076Spjd# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 19204076Spjd# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20204076Spjd# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21204076Spjd# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 22204076Spjd# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23204076Spjd# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24204076Spjd# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25204076Spjd# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26204076Spjd# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27204076Spjd# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28204076Spjd# SUCH DAMAGE. 29204076Spjd# 30204076Spjd# $FreeBSD$ 31204076Spjd 32204076Spjd# Resource name as defined in /etc/hast.conf. 33204076Spjdresource="test" 34204076Spjd# Supported file system types: UFS, ZFS 35204076Spjdfstype="UFS" 36204076Spjd# ZFS pool name. Required only when fstype == ZFS. 37204076Spjdpool="test" 38204076Spjd# File system mount point. Required only when fstype == UFS. 39204076Spjdmountpoint="/mnt/test" 40204076Spjd# Name of HAST provider as defined in /etc/hast.conf. 41204076Spjd# Required only when fstype == UFS. 42204076Spjddevice="/dev/hast/${resource}" 43204076Spjd 44204076Spjdexport PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 45204076Spjd 46204076Spjd# KIll UP script if it still runs in the background. 47204076Spjdsig="TERM" 48204076Spjdfor i in `jot 30`; do 49204076Spjd pgid=`pgrep -f ucarp_up.sh | head -1` 50204076Spjd [ -n "${pgid}" ] || break 51204076Spjd kill -${sig} -- -${pgid} 52204076Spjd sig="KILL" 53204076Spjd sleep 1 54204076Spjddone 55204076Spjdif [ -n "${pgid}" ]; then 56204076Spjd logger -p local0.error -t hast "UCARP UP process for resource ${resource} is still running after 30 seconds." 57204076Spjd exit 1 58204076Spjdfi 59204076Spjdlogger -p local0.debug -t hast "UCARP UP is not running." 60204076Spjd 61204076Spjdcase "${fstype}" in 62204076SpjdUFS) 63204076Spjd mount | egrep -q "^${device} on " 64204076Spjd if [ $? -eq 0 ]; then 65204076Spjd # Forcibly unmount file system. 66204076Spjd out=`umount -f "${mountpoint}" 2>&1` 67204076Spjd if [ $? -ne 0 ]; then 68204076Spjd logger -p local0.error -t hast "Unable to unmount file system for resource ${resource}: ${out}." 69204076Spjd exit 1 70204076Spjd fi 71204076Spjd logger -p local0.debug -t hast "File system for resource ${resource} unmounted." 72204076Spjd fi 73204076Spjd ;; 74204076SpjdZFS) 75204076Spjd zpool list | egrep -q "^${pool} " 76204076Spjd if [ $? -eq 0 ]; then 77204076Spjd # Forcibly export file pool. 78204076Spjd out=`zpool export -f "${pool}" 2>&1` 79204076Spjd if [ $? -ne 0 ]; then 80204076Spjd logger -p local0.error -t hast "Unable to export pool for resource ${resource}: ${out}." 81204076Spjd exit 1 82204076Spjd fi 83204076Spjd logger -p local0.debug -t hast "ZFS pool for resource ${resource} exported." 84204076Spjd fi 85204076Spjd ;; 86204076Spjdesac 87204076Spjd 88204076Spjd# Change role to secondary for our resource. 89204076Spjdout=`hastctl role secondary "${resource}" 2>&1` 90204076Spjdif [ $? -ne 0 ]; then 91204076Spjd logger -p local0.error -t hast "Unable to change to role to secondary for resource ${resource}: ${out}." 92204076Spjd exit 1 93204076Spjdfi 94204076Spjdlogger -p local0.debug -t hast "Role for resource ${resource} changed to secondary." 95204076Spjd 96204076Spjdlogger -p local0.info -t hast "Successfully switched to secondary for resource ${resource}." 97204076Spjd 98204076Spjdexit 0 99