21.4.5 待機系の汎用スクリプトファイルの作成

待機系でリカバリ処理を実行するための汎用スクリプトファイルをVBScriptで記述します。

<この項の構成>
(1) 待機系の汎用スクリプトファイルの例
(2) 待機系の汎用スクリプトファイルの関数
(3) 待機系の汎用スクリプトファイルの変数

(1) 待機系の汎用スクリプトファイルの例

N:1リカバリシステムの待機系で使用する汎用スクリプトファイルの例を次に示します。なお,汎用スクリプトファイルに定義する関数と変数については,「(2) 待機系の汎用スクリプトファイルの関数」,および「(3) 待機系の汎用スクリプトファイルの変数」を参照してください。

Dim WshShell, fso, oExec, oRun, oCosmiHome, oRecover, oCjsleep

Set WshShell = CreateObject("WScript.Shell")
oCosmiHome = WshShell.ExpandEnvironmentStrings("%COSMINEXUS_HOME%")
oRecover = """" & oCosmiHome & "¥CC¥server¥bin¥cjstartrecover"""
oCjsleep = """" & oCosmiHome & "¥CC¥server¥bin¥cjsleep"""

'==== Open ====
Function Open( )
   Resource.LogInformation "======== Entering Open. ========"
   ' --- J2EE Server Name ---
   If Resource.PropertyExists("ServerName") = False Then
       Resource.LogInformation "### Private property ServerName is not set. ###"
   End If
   ' --- Inprocess OTS Status Path ---
   If Resource.PropertyExists("StatusPath") = False Then
       Resource.LogInformation "### Private property StatusPath is not set. ###"
   End If
   ' --- Cluster IP Address ---
   If Resource.PropertyExists("IPAddress") = False Then
       Resource.LogInformation "### Private property IPAddress is not set. ###"
   End If
   ' --- Cluster Host Name ---
   If Resource.PropertyExists("HostName") = False Then
       Resource.LogInformation "### Private property HostName is not set. ###"
   End If
   Open = True
End Function

'==== Online ====
Function Online( )
   Resource.LogInformation "======== Entering Online. ========"
   RecoverSuccess = 0

   '--- private properties ---
   If Resource.PropertyExists("ServerName") = False Or _
      Resource.PropertyExists("StatusPath") = False Or _
      Resource.PropertyExists("IPAddress") = False Or _
      Resource.PropertyExists("HostName") = False Then

      Resource.LogInformation "### Private property is not set. ###"
      Online = False
      Exit Function
   End If

   ' --- A parameters of recover command ---
   Dir_Name = "C:¥MSCS¥RecoverExclusive"
   Sleep_Time = 60
   Retries = 30

   Set fso = CreateObject("Scripting.FileSystemObject")

   oRun = oRecover & " " & Resource.ServerName _
                   & " -p vbroker.se.iiop_tp.host=" & Resource.IPAddress _
                   & " -p ejbserver.distributedtx.ots.status.directory1=" & Resource.StatusPath _
                   & " -t 600"

   On Error Resume Next
   For i=0 To Retries
       Err.Clear
       fso.CreateFolder(Dir_Name)
       If Err.Number = 0 Then
           '--- cjstartrecover ---
           Resource.LogInformation "[" & Resource.HostName & "]--- cjstartrecover start... ---"
           Resource.LogInformation "[" & Resource.HostName & "]" & oRun
           Set oResult = WshShell.Run(oRun, 0, True)
           If oResult <> 0 Then
               Resource.LogInformation "[" & Resource.HostName & _
                   "]### cjstartrecover command is failed. ### rtn=" & oResult
           End If
           fso.DeleteFolder(Dir_Name)
           RecoverSuccess = 1
           Resource.LogInformation "[" & Resource.HostName & "]--- The revover command finished. ---"
           Exit For
       Else
           Resource.LogInformation "[" & Resource.HostName & "]CreateFolder()=" & Err.Number & " " & Err.Description
           Resource.LogInformation "[" & Resource.HostName & "]" & oCjsleep & " " & Sleep_Time & " retry=" & i
           WshShell.Run oCjsleep & " " & Sleep_Time, 0, True
       End If
   Next
   On Error Goto 0

   If RecoverSuccess = 0 Then
       Resource.LogInformation "[" & Resource.HostName & "]### Timeout occurred before starting cjstartrecover. ###"
       Resource.LogInformation "[" & Resource.HostName & "]### Perform following command manually. ###"
       Resource.LogInformation "[" & Resource.HostName & "]" & oRun
       Online = False
       Exit Function
   End If

   WshShell.Run "cluster res " & Resource.Name & " /off", 0, False
   Online = True
End Function

'==== LooksAlive ====
Function LooksAlive( )
   Resource.LogInformation "======== Entering LooksAlive. ========"
   LooksAlive = True
End Function

'==== IsAlive ====
Function IsAlive( )
   Resource.LogInformation "======== Entering IsAlive. ========"
   IsAlive = True
End Function

'==== Offline ====
Function Offline( )
   Resource.LogInformation "======== Entering Offline. ========"
   Offline = True
End Function

'==== Close ====
Function Close( )
   Resource.LogInformation "======== Entering Close. ========"
   Close = True
End Function

'==== Terminate ====
Function Terminate( )
   Resource.LogInformation "======== Entering Terminate. ========"
   Terminate = True
End Function

(2) 待機系の汎用スクリプトファイルの関数

汎用スクリプトファイルには,関数を定義する必要があります。各関数の戻り値は,正常終了時には「True」を,異常終了時には「False」を返します。待機系の汎用スクリプトファイルに定義する関数を次の表に示します。

表21-5 待機系の汎用スクリプトファイルの関数(N:1リカバリシステムの場合)

関数名内容
Openこのスクリプトファイルが開かれるときに実行される関数です。プライベートプロパティが設定されているかどうかを判定します。
Online汎用スクリプトリソースのオンライン時に実行される関数です。CreateFolderメソッドを利用して,リカバリ処理が排他的に実行されるようにします。Dir_Nameフォルダが作成できた場合はErr.Numberに0が設定され,リカバリ処理を実行します。リカバリ処理終了後,Dir_Nameフォルダを削除して,リソースをオフラインにします。フォルダが作成できなかった場合は,Err.Numberに0以外が設定され,Sleep_Timeに設定した時間(秒)スリープし,再度フォルダの作成を試みます。リカバリ処理の実行が成功するまでRetriesに設定した回数分繰り返します。
LooksAlive常に「True」を返します。
IsAlive常に「True」を返します。
Offline常に「True」を返します。
Close常に「True」を返します。
Terminate常に「True」を返します。

(3) 待機系の汎用スクリプトファイルの変数

待機系の汎用スクリプトファイルでは,必要に応じて次の表に示す変数の値を変更してください。

表21-6 待機系の汎用スクリプトファイルの変数(N:1リカバリシステムの場合)

変数名内容
Dir_Name排他制御用のフォルダのパス
指定例:C:¥recover¥exclusive
この例では,C:¥recoverフォルダが存在している必要があります。exclusiveフォルダは存在していてはいけません。
Sleep_Timeリカバリコマンドの排他制御時にスリープする時間(秒)
Retriesリカバリコマンドの排他制御時のリトライ回数