Blame SOURCES/bz1232376-oracle-agent-update.diff

261ad6
diff --git a/heartbeat/oracle b/heartbeat/oracle
261ad6
index 5ecc2f3..c629eb6 100755
261ad6
--- a/heartbeat/oracle
261ad6
+++ b/heartbeat/oracle
261ad6
@@ -27,6 +27,9 @@
261ad6
 #	OCF_RESKEY_ipcrm (optional; defaults to "instance")
261ad6
 #	OCF_RESKEY_clear_backupmode (optional; default to "false")
261ad6
 #	OCF_RESKEY_shutdown_method (optional; default to "checkpoint/abort")
261ad6
+#	OCF_RESKEY_monuser (optional; defaults to "OCFMON")
261ad6
+#	OCF_RESKEY_monpassword (optional; defaults to "OCFMON")
261ad6
+#	OCF_RESKEY_monprofile (optional; defaults to "OCFMONPROFILE")
261ad6
 #
261ad6
 # Initialization:
261ad6
 
261ad6
@@ -56,6 +59,11 @@ oracle_usage() {
261ad6
 	!
261ad6
 }
261ad6
 
261ad6
+# Defaults
261ad6
+OCF_RESKEY_monuser_default="OCFMON"
261ad6
+OCF_RESKEY_monpassword_default="OCFMON"
261ad6
+OCF_RESKEY_monprofile_default="OCFMONPROFILE"
261ad6
+
261ad6
 oracle_meta_data() {
261ad6
 	cat <
261ad6
 
261ad6
@@ -100,6 +108,39 @@ If this does not work for you, just set it explicitely.
261ad6
 <content type="string" default="" />
261ad6
 </parameter>
261ad6
 
261ad6
+<parameter name="monuser" unique="0">
261ad6
+<longdesc lang="en">
261ad6
+Monitoring user name. Every connection as
261ad6
+sysdba is logged in an audit log. This can
261ad6
+result in a large number of new files created.
261ad6
+A new user is created (if it doesn't exist) in
261ad6
+the start action and subsequently used in monitor.
261ad6
+It should have very limited rights. Make sure
261ad6
+that the password for this user does not expire.
261ad6
+</longdesc>
261ad6
+<shortdesc lang="en">monuser</shortdesc>
261ad6
+<content type="string" default="$OCF_RESKEY_monuser_default" />
261ad6
+</parameter>
261ad6
+
261ad6
+<parameter name="monpassword" unique="0">
261ad6
+<longdesc lang="en">
261ad6
+Password for the monitoring user. Make sure
261ad6
+that the password for this user does not expire.
261ad6
+</longdesc>
261ad6
+<shortdesc lang="en">monpassword</shortdesc>
261ad6
+<content type="string" default="$OCF_RESKEY_monpassword_default" />
261ad6
+</parameter>
261ad6
+
261ad6
+<parameter name="monprofile" unique="0">
261ad6
+<longdesc lang="en">
261ad6
+Profile used by the monitoring user. If the
261ad6
+profile does not exist, it will be created
261ad6
+with a non-expiring password.
261ad6
+</longdesc>
261ad6
+<shortdesc lang="en">monprofile</shortdesc>
261ad6
+<content type="string" default="$OCF_RESKEY_monprofile_default" />
261ad6
+</parameter>
261ad6
+
261ad6
 <parameter name="ipcrm" unique="0">
261ad6
 <longdesc lang="en">
261ad6
 Sometimes IPC objects (shared memory segments and semaphores)
261ad6
@@ -216,7 +257,7 @@ execsql() {
261ad6
 	if [ "$US" = "$ORACLE_OWNER" ]; then
261ad6
 		sqlplus -S /nolog
261ad6
 	else
261ad6
-		su - $ORACLE_OWNER -c ". $ORA_ENVF; sqlplus -S /nolog"
261ad6
+		su - $ORACLE_OWNER -s /bin/sh -c ". $ORA_ENVF; sqlplus -S /nolog"
261ad6
 	fi
261ad6
 }
261ad6
 
261ad6
@@ -250,7 +291,7 @@ dbasql() {
261ad6
 	runsql "connect / as sysdba" $*
261ad6
 }
261ad6
 monsql() {
261ad6
-	runsql "connect $MONUSR/$MONUSR" $*
261ad6
+	runsql "connect $MONUSR/\"$MONPWD\"" $*
261ad6
 }
261ad6
 # use dbasql_one if the query should result in a single line output
261ad6
 # at times people stuff commands in oracle .profile
261ad6
@@ -325,22 +366,73 @@ getipc() {
261ad6
 	echo "oradebug tracefile_name"
261ad6
 	echo "oradebug ipc"
261ad6
 }
261ad6
+show_mon_profile() {
261ad6
+	echo "select PROFILE from dba_profiles where PROFILE='$MONPROFILE';"
261ad6
+}
261ad6
+mk_mon_profile() {
261ad6
+	cat<
261ad6
+create profile $MONPROFILE limit FAILED_LOGIN_ATTEMPTS UNLIMITED PASSWORD_LIFE_TIME UNLIMITED;
261ad6
+EOF
261ad6
+}
261ad6
 show_mon_user() {
261ad6
 	echo "select USERNAME, ACCOUNT_STATUS from dba_users where USERNAME='$MONUSR';"
261ad6
 }
261ad6
 mk_mon_user() {
261ad6
 	cat<
261ad6
-create user $MONUSR identified by $MONUSR;
261ad6
+create user $MONUSR identified by "$MONPWD" profile $MONPROFILE;
261ad6
 grant create session to $MONUSR;
261ad6
 grant select on v_\$instance to $MONUSR;
261ad6
 EOF
261ad6
 }
261ad6
-check_mon_user() {
261ad6
+show_mon_user_profile() {
261ad6
+	echo "select PROFILE from dba_users where USERNAME='$MONUSR';"
261ad6
+}
261ad6
+set_mon_user_profile() {
261ad6
+	echo "alter user $MONUSR profile $MONPROFILE;"
261ad6
+}
261ad6
+reset_mon_user_password() {
261ad6
+	echo "alter user $MONUSR identified by $MONPWD;"
261ad6
+}
261ad6
+check_mon_profile() {
261ad6
 	local output
261ad6
-	dbasql show_mon_user | grep -w "^$MONUSR" >/dev/null &&
261ad6
+	output=`dbasql show_mon_profile`
261ad6
+	if echo "$output" | grep -iw "^$MONPROFILE" >/dev/null; then
261ad6
 		return 0
261ad6
+	fi
261ad6
+	output=`dbasql mk_mon_profile show_mon_profile`
261ad6
+	if echo "$output" | grep -iw "^$MONPROFILE" >/dev/null; then
261ad6
+		return 0
261ad6
+	else
261ad6
+		ocf_log err "could not create $MONPROFILE oracle profile"
261ad6
+		ocf_log err "sqlplus output: $output"
261ad6
+		return 1
261ad6
+	fi
261ad6
+}
261ad6
+check_mon_user() {
261ad6
+	local output
261ad6
+	local output2
261ad6
+
261ad6
+	output=`dbasql show_mon_user`
261ad6
+	if echo "$output" | grep -iw "^$MONUSR" >/dev/null; then
261ad6
+		if echo "$output" | grep -w "EXPIRED" >/dev/null; then
261ad6
+			dbasql reset_mon_user_password
261ad6
+		fi
261ad6
+		output=`dbasql show_mon_user_profile`
261ad6
+		if echo "$output" | grep -iw "^$MONPROFILE" >/dev/null; then
261ad6
+			return 0
261ad6
+		else
261ad6
+			output=`dbasql set_mon_user_profile`
261ad6
+			output2=`dbasql show_mon_user_profile`
261ad6
+			if echo "$output2" | grep -iw "^$MONPROFILE" >/dev/null; then
261ad6
+				return 0
261ad6
+			fi
261ad6
+			ocf_log err "could not set profile for $MONUSR oracle user"
261ad6
+			ocf_log err "sqlplus output: $output( $output2 )"
261ad6
+			return 1
261ad6
+		fi
261ad6
+	fi
261ad6
 	output=`dbasql mk_mon_user show_mon_user`
261ad6
-	if echo "$output" | grep -w "^$MONUSR" >/dev/null; then
261ad6
+	if echo "$output" | grep -iw "^$MONUSR" >/dev/null; then
261ad6
 		return 0
261ad6
 	else
261ad6
 		ocf_log err "could not create $MONUSR oracle user"
261ad6
@@ -417,7 +509,7 @@ ipcdesc() {
261ad6
 }
261ad6
 rmipc() {
261ad6
 	local what=$1 id=$2
261ad6
-	ipcs -$what | filteroraipc | grep -w $id >/dev/null 2>&1 ||
261ad6
+	ipcs -$what | filteroraipc | grep -iw $id >/dev/null 2>&1 ||
261ad6
 		return
261ad6
 	ocf_log info "Removing `ipcdesc $what` $id."
261ad6
 	ipcrm -$what $id
261ad6
@@ -447,6 +539,8 @@ is_proc_running() {
261ad6
 # instance in OPEN state?
261ad6
 instance_live() {
261ad6
 	local status=`monsql_one dbstat`
261ad6
+	[ "$status" = OPEN ] && return 0
261ad6
+	status=`dbasql_one dbstat`
261ad6
 	if [ "$status" = OPEN ]; then
261ad6
 		return 0
261ad6
 	else
261ad6
@@ -473,7 +567,7 @@ ora_cleanup() {
261ad6
 }
261ad6
 
261ad6
 oracle_getconfig() {
261ad6
-	ora_common_getconfig "$OCF_RESKEY_sid" "$OCF_RESKEY_home" "$OCF_RESKEY_user" "$OCF_RESKEY_tns_admin"
261ad6
+	ora_common_getconfig "$OCF_RESKEY_sid" "$OCF_RESKEY_home" "$OCF_RESKEY_user"
261ad6
 
261ad6
 	clear_backupmode=${OCF_RESKEY_clear_backupmode:-"false"}
261ad6
 	shutdown_method=${OCF_RESKEY_shutdown_method:-"checkpoint/abort"}
261ad6
@@ -493,7 +587,7 @@ oracle_getconfig() {
261ad6
 oracle_start() {
261ad6
 	local status output
261ad6
 	if is_proc_running; then
261ad6
-		status="`monsql_one dbstat`"
261ad6
+		status="`dbasql_one dbstat`"
261ad6
 		case "$status" in
261ad6
 		"OPEN")
261ad6
 			: nothing to be done, we can leave right now
261ad6
@@ -541,6 +635,11 @@ oracle_start() {
261ad6
 	fi
261ad6
 	output=`dbasql dbopen`
261ad6
 
261ad6
+	# check/create the monitor profile
261ad6
+	if ! check_mon_profile; then
261ad6
+		return $OCF_ERR_GENERIC
261ad6
+	fi
261ad6
+
261ad6
 	# check/create the monitor user
261ad6
 	if ! check_mon_user; then
261ad6
 		return $OCF_ERR_GENERIC
261ad6
@@ -650,7 +749,12 @@ show_procs() {
261ad6
 proc_pids() { show_procs | awk '{print $1}'; }
261ad6
 PROCS_CLEANUP_TIME="30"
261ad6
 
261ad6
-MONUSR="OCFMON"
261ad6
+MONUSR=${OCF_RESKEY_monuser:-$OCF_RESKEY_monuser_default}
261ad6
+MONPWD=${OCF_RESKEY_monpassword:-$OCF_RESKEY_monpassword_default}
261ad6
+MONPROFILE=${OCF_RESKEY_monprofile_default:-$OCF_RESKEY_monprofile_default}
261ad6
+
261ad6
+MONUSR=$(echo $MONUSR | awk '{print toupper($0)}')
261ad6
+MONPROFILE=$(echo $MONPROFILE | awk '{print toupper($0)}')
261ad6
 OCF_REQUIRED_PARAMS="sid"
261ad6
 OCF_REQUIRED_BINARIES="sqlplus"
261ad6
 ocf_rarun $*
261ad6
diff --git a/heartbeat/oralsnr b/heartbeat/oralsnr
261ad6
index 2409017..a91eeab 100755
261ad6
--- a/heartbeat/oralsnr
261ad6
+++ b/heartbeat/oralsnr
261ad6
@@ -158,7 +158,7 @@ runasdba() {
261ad6
 		(
261ad6
 		echo ". $ORA_ENVF"
261ad6
 		cat
261ad6
-		) | su - $ORACLE_OWNER
261ad6
+		) | su -s $SH - $ORACLE_OWNER
261ad6
 	fi
261ad6
 }
261ad6
 
261ad6
@@ -268,7 +268,7 @@ oralsnr_validate_all() {
261ad6
 # used in ora-common.sh
261ad6
 show_procs() {
261ad6
 	ps -e -o pid,user,args |
261ad6
-		grep '[t]nslsnr' | grep -w "$listener" | grep -w "$ORACLE_OWNER"
261ad6
+		grep '[t]nslsnr' | grep -i -w "$listener" | grep -w "$ORACLE_OWNER"
261ad6
 }
261ad6
 proc_pids() { show_procs | awk '{print $1}'; }
261ad6
 PROCS_CLEANUP_TIME="10"