1#!/bin/sh 2# 3# Copyright (c) 2010 The FreeBSD Foundation 4# All rights reserved. 5# 6# This software was developed by Pawel Jakub Dawidek under sponsorship from 7# the FreeBSD Foundation. 8# 9# Redistribution and use in source and binary forms, with or without 10# modification, are permitted provided that the following conditions 11# are met: 12# 1. Redistributions of source code must retain the above copyright 13# notice, this list of conditions and the following disclaimer. 14# 2. Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in the 16# documentation and/or other materials provided with the distribution. 17# 18# THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 19# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 22# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28# SUCH DAMAGE. 29# 30# $FreeBSD$ 31 32# Resource name as defined in /etc/hast.conf. 33resource="test" 34# Supported file system types: UFS, ZFS 35fstype="UFS" 36# ZFS pool name. Required only when fstype == ZFS. 37pool="test" 38# File system mount point. Required only when fstype == UFS. 39mountpoint="/mnt/test" 40# Name of HAST provider as defined in /etc/hast.conf. 41# Required only when fstype == UFS. 42device="/dev/hast/${resource}" 43 44export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 45 46# KIll UP script if it still runs in the background. 47sig="TERM" 48for i in `jot 30`; do 49 pgid=`pgrep -f ucarp_up.sh | head -1` 50 [ -n "${pgid}" ] || break 51 kill -${sig} -- -${pgid} 52 sig="KILL" 53 sleep 1 54done 55if [ -n "${pgid}" ]; then 56 logger -p local0.error -t hast "UCARP UP process for resource ${resource} is still running after 30 seconds." 57 exit 1 58fi 59logger -p local0.debug -t hast "UCARP UP is not running." 60 61case "${fstype}" in 62UFS) 63 mount | egrep -q "^${device} on " 64 if [ $? -eq 0 ]; then 65 # Forcibly unmount file system. 66 out=`umount -f "${mountpoint}" 2>&1` 67 if [ $? -ne 0 ]; then 68 logger -p local0.error -t hast "Unable to unmount file system for resource ${resource}: ${out}." 69 exit 1 70 fi 71 logger -p local0.debug -t hast "File system for resource ${resource} unmounted." 72 fi 73 ;; 74ZFS) 75 zpool list | egrep -q "^${pool} " 76 if [ $? -eq 0 ]; then 77 # Forcibly export file pool. 78 out=`zpool export -f "${pool}" 2>&1` 79 if [ $? -ne 0 ]; then 80 logger -p local0.error -t hast "Unable to export pool for resource ${resource}: ${out}." 81 exit 1 82 fi 83 logger -p local0.debug -t hast "ZFS pool for resource ${resource} exported." 84 fi 85 ;; 86esac 87 88# Change role to secondary for our resource. 89out=`hastctl role secondary "${resource}" 2>&1` 90if [ $? -ne 0 ]; then 91 logger -p local0.error -t hast "Unable to change to role to secondary for resource ${resource}: ${out}." 92 exit 1 93fi 94logger -p local0.debug -t hast "Role for resource ${resource} changed to secondary." 95 96logger -p local0.info -t hast "Successfully switched to secondary for resource ${resource}." 97 98exit 0 99