Welcome, guest | Sign In | My Account | Store | Cart

Start and monitor Cloudscape network server.

Tcl, 310 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
@echo off

setlocal

echo ###################################################
echo # Start Cloudscape Server on %computername%
echo ###################################################

set derbyDir=D:\CloudscapeDatabases
set traceDir=D:\CloudscapeDatabases\trace

set CLASSPATH=%CLASSPATH%;d:\IBM\Cloudscape_10.1\lib\derby.jar
set CLASSPATH=%CLASSPATH%;d:\IBM\Cloudscape_10.1\lib\derbyclient.jar
set CLASSPATH=%CLASSPATH%;d:\IBM\Cloudscape_10.1\lib\derbynet.jar
set CLASSPATH=%CLASSPATH%;d:\IBM\Cloudscape_10.1\lib\derbytools.jar

D:\scripts\TCL\JACL\cloudscape\startNetworkServer.tcl %derbyDir% %traceDir%

endlocal

=====================================================================

# 
# start cloudscape network server 

####################################################################
# Patrick Finnegan 17/11/2005.  V1. 
####################################################################

puts "\n **** executing [info script] **** \n"

# make script drive independent.

set drive [lindex [file split [info script]] 0 ] 

puts "\n proclib = $drive/scripts/TCL/proclib"

source $drive/scripts/TCL/proclib/checkFile_proc.tcl
source $drive/scripts/TCL/proclib/smtp_proc.tcl
source $drive/scripts/TCL/proclib/reportHeader_proc.tcl

####################################################################
# Get Cloudscape connection.
####################################################################
proc startServer { traceFile } {

   puts "\n**********"
   puts "startServer"
   puts "**********\n"

   global env 
   global null

   # import required classes 

   java::import java.net.InetAddress
   java::import org.apache.derby.drda.NetworkServerControl

   puts "\nimported classes are:\n"
   
   foreach i [java::import] {
       
      puts [ format "%-5s %-50s" " " $i ] 

   }

   if { [ catch { java::new NetworkServerControl } r ] == 0 } {
   
        set NetworkServerControl $r 

   } else {

        puts $r 
        return -code error

   }

   puts "\nNetworkServerControl start\n" 

   if { [ catch { $NetworkServerControl start $null } r ] == 0 } {

          puts  $r 
          puts  $traceFile $r 
          flush $traceFile 

   } else {

          puts "\n$r\n"
          puts $traceFile "\n$r\n"
          flush $traceFile 
          return -code error

   } 

   flush $traceFile 

   java::lock $NetworkServerControl

   return $NetworkServerControl

}
####################################################################
# Get Cloudscape server info.
####################################################################
proc serverInfo { traceFile NetworkServerControl } {

   puts "\n**********"
   puts "serverInfo"
   puts "**********\n"

   global env
   global null

   set hostName [ lindex [ array get env COMPUTERNAME ] 1 ]
   set hostAddress [ java::call InetAddress getByName "0.0.0.0" ]

   puts "\nNetworkServerControl ping\n" 

   if { [ catch { $NetworkServerControl ping } r ] == 0 } {

          puts  $r 
          puts  $traceFile $r 
          flush $traceFile 

   } else {

          puts "\n$r\n"
          puts $traceFile "\n$r\n"
          flush $traceFile 
          return -code error

   } 

   puts "\nNetworkServerControl getSysinfo\n" 

   if { [ catch { $NetworkServerControl getSysinfo } r ] == 0 } {

       puts  $r 
       puts  $traceFile $r 
       flush $traceFile 

   } else {

       puts "\n$r\n"
       puts $traceFile "\n$r\n"
       flush $traceFile 
       return -code error

   }

   puts "\nNetworkServerControl getRuntimeInfo\n" 

   if { [ catch { $NetworkServerControl getRuntimeInfo } r ] == 0 } {

       puts  $r 
       puts  $traceFile $r 
       flush $traceFile 

   } else {

       puts "\n$r\n"
       puts $traceFile "\n$r\n"
       flush $traceFile 
       return -code error

   }

   flush $traceFile 

}
####################################################################
# Ping Cloudscape Server.
####################################################################
proc pingServer { traceFile NetworkServerControl } {

   puts "\n**********"
   puts "pingServer"
   puts "**********\n"

   global null

   flush $traceFile 

   while {1} {

       after 30000
      
       puts "\n ping the server \n"

       if { [ catch { $NetworkServerControl ping } r ] == 0 } {

	   set s "[ clock format [ clock seconds ] ] NetworkServerControl ping ok "
	   puts  $s 
	   puts  $traceFile $s 
           flush $traceFile 

       } else {

	   puts "\n$r\n"
	   puts $traceFile "\n$r\n"
           flush $traceFile 
	   return -code error

       }

   flush $traceFile 

   }

}
####################################################################
# Main Control.
####################################################################

puts "\n argc = $argc \n"

if {$argc < 2} {

        return -code error "\nerror - not enough arguments supplied.\nSupply Derby dir and trace directory.\n"

}

set computerName  $::env(COMPUTERNAME)

set derbyDir      [ lindex $argv 0 ]
set traceDir      [ lindex $argv 1 ]
set traceFile     [ file join $traceDir traceFile\.txt ]
set traceFileId   [ open $traceFile  w ]

set body         $traceFile

checkFile $traceDir

set header   "$computerName: start Cloudscape Server"
reportHeader $traceFileId $header $traceFile

set computerTime [clock format [clock seconds] -format "%d-%m-%Y %H.%M.%S"]

puts "tracefile = $traceFile" 

# set database properties.

lappend optList "-Dderby.drda.host=$computerName"
# if configured to listen on the loopback address then will only accept connections from  local host. 
#lappend optList "-Dderby.drda.host=0.0.0.0"
lappend optList "-Dderby.drda.keepAlive=true"
lappend optList "-Dderby.infolog.append=true"
lappend optList "-Dderby.drda.logConnections=true"
lappend optList "-Dderby.drda.maxThreads=50"
lappend optList "-Dderby.drda.minThreads=10"
lappend optList "-Dderby.drda.portNumber=1527"
# start programatically rather then from property.
#lappend optList "-Dderby.drda.startNetworkServer=true"
lappend optList "-Dderby.drda.timeslice=2000"
lappend optList "-Dderby.drda.traceAll=true"
lappend optList "-Dderby.drda.traceDirectory=$traceDir"
lappend optList "-Dderby.system.home=$derbyDir"
#lappend optList "-Dderby.stream.error.logSeverityLevel=40000"
lappend optList "-Dderby.locks.monitor=true"
#lappend optList "-Dderby.locks.deadlockTrace=true"

puts "\n java command line options list is:\n"

foreach x $optList {
    puts [ format "%-5s %-50s" " " $x ] 
}

set tclblend_init $optList  

#call java package 

package require java

# build tcl classpath

set null [ java::null ]

if { [ catch { startServer $traceFileId  } r ] == 0 } {

    set NetworkServerControl $r

    if { [ catch { serverInfo $traceFileId $NetworkServerControl } r ] == 0 } {

       flush $traceFileId	
       set subject       "$computerName: Start Cloudscape Server"
       set emailAddress  youremail@you.com
       sendSimpleMessage $emailAddress $subject $body

       if { [ catch { pingServer $traceFileId $NetworkServerControl } r ] == 0 } {

	   set ok true

       }

    } 

} else {

    return

}


set computerTime [clock format [clock seconds] -format "%d-%m-%Y %H.%M.%S"]
puts $traceFileId "\n********* Cloudscape Server stopped at: $computerTime *********\n"
close $traceFileId

set subject       "$computerName: Cloudscape server Stopped."
set emailAddress  yourmail@yourmail.com
sendSimpleMessage $emailAddress $subject $body

This script uses the Cloudscape Java API to;

  1. Start the Cloudscape network server.

  2. Ping the network server to ensure it has started.

  3. Get the server system infomation.

  4. Get the server runtime information.

  5. Runs in the background and pings the server continously to ensure it has started. Generates an email alert if the server fails.

It can be run as a service under Windows or a daemon on Unix. Requires Tclblend.

Tclblend: http://tcljava.sourceforge.net/docs/website/index.html. Tclblend Wwindows Build Instructions: http://wiki.tcl.tk/9993

Created by Patrick Finnegan on Wed, 7 Dec 2005 (MIT)
Tcl recipes (162)
Patrick Finnegan's recipes (56)

Required Modules

  • (none specified)

Other Information and Tasks