From: Martyn Taylor mtaylor@redhat.com
--- src/app/util/condormatic.rb | 24 +++++++++++ src/condor_refreshd/condor_refreshd | 78 +++++++++++------------------------ 2 files changed, 48 insertions(+), 54 deletions(-)
diff --git a/src/app/util/condormatic.rb b/src/app/util/condormatic.rb index 572f413..4aa1139 100644 --- a/src/app/util/condormatic.rb +++ b/src/app/util/condormatic.rb @@ -292,6 +292,30 @@ def condormatic_classads_sync Rails.logger.info "done" end
+def condormatic_queue_classad_sync(timeout) + begin + pipe = IO.popen("condor_submit 2>&1", "w+") + pipe.puts "Executable = /usr/share/aeolus-conductor/condor_refreshd/condor_refreshd\n" + Rails.logger.info "Executable = /usr/share/aeolus-conductor/condor_refreshd/condor_refreshd\n" + pipe.puts "Requirements = true\n" + Rails.logger.info "Requirements = true\n" + pipe.puts "environment = RAILS_ENV=production\n" + Rails.logger.info "environment = RAILS_ENV=production\n" + pipe.puts "Queue\n" + Rails.logger.info "Queue\n" + pipe.close_write + out = pipe.read + pipe.close + + @logger.error "$? (return value?) is #{$?}" + raise ("Error calling condor_submit: #{out}") if $? != 0 + + rescue Exception => ex + @logger.error ex.message + @logger.error ex.backtrace + end +end + def kick_condor begin socket = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0) diff --git a/src/condor_refreshd/condor_refreshd b/src/condor_refreshd/condor_refreshd index 273902f..2bc5803 100755 --- a/src/condor_refreshd/condor_refreshd +++ b/src/condor_refreshd/condor_refreshd @@ -26,33 +26,23 @@ require 'optparse' require 'socket' require 'dutils'
-port = 7890 help = false -daemon = true -refreshd_log_dir = "/var/log/aeolus-conductor" -refreshd_pid_dir = "/var/run/aeolus-conductor" -timeout = 15 +delay = 0 +refreshd_log_dir = "/var/log/aeolus-conductor/" +refresh_log = "condor_refreshd.log"
optparse = OptionParser.new do |opts| - opts.banner = <<BANNER Usage: condor_refreshd [options]
Options: BANNER - opts.on( '-f', '--pid-file PATH', "Use PATH to the condor_refreshd pid directory (defaults to #{refreshd_pid_dir})") do |newpath| - refreshd_pid_dir = newpath - end opts.on( '-h', '--help', '') { help = true } opts.on( '-l', '--log PATH', "Use PATH to the condor_refreshd log directory (defaults to #{refreshd_log_dir}). Use '-' for stdout") do |newpath| refreshd_log_dir = newpath end - opts.on( '-n', '--nodaemon', 'Do not daemonize (useful in combination with -l for debugging)') { daemon = false } - opts.on( '-p', '--port PORT', 'Use PORT (default: 7890)') do |newport| - port = newport - end - opts.on( '-t', '--timeout TIMEOUT', 'Automatically refresh classads after TIMEOUT minutes') do |newtime| - timeout = newtime + opts.on( '-d', '--delay SECONDS', 'do not run for SECONDS before refreshing classads.') do |newdelay| + delay = newdelay end end
@@ -76,49 +66,29 @@ if refreshd_log_dir == '-' else REFRESHD_LOG_FILE = "#{refreshd_log_dir}/condor_refreshd.log" end -logger = Logger.new(REFRESHD_LOG_FILE) -logger.level = Logger::DEBUG
-logger.info "Starting condor_refreshd..." -socket = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0) -in_addr = Socket.pack_sockaddr_in(port, '127.0.0.1') -socket.bind(in_addr) +logger = Logger.new(REFRESHD_LOG_FILE)
-# daemonize -if daemon - # note that this requires 'active_support', which we get for free from dutils - Process.daemon -end +logger.level = Logger::DEBUG
begin - REFRESHD_PID_FILE = "#{refreshd_pid_dir}/condor_refreshd.pid" - FileUtils.mkdir_p File.dirname(REFRESHD_PID_FILE) - open(REFRESHD_PID_FILE, "w") {|f| f.write(Process.pid) } - File.chmod(0644, REFRESHD_PID_FILE) - - while true - begin - condormatic_classads_sync - results = select([socket], nil, nil, timeout * 60) - - # if results was nil, we timed out waiting, and we need to do a sync - # but not read from the socket - if not results.nil? and results[0][0] == socket - socket.recvfrom(1024) - logger.info "Doing classad sync after getting data from the socket" - else - logger.info "Doing classad sync after timeout" - end - rescue => e - logger.error "#{e.backtrace.shift}: #{e.message}" - e.backtrace.each do |step| - logger.error "\tfrom #{step}" - end + # Ideally get the start time here. + #sleep(delay) + sleep(20) + begin + logger.info("----------------------------------------------") + logger.info(Time.now.to_s + ": " + "Executing ClassAd Sync") + condormatic_classads_sync + rescue => e + logger.error "#{e.backtrace.shift}: #{e.message}" + e.backtrace.each do |step| + logger.error "\tfrom #{step}" end end -rescue => e - logger.error "#{e.backtrace.shift}: #{e.message}" - e.backtrace.each do |step| - logger.error "\tfrom #{step}" - end + # Get the end time, calculate elapsed time, subtract it from 55 (5 sec buffer), and use that as the arg to the timeout. + condormatic_queue_classad_sync(30) + + logger.info(Time.now.to_s + ": Refresh Completed") + logger.info("----------------------------------------------") + exit(0) end
aeolus-devel@lists.fedorahosted.org