#!/bin/sh # # OCF RA for OCFS2 on DRBD # # Copyright (c) 2008,2009 Barton IT-Consulting # Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Brée # 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. # # Initialization: . ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - meta_data() { cat < 1.5 This Resource Agent starts and stops OCFS2 file systems located on DRBD devices. OCFS2 on DRBD resource agent ID of the DRBD resource ID of the DRBD resource DRBD device DRBD device Mountpoint for OCFS2 filesystem Mountpoint for OCFS2 filesystem Reload CRON configuration after mounting OCFS2 filesystem Reload CRON configuration END } # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ClusterFS_usage() { echo "usage: $0 {start|stop|monitor|validate-all|meta-data}" } ClusterFS_start() { mkdir -p "$OCF_RESKEY_mountpoint" drbdadm primary "$OCF_RESKEY_drbd" if [ $? -ne 0 ]; then return $OCF_ERR_GENERIC fi mount -t ocfs2 -o noatime \ "$OCF_RESKEY_drbd_dev" "$OCF_RESKEY_mountpoint" if [ $? -ne 0 ]; then return $OCF_ERR_GENERIC fi if [ "$OCF_RESKEY_reload_cron" = "1" ]; then [ -d /etc/cron.d ] && touch /etc/cron.d fi return $OCF_SUCCESS } ClusterFS_stop() { mount | grep "$OCF_RESKEY_drbd_dev on " >/dev/null if [ $? -eq 0 ]; then umount "$OCF_RESKEY_mountpoint" if [ $? -ne 0 ]; then # try harder, kill processes on this filesystem pids=$(ps ax|awk "{print \$1}"|grep -v PID) for p in $pids; do lsof -p $p -n | grep " $OCF_RESKEY_mountpoint" \ >/dev/null 2>&1 [ $? -eq 0 ] || continue kill $p done sleep 3 pids=$(ps ax|awk "{print \$1}"|grep -v PID) for p in $pids; do lsof -p $p -n | grep " $OCF_RESKEY_mountpoint" \ >/dev/null 2>&1 [ $? -eq 0 ] || continue kill -9 $p done sleep 1 umount "$OCF_RESKEY_mountpoint" if [ $? -ne 0 ]; then return $OCF_ERR_GENERIC fi fi fi drbdadm secondary "$OCF_RESKEY_drbd" if [ "$OCF_RESKEY_reload_cron" = "1" ]; then [ -d /etc/cron.d ] && touch /etc/cron.d fi return $OCF_SUCCESS } ClusterFS_monitor() { mount | grep "$OCF_RESKEY_drbd_dev on " >/dev/null if [ $? -eq 0 ]; then return $OCF_SUCCESS fi return $OCF_NOT_RUNNING } ClusterFS_validate() { if [ -z "$OCF_RESKEY_drbd" ]; then return $OCF_ERR_ARGS fi if [ -z "$OCF_RESKEY_drbd_dev" ]; then return $OCF_ERR_ARGS fi if [ -z "$OCF_RESKEY_mountpoint" ]; then return $OCF_ERR_ARGS fi return $OCF_SUCCESS } case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; start) ClusterFS_start ;; stop) ClusterFS_stop ;; monitor) ClusterFS_monitor ;; validate-all) ClusterFS_validate ;; usage|help) ClusterFS_usage exit $OCF_SUCCESS ;; *) ClusterFS_usage exit $OCF_ERR_UNIMPLEMENTED ;; esac rc=$? ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc" exit $rc # -eof-