OpenVMS Source Code Demos

MARIADB_SHUTDOWN_HELPER

$!==============================================================================
$! Title  : csmis$com:mariadb_shutdown_helper.com
$! Author : Neil Rieck
$! Caveat : crashing mariadb-5 is dangerous if tx_isolation > 'READ-COMMITTED'
$! History:
$! 105 NSR 150926 copied from csmis$com:ICSIS_SHUTDOWN_HELPER.COM
$!==============================================================================
$	bel[0,8]=7								!
$	dq[0,8]=34								!
$	pid = ""								!
$	set control								!
$	set noon								!
$	write sys$output "-i-starting: ",f$environment("procedure")		!
$	ver_flag = f$environment("VERIFY_PROCEDURE")				! save: ON/OFF
$	set nover								! OFF
$	du = "neil"								!
$	dp = "passwd123"							!
$!==============================================================================
$	write sys$output "csmis$com:mariadb_shutdown_helper.com"
$	write sys$output "====================================="
$	write sys$output "DANGER DANGER DANGER"
$	write sys$output "caveat: a typical MariaDB shutdown may take 10-30 minutes"
$	inquire/nopunct choice "Are you sure? (y/N) "
$	if choice .nes. "Y" then goto fini
$!==============================================================================
$	target_proc = "MARIADB_SERVER"					!
$	gosub	find_target_proc					!
$	if (pid .eqs. "") then goto jump_past_maria_stuff		! not found so jump
$!----------------------------------------------------------------------
$	write sys$output ""						!
$	write sys$output "-i-mariadb is running"			!
$	write sys$output "-i-shutting down mariadb (pass-1-of-2: no error expected)"
$!~~~	mysqladmin --user='du' --pass='dp' ping
$	mysqladmin --user='du' --pass='dp' ver
$	mysql      --user='du' --pass='dp'
show master logs;
purge master logs before current_date;
show master logs;
exit
$	wait 0:0:05							!
$	mysqladmin --user='du' --pass='dp' refresh
$	mysqladmin --user='du' --pass='dp' status
$	mysqladmin --user='du' --pass='dp' shutdown
$	wait 0:0:05							!
$	write sys$output "-i-shutting down mariadb (pass-2-of-2: blind)"
$	mysqladmin --user='du' --pass='dp' --silent shutdown
$	wait 0:0:05							!
$	target_proc = "MARIADB_SERVER"					!
$	gosub	wait_target_proc_do_not_kill				! wait (but do not kill)
$jump_past_maria_stuff:							!
$!----------------------------------------------------------------------
$fini:
$	if ver_flag .eqs. "FALSE"
$	then
$		set nover
$	else
$		set ver
$	endif
$	write sys$output "-i-exiting: ",f$environment("procedure")	!
$	exit
$!==============================================================================
$find_target_proc:
$	kill_it = 0
$	goto common_target_proc
$stop_target_proc:
$	kill_it = 1
$common_target_proc:
$	write sys$output ""
$	write sys$output "-i-searching for: ",target_proc
$	target_length = f$length(target_proc)
$	context = ""								! init context
$scan_loop1:
$	pid   = f$pid( context )						!
$	if pid .eqs. ""								! we hit the end
$	then
$		write sys$output "-w-warning, process: ",target_proc," was not found"
$		return
$	endif
$	name = f$getjpi( pid,"PRCNAM")
$	name = f$edit( name, "UPCASE,COLLAPSE,COMPRESS")
$!~~~	write sys$output "prcnam: ",name
$!~~~	if name .eqs. target_proc
$!
$!	use f$extract to find the process we want to kill
$!	caveat: our XCOM process can have any one of the following names
$!		TID40xx2 [DISC]
$!		TID40xx2 [IDLE]
$!		TID40xx2 [RFIL]
$!
$	if f$extract(0,target_length,name) .nes. target_proc
$	then
$		goto scan_loop1
$	endif
$	if (kill_it.eq.1)
$	then
$		write sys$output "-i-stopping process: ",target_proc," pid: ",pid
$		stop proc/id='pid'
$		wait 0:0:02
$	endif
$	return
$!==============================================================================
$!
$!	wait for MARIADB_SERVER to exit on its own juice
$!	caveat: with InnoDB under Maria-5.5-25 this may require 30 minutes
$!
$wait_target_proc_kill:
$	kill_at_end = 1								!
$	goto wait_target_proc_common						!
$wait_target_proc_do_not_kill:							!
$	kill_at_end = 0								!
$wait_target_proc_common:							!
$	write sys$output ""							!
$	target_length = f$length(target_proc)					!
$	attempts = 0								! init
$restart2:									!
$	context = ""								! init
$	write sys$output "-i-waiting for: ",target_proc," to exit"		!
$scan_loop2:									!
$	pid   = f$pid( context )						!
$	if pid .eqs. ""								! we hit the end
$	then									!
$		if (attempts.eq.0)						!
$		then								!
$			write sys$output "-w-warning, process: ",target_proc," was never found"
$		else								!
$			write sys$output "-i-process: ",target_proc," has exited"
$		endif								!
$		return								!
$	endif									!
$	name = f$getjpi( pid,"PRCNAM")						!
$	name = f$edit( name, "UPCASE,COLLAPSE,COMPRESS")			!
$!~~~	write sys$output "prcnam: ",name					!
$!~~~	if name .eqs. target_proc
$	if f$extract(0,target_length,name) .eqs. target_proc			!
$	then									!
$		write sys$output "-i-found process: ",target_proc," pid: ",pid	!
$		attempts = attempts + 1						!
$!------------------------------------------------------------------------------
$! After telling mariadb to shutdown twice you should see the following events:
$! 1) flush binary logs to one or two: MYSQL055_ROOT:[log]mariadb-bin.######
$! 2) process redo/rollback files: MYSQL055_ROOT:[log]ib_logfile#.
$! 3) write the following to MYSQL055_ROOT:[mysql_server]MYSQLD.LOG
$! a)   "normal shutdown"		-- but still waiting for engines to exit
$! b)   "InnoDB: Shutdown completed"	-- InnoDB has exited
$! 4) MariaDB_Server should exit shortly after 3b
$! CAVEAT: You might be able to get away with killing the server process between
$!	steps 3a and 3b proided tx_isoloation <= READ-COMMITTED
$!------------------------------------------------------------------------------
$		if (attempts .ge. 10)						!
$		then
$		    write sys$output "-i-testing server log file (test-10)"
$		    search MYSQL055_ROOT:[mysql_server]MYSQLD.LOG; "InnoDB: Shutdown completed"/nowarn
$		    saved_status = $status
$		    yada = f$integer(saved_status)
$		    if ((yada.and.7).eq.1)
$		    then
$			write sys$output "-w-logfile looks okay (test-10) so will kill mariadb"
$			stop proc/id='pid'
$			wait 0:0:02
$			return
$		    endif
$		endif
$		if (attempts .ge. 15)						! perhaps should be 20?
$		then
$		    write sys$output "-i-testing server log file (test-15)"
$		    search MYSQL055_ROOT:[mysql_server]MYSQLD.LOG; "Normal shutdown"/nowarn
$		    saved_status = $status
$		    yada = f$integer(saved_status)
$		    if ((yada.and.7).eq.1)
$		    then
$			write sys$output "-w-logfile looks okay (test-15) so will kill mariadb"
$			stop proc/id='pid'
$			wait 0:0:02
$			return
$		    endif
$		endif
$		if (attempts .le. 30)						!
$		then
$		    write sys$output "-i-will sleep 60 seconds then try again (",attempts,"/30) time:",f$cvtime()
$		    wait 0:0:59							! wait one minute
$		    goto restart2
$		endif
$		if (kill_at_end .eq. 0)						!
$		then
$			write sys$output ""
$			write sys$output "   ======================================================================"
$			write sys$output "-w-waited for too many tries so will exit this script",bel
$			write sys$output "-w-EXITING SHUTDOWN SCRIPT",bel
$			write sys$output "-i-Hints:"
$			write sys$output "   Task-1: check for recent output to file: [.mysql_server]MYSQLD.LOG"
$			write sys$output "   You can safely kill MariaDB_Server if you see something like this:"
$			write sys$output "      150913 18:57:28  InnoDB: Starting shutdown..."
$			write sys$output "      150913 18:57:30  InnoDB: Shutdown completed; log sequence number 639589672735"
$			write sys$output "      150913 18:57:30 [Note] KAWC96$DKE3:[MYSQL055.][bin.alpha]MYSQLD.EXE;1: Shutdown complete"
$			write sys$output "   Task-2: check for recent writes to files in [.log]"
$			write sys$output "      dir [.log]/width=file=25/date=mod/since="+ dq +"-:59:59"+ dq
$			write sys$output "   ======================================================================"
$			exit							!
$		else								!
$			write sys$output "-w-waited for too many tries so will kill it"
$			stop proc/id='pid'					!
$			wait 0:0:02						!
$			return							!
$		endif								!
$	else
$		goto scan_loop2
$	endif
$!==============================================================================