diff -r da66b28a0a0b oracle
--- a/oracle	Tue Mar 25 08:24:58 2008 +0900
+++ b/oracle	Tue Mar 25 09:08:18 2008 +0900
@@ -25,6 +25,8 @@
 #	OCF_RESKEY_home (optional; else read it from /etc/oratab)
 #	OCF_RESKEY_user (optional; figure it out by checking file ownership)
 #	OCF_RESKEY_ipcrm (optional; defaults to "instance")
+#	OCF_RESKEY_clear_backupmode (optional; default to "false")
+#	OCF_RESKEY_shutdown_method (optional; default to "checkpoint/abort")
 #
 # Initialization:
 
@@ -141,6 +143,22 @@ Please report any problems. Suggestions/
 <content type="string" default="instance" />
 </parameter>
 
+<parameter name="clear_backupmode" unique="0" required="0">
+<longdesc lang="en">
+The clear of the backup mode of ORACLE.
+</longdesc>
+<shortdesc lang="en">clear_backupmode</shortdesc>
+<content type="boolean" default="false" />
+</parameter>
+
+<parameter name="shutdown_method" unique="0" required="0">
+<longdesc lang="en">
+The appointment of the stop method of ORACLE.
+</longdesc>
+<shortdesc lang="en">shutdown_method</shortdesc>
+<content type="string" default="checkpoint/abort" />
+</parameter>
+
 </parameters>
 
 <actions>
@@ -218,11 +236,11 @@ setoraenv() {
 #
 #	Run commands as the Oracle owner...
 #
-runasdba() {
+execsql() {
 	if [ "$US" = "$ORACLE_OWNER" ]; then
-		$SH
+		$sqlplus -S /nolog
 	else
-		su $ORACLE_OWNER
+		su - $ORACLE_OWNER -c "$sqlplus -S /nolog"
 	fi
 }
 
@@ -238,11 +256,7 @@ dbasql() {
 	echo "set pagesize 0"
 	for func; do $func; done
 	) |
-	if [ "$US" = "$ORACLE_OWNER" ]; then
-		$sqlplus -S /nolog
-	else
-		su $ORACLE_OWNER -c "$sqlplus -S /nolog"
-	fi | grep -v '^Connected'
+	execsql | grep -v '^Connected'
 }
 
 #
@@ -257,12 +271,47 @@ dbopen() {
 dbopen() {
 	echo 'alter database open;'
 }
+dbstop_immediate() {
+	echo 'shutdown immediate'
+}
 dbstop() {
 	echo 'alter system checkpoint;'
 	echo 'shutdown abort'
 }
 dbstart() {
 	echo 'startup'
+}
+dbstart_mount() {
+	echo 'startup mount'
+}
+dbendbackup() {
+	echo 'alter database end backup;'
+}
+db_backup_mode() {
+	echo "select 'COUNT'||count(*) from v\$backup where status='ACTIVE';"
+}
+is_clear_backupmode_set(){
+	if [ "${clear_backupmode}" = "true" ] ; then
+		return 0
+	else
+		return 1
+	fi
+}
+is_instance_in_backupmode() {
+	typeset count count
+	count="`dbasql db_backup_mode | sed 's/COUNT//'`"
+	if [ $count = "0" ]; then
+		ocf_log info "Oracle instance $ORACLE_SID is not backup mode now."
+		return 1
+	else
+		ocf_log info "Oracle instance $ORACLE_SID is backup mode now. (count=$count)"
+		return 0
+	fi
+}
+clear_backup_mode() {
+	typeset output
+	output="`dbasql dbendbackup`"
+	ocf_log info "Oracle instance $ORACLE_SID alter database end backup: $output"
 }
 getdumpdest() {
 	#echo 'select value from v$parameter where name = \'user_dump_dest\';'
@@ -385,7 +434,6 @@ ora_cleanup() {
 # mode, i.e. it appears as running, but its availability is
 # "not for general use"
 #
-
 oracle_start() {
 	typeset status output
 	if is_oracle_up; then
@@ -426,13 +474,102 @@ oracle_start() {
 }
 
 #
+# oracle_start_clear_backupmode: Start the Oracle instance
+#
+oracle_start_clear_backupmode() {
+	typeset status output
+	if is_oracle_up; then
+		ocf_log info "Oracle instance $ORACLE_SID already started ..."
+		status="`dbasql dbstat`"
+		case "$status" in
+		"OPEN")
+			: nothing to be done, we can leave right now
+			ocf_log info "Oracle instance $ORACLE_SID is already opened, return success."
+			return $OCF_SUCCESS
+		;;
+		"STARTED")
+			ocf_log info "Oracle instance $ORACLE_SID is already started, alter database mount now."
+			output=`dbasql dbmount`
+			ocf_log info "Oracle instance $ORACLE_SID is mounted: $output"
+		;;
+		"MOUNTED")
+			ocf_log info "Oracle instance $ORACLE_SID is already mounted."
+		;;
+		*) # status unknown
+			ocf_log info "Oracle instance $ORACLE_SID is unknown status, shutdown abort & startup mount now."
+			output=`dbasql dbstop_immediate dbstop dbstart_mount`
+			ocf_log info "Oracle instance $ORACLE_SID is mounted: $output"
+		;;
+		esac
+	else
+		ocf_log info "Oracle instance $ORACLE_SID startup now ..."
+		output="`dbasql dbstart_mount`"
+		ocf_log info "Oracle $ORACLE_SID is mounted: $output"
+		# try to cleanup in case of
+		# ORA-01081: cannot start already-running ORACLE - shut it down first
+		if echo "$output" | grep ORA-01081 >/dev/null 2>&1; then
+			ora_cleanup
+			output=`dbasql dbstart_mount`
+			ocf_log info "Oracle $ORACLE_SID is mounted: $output"
+		fi
+	fi
+
+	# oracle instance is mounted.
+	status="`dbasql dbstat`"
+	case "$status" in
+	"MOUNTED")
+		;;
+	*)
+		: error!!
+		ocf_log info "Oracle $ORACLE_SID can not mount."
+		return $OCF_ERR_GENERIC
+		;;
+	esac
+
+	# It is examined whether mode is "online backup mode",
+	# and if it is true, makes clear the mode.
+	# Afterwards, DB is opened.
+	if is_instance_in_backupmode; then
+		ocf_log info "Oracle instance $ORACLE_SID backup mode remains, so clear it..."
+		clear_backup_mode
+		ocf_log info "Oracle instance $ORACLE_SID backup mode cleared."
+	fi
+	ocf_log info "Oracle instance $ORACLE_SID is mounted, open now."
+	output=`dbasql dbopen`
+	ocf_log info "Oracle instance $ORACLE_SID is open: $output"
+
+	if is_oracle_up && instance_live; then
+		: cool, we are up and running
+		ocf_log info "Oracle instance $ORACLE_SID started."
+		return $OCF_SUCCESS
+	else
+		ocf_log err "Oracle instance $ORACLE_SID not started."
+		return $OCF_ERR_GENERIC
+	fi
+}
+
+#
 # oracle_stop: Stop the Oracle instance
 #
 oracle_stop() {
 	typeset status output ipc=""
 	if is_oracle_up; then
 		[ "$IPCRM" = "instance" ] && ipc=$(parseipc `dumpinstipc`)
-		output=`dbasql dbstop`
+		if [ "${shutdown_method}" = "immediate" ] ; then
+			ocf_log info "Oracle instance $ORACLE_SID shutdown immediate now ..."
+			output=`dbasql dbstop_immediate`
+			ocf_log info "Oracle instance $ORACLE_SID shutdown immediate: $output"
+
+			if is_oracle_up; then
+				ocf_log info "Oracle instance $ORACLE_SID shutdown abort now ..."
+				output=`dbasql dbstop`
+				ocf_log info "Oracle instance $ORACLE_SID shutdown abort: $output"
+			fi
+		else
+			ocf_log info "Oracle instance $ORACLE_SID shutdown checkpoint and abort now ..."
+			output=`dbasql dbstop`
+			ocf_log info "Oracle instance $ORACLE_SID shutdown checkpoint and abort: $output"
+		fi
 	else
 		ocf_log info "Oracle instance $ORACLE_SID already stopped"
 		return $OCF_SUCCESS
@@ -474,10 +611,10 @@ oracle_monitor() {
 	then
 		#ocf_log info "Oracle instance $ORACLE_SID is alive"
 		return $OCF_SUCCESS
-    else
+	else
 		ocf_log info "Oracle instance $ORACLE_SID is down"
 		return $OCF_NOT_RUNNING
-    fi
+	fi
 }
 
 #
@@ -543,10 +680,17 @@ else
 	IPCRM="$OCF_RESKEY_ipcrm"
 fi
 
+clear_backupmode=${OCF_RESKEY_clear_backupmode:-"false"}
+shutdown_method=${OCF_RESKEY_shutdown_method:-"checkpoint/abort"}
+
 # What kind of method was invoked?
 case "$1" in
 
-  start)	oracle_start
+  start)	if is_clear_backupmode_set; then
+			oracle_start_clear_backupmode
+		else
+			oracle_start
+		fi
 		exit $?;;
 
   stop)		oracle_stop
@@ -587,3 +731,5 @@ esac
 
 #
 # vim:tabstop=4:shiftwidth=4:textwidth=0:wrapmargin=0
+
+
