⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lvm.in

📁 在LINUX下实现HA的源代码
💻 IN
字号:
#!/bin/sh## $Id: LVM.in,v 1.2.4.2 2005/06/20 05:46:36 horms Exp $# # LVM## Description:	Manages an LVM volume as an HA resource### Author:	Alan Robertson# Support:	linux-ha-dev@lists.tummy.com# License:	GNU Lesser General Public License (LGPL)# Copyright:	(C) 2002 International Business Machines, Inc.##	This code significantly inspired by the LVM resource#	in FailSafe by Lars Marowsky-Bree### An example usage in /etc/ha.d/haresources: #       node1  10.0.0.170 LinuxSCSI::0:0 ServeRAID::1::1 LVM::myvolname## See usage() function below for more details...#prefix=@prefix@exec_prefix=@exec_prefix@#. @sysconfdir@/ha.d/shellfuncs. /etc/ha.d/shellfuncs###unset LC_ALL; export LC_ALLunset LANGUAGE; export LANGUAGEusage() {  methods=`LVM_methods | grep -v methods`  methods=`echo $methods | tr ' ' '|'`  cat <<-! >&1	usage: $0 <LVM-configuration file> ($methods)	usage: $0 methods	$0 manages an  Linux Volume Manager volume (LVM) as an HA resource	The 'start' operation brings the given volume online	The 'stop' operation takes the given volume offline	The 'status' operation reports whether the volume is available	The 'monitor' operation reports whether the volume seems present	The 'methods' operation reports on the methods $0 supports	$Id: LVM.in,v 1.2.4.2 2005/06/20 05:46:36 horms Exp $	!  exit 1}##	run:  run a script, and log its output.#run() {  output=`"$@" 2>&1`  rc=$?  output=`echo $output`  if    [ $rc -eq 0 ]  then     if      [ ! -z "$output" ]    then      ha_log "info: $output"    fi    return 0  else    if      [ ! -z "$output" ]    then      ha_log "ERROR: $output"    else      ha_log "ERROR: command failed: $*"    fi    return $rc  fi}## methods: What methods/operations do we support?#LVM_methods() {  cat <<-!	start	stop	status	monitor	methods	!}##	Return LVM status (silently)#LVM_status() {  if     [ "$LVM_VERSION" -eq "200" ]  then  	vgdisplay -v $1 | grep -i 'Status[ \t]*available' &>/dev/null	return $?  else  	vgdisplay $1 | grep -i 'Status.*available' >/dev/null	return $?  fi}##	Report on LVM volume status to stdout...#LVM_report_status() {  if     [ "$LVM_VERSION" -eq "200" ]  then  	VGOUT=`vgdisplay -v $1 2>&1`	echo "$VGOUT" | grep -i 'Status[ \t]*available' >/dev/null	rc=$?  else  	VGOUT=`vgdisplay $1 2>&1`  	echo "$VGOUT" | grep -i 'Status.*available' >/dev/null	rc=$?  fi  if    [ $rc -eq 0 ]  then    : Volume $1 is available  else    echo "LVM Volume $1 is not available (stopped)"    return 1  fi  if    echo "$VGOUT" | grep -i 'Access.*read/write' >/dev/null  then    echo "Volume $1 is available read/write (running)"  else    echo "Volume $1 is available read-only (running)"  fi    }##	Monitor the volume - does it really seem to be working?##LVM_monitor() {  if    LVM_status $1  then    : OK  else    ha_log "ERROR: LVM Volume $1 is offline"    return 1  fi  run vgck $1}##	Enable LVM volume#LVM_start() {  ha_log "Activating volume group $1"  if     [ "$LVM_VERSION" -eq "200" ]  then  	run vgscan  else  	run vgscan $1  fi  run vgchange -a y $1 || return 1  if    LVM_status $1  then    : OK Volume $1 activated just fine!    return 0  else    ha_log "ERROR: LVM: $1 did not activate correctly"    return 1  fi}##	Disable the LVM volume#LVM_stop() {  ha_log "Deactivating volume group $1"  run vgchange -a n $1 || return 1  if    LVM_status $1  then    ha_log "ERROR: LVM: $1 did not stop correctly"    return 1  fi  return 0}##	'main' starts here...#if  [ $# -eq 1 -a "methods" = "$1" ]then  LVM_methods  exit $?fiLVM_VERSION=`/sbin/lvmiopversion`rc=$?if   [ $rc -ne 0 ]then  ha_log "ERROR: LVM: $1 could not determine LVM version"  return  $rcfiVOLUME=$1# What kind of method was invoked?case "$2" in  start)	LVM_start $1		exit $?;;  stop)		LVM_stop $1		exit $?;;  status)	LVM_report_status $1		exit $?;;  monitor)	LVM_monitor $1		exit $?;;  methods)	LVM_methods		exit $?;;esacusage

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -