Index: openacs-4/etc/keepalive/keepalive.sh =================================================================== RCS file: /usr/local/cvsroot/openacs-4/etc/keepalive/keepalive.sh,v diff -u -r1.3 -r1.4 --- openacs-4/etc/keepalive/keepalive.sh 29 Apr 2004 08:29:28 -0000 1.3 +++ openacs-4/etc/keepalive/keepalive.sh 12 Jun 2004 14:26:23 -0000 1.4 @@ -16,17 +16,6 @@ source $script_dir/keepalive-config.tcl -global restart_time_file -set restart_time_file $script_dir/last-restart-time - -proc read_file { file_path } { - set file_id [open $file_path r] - set file_contents [read $file_id] - close $file_id - - return $file_contents -} - proc server_responds_p { server_url } { set script_dir [file dirname [info script]] @@ -35,71 +24,34 @@ file delete -force $wget_file } - if { [catch {exec wget --timeout 6 --output-document $wget_file --tries=3 ${server_url}/SYSTEM/dbtest} errmsg] } { - #puts "wget threw error $errmsg" - } + catch {exec /usr/bin/wget -O $wget_file --tries=5 ${server_url}/SYSTEM/dbtest} if { [file exists $wget_file] } { - set wget_file_contents [read_file $wget_file] - - if { [regexp -nocase {^\s*success\s*$} $wget_file_contents] } { - set responds_p 1 - } else { - set responds_p 0 - } - } else { - set responds_p 0 - } + set wget_file_id [open $wget_file r] + set wget_file_contents [read $wget_file_id] + close $wget_file_id + if { [regexp {success} $wget_file_contents] } { + set responds_p 1 + } else { + set responds_p 0 + } + } else { + set responds_p 0 + } - return $responds_p + return $responds_p } -proc waiting_for_restart_p { seconds_between_restarts } { - - global restart_time_file - - if { [file exists $restart_time_file] } { - set last_restart_time [string trim [read_file $restart_time_file]] - set current_time [clock seconds] - set time_since_restart [expr $current_time - $last_restart_time] - - if { [expr $time_since_restart > $seconds_between_restarts] } { - return 0 - } else { - return 1 - } - } else { - # This is the first restart - return 0 - } -} - -proc record_current_time { file } { - set fd [open $file w] - puts $fd [clock seconds] - close $fd -} - foreach {server_url restart_command} $servers_to_monitor { - #puts -nonewline "Checking server at $server_url - " + puts -nonewline "Checking server at $server_url - " if { [server_responds_p $server_url] } { - #puts "server responds." + puts "server responds." } else { - #puts -nonewline "no response. " - - # Only restart server if we didn't recently restart it - if { ![waiting_for_restart_p $seconds_between_restarts] } { - puts "Executing command \"$restart_command\" to restart server at $server_url." - if { [catch {eval exec $restart_command} errmsg] } { - puts "Error executing restart_command: $errmsg" - } - - # Record new restart time - global restart_time_file - record_current_time $restart_time_file - } else { - puts "Server at $server_url has been restarted within last $seconds_between_restarts seconds so not restarting yet" - } + puts -nonewline "no response. " + puts "Executing command \"$restart_command\" to restart server." + if { [catch {eval exec $restart_command} errmsg] } { + puts "Error executing restart_command: $errmsg" + } } }