Restart the JVM in Domino without rebooting the Windows server.

This is a helpful agent when you have a minor memory leak that you can't isolate in your system. Over time, the JVM will eventually fill up and cause an Out-Of-Memory failure and you won't be able to perform any Java remote calls until you reset/restart the JVM to clear the memory. One method to do this is to reboot the entire Domino and/or Windows server, but this takes a lot of time and can't be called via LotusScript. The agent below will check the server log every five minutes and if it finds an out-of-memory error, it sends the "restart task http" command which will restart the entire JVM and notify you via email. This typically takes around 20 seconds to complete, so it's much more efficient that restarting the server.
LotusScript


Create the lotus script agent below on a schedule basis of every 5 minutes. It will also skip the restart if it has already been done recently. If you're having multiple JVM failures within the window of one log entry document, you should really address that issue instead of using this agent to clear it. Be sure to set the runtime security of the agent to "3. Allow restricted operations with full administration rights".

Sub Initialize
	
	Dim session As New NotesSession
	Dim db As notesdatabase
	Set db = session.currentdatabase
	
	Dim Ldb As NotesDatabase
	Set Ldb = session.GetDatabase(db.server, "log.nsf")
	If Not Ldb.IsOpen Then Exit Sub
	Dim view As NotesView
	Set view = Ldb.GetView("MiscEvents")
	Dim doc As notesdocument
	Set doc = view.GetLastDocument
	If doc Is Nothing Then Exit Sub
	
	Dim item As NotesItem
	Set item = doc.GetFirstItem("EventList")
	Dim x As Long
	Dim stringtotest As String
	Dim trigger As String
	
	'#################################################
	trigger = Lcase("OutOfMemoryError")
	'#################################################
	
	'parse thru all values from last to first
	For x = Ubound(item.values) To 0 Step -1
		
		'retrieve the row by index value
		stringtotest = Lcase(item.values(x)) 
		
		'test if the http task has already been restarted, if so, skip and exit
		If Right(stringtotest,17) = "restart task http" Then Exit For
		
		'continue to test if the trigger value is present in this index
		If Instr(1, stringtotest, trigger) >1 Then
			
			'Restart the JVM via http task.			
			Dim consoleReturn As String 
			consoleReturn = session.SendConsoleCommand( "", "restart task http" )		
	
			'Send notification
			Dim edoc As notesdocument
			Set edoc = db.CreateDocument
			'///////////////////////////////////////////////////////////
			edoc.INetFrom = "ServerName <ServerEmailAddress@domain.com>"
			edoc.From = "ServerName <ServerEmailAddress@domain.com>"
			edoc.Submitter = "ServerName <ServerEmailAddress@domain.com>"
			'///////////////////////////////////////////////////////////
			edoc.Form = "Memo"	
			edoc.Subject = "URGENT! - JVM Memory Failure"
			Dim rtitem As NotesRichTextItem
			Set rtItem = edoc.CreateRichTextItem("Body")
			Call rtitem.AppendText("An Out-Of-Memory Error has occured on ServerName.")
			Call rtitem.Addnewline(2)
			Call rtitem.AppendText("The RESTART TASK HTTP command was sent to the console to restart the JVM.")
			Call rtitem.Addnewline(2)
			edoc.Sendto = "YourEmailAddress@domain.com"
			Call edoc.Send( False )
			
			Exit For
		End If
	Next x
	
End Sub

Images/Screenshots:

Posted by fbrefere001 on Thursday August 21, 2014