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