This should make debugging a lot easier.

Signed-off-by: Chris Lalancette <[email protected]>
---
 src/condor_refreshd/condor_refreshd             |   26 +++---
 src/dbomatic/dbomatic                           |  115 ++++++++++++-----------
 src/image_builder_service/image_builder_service |   37 ++++----
 3 files changed, 90 insertions(+), 88 deletions(-)

diff --git a/src/condor_refreshd/condor_refreshd 
b/src/condor_refreshd/condor_refreshd
index 1210e1b..74dbb82 100755
--- a/src/condor_refreshd/condor_refreshd
+++ b/src/condor_refreshd/condor_refreshd
@@ -91,22 +91,22 @@ begin
   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
+      packet = socket.recvfrom(1024)
+      logger.info "Doing 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
+  end
 rescue => e
   logger.error "#{e.backtrace.shift}: #{e.message}"
   e.backtrace.each do |step|
     logger.error "\tfrom #{step}"
   end
 end
-
-while true
-  begin
-    packet = socket.recvfrom(1024)
-    logger.info "Doing 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
-end
diff --git a/src/dbomatic/dbomatic b/src/dbomatic/dbomatic
index 2a5211f..9e41ea1 100755
--- a/src/dbomatic/dbomatic
+++ b/src/dbomatic/dbomatic
@@ -88,18 +88,6 @@ if daemon
   Process.daemon
 end
 
-begin
-  DBOMATIC_PID_FILE = "#{dbomatic_pid_dir}/dbomatic.pid"
-  FileUtils.mkdir_p File.dirname(DBOMATIC_PID_FILE)
-  open(DBOMATIC_PID_FILE, "w") {|f| f.write(Process.pid) }
-  File.chmod(0644, DBOMATIC_PID_FILE)
-rescue => e
-  logger.error "#{e.backtrace.shift}: #{e.message}"
-  e.backtrace.each do |step|
-    logger.error "\tfrom #{step}"
-  end
-end
-
 # Handle the event log's xml
 class CondorEventLog < Nokogiri::XML::SAX::Document
   attr_accessor :tag, :event_type, :event_cmd, :event_time, :trigger_type, 
:grid_resource, :execute_host, :hold_reason
@@ -230,12 +218,6 @@ class CondorEventLog < Nokogiri::XML::SAX::Document
 
   end
 end
-parser = Nokogiri::XML::SAX::PushParser.new(CondorEventLog.new(logger))
-
-# XXX hack, condor event log doesn't seem to have a top level element
-# enclosing everything else in the doc (as standards conforming xml must).
-# Create one for parsing purposes.
-parser << "<events>"
 
 def parse_log_file(log_file, parser)
   while s = log_file.gets
@@ -244,49 +226,68 @@ def parse_log_file(log_file, parser)
   File.open(EVENT_LOG_POS_FILE, 'w') { |f| f.write log_file.pos.to_s }
 end
 
-# sync up the states that condor knows about with what is in the aggregator
-# database.  Note that there is still a chance that the state is changing
-# internally to condor while we are syncing the states here.  However, condor
-# will emit an event in that case, so it will be taken care of by the
-# EventLog parsing later on.
-condormatic_instances_sync_states
-
-notifier = INotify::Notifier.new
-log_file = nil
-
-if File.exists? CONDOR_EVENT_LOG_FILE
-  log_file = File.open(CONDOR_EVENT_LOG_FILE)
-
-  # persistantly store log position in filesystem
-  # incase of dbomatic restarts
-  if File.exists?(EVENT_LOG_POS_FILE)
-    File.open(EVENT_LOG_POS_FILE, 'r') { |f| log_file.pos = f.read.to_i }
-    # FIXME: we really need to parse from here to the end of the file.
-    # otherwise we won't get new events until something else causes the
-    # inotify watch to fire.
-  end
+begin
+  DBOMATIC_PID_FILE = "#{dbomatic_pid_dir}/dbomatic.pid"
+  FileUtils.mkdir_p File.dirname(DBOMATIC_PID_FILE)
+  open(DBOMATIC_PID_FILE, "w") {|f| f.write(Process.pid) }
+  File.chmod(0644, DBOMATIC_PID_FILE)
 
-  # Setup inotify watch for condor event log
-  notifier.watch(CONDOR_EVENT_LOG_FILE, :modify){ |event|
-    parse_log_file log_file, parser
-  }
+  parser = Nokogiri::XML::SAX::PushParser.new(CondorEventLog.new(logger))
+
+  # XXX hack, condor event log doesn't seem to have a top level element
+  # enclosing everything else in the doc (as standards conforming xml must).
+  # Create one for parsing purposes.
+  parser << "<events>"
+
+  # sync up the states that condor knows about with what is in the aggregator
+  # database.  Note that there is still a chance that the state is changing
+  # internally to condor while we are syncing the states here.  However, condor
+  # will emit an event in that case, so it will be taken care of by the
+  # EventLog parsing later on.
+  condormatic_instances_sync_states
+
+  notifier = INotify::Notifier.new
+  log_file = nil
+
+  if File.exists? CONDOR_EVENT_LOG_FILE
+    log_file = File.open(CONDOR_EVENT_LOG_FILE)
+
+    # persistantly store log position in filesystem
+    # incase of dbomatic restarts
+    if File.exists?(EVENT_LOG_POS_FILE)
+      File.open(EVENT_LOG_POS_FILE, 'r') { |f| log_file.pos = f.read.to_i }
+      # FIXME: we really need to parse from here to the end of the file.
+      # otherwise we won't get new events until something else causes the
+      # inotify watch to fire.
+    end
 
-# if log file doesn't exist wait until it does
-else
-  notifier.watch(condor_event_log_dir, :create){ |event|
-    if event.name == "EventLog"
-      log_file = File.open(CONDOR_EVENT_LOG_FILE)
+    # Setup inotify watch for condor event log
+    notifier.watch(CONDOR_EVENT_LOG_FILE, :modify){ |event|
       parse_log_file log_file, parser
+    }
 
-      # Setup inotify watch for condor event log
-      notifier.watch(CONDOR_EVENT_LOG_FILE, :modify){ |event|
+    # if log file doesn't exist wait until it does
+  else
+    notifier.watch(condor_event_log_dir, :create){ |event|
+      if event.name == "EventLog"
+        log_file = File.open(CONDOR_EVENT_LOG_FILE)
         parse_log_file log_file, parser
-      }
-    end
-  }
-end
 
-notifier.run
+        # Setup inotify watch for condor event log
+        notifier.watch(CONDOR_EVENT_LOG_FILE, :modify){ |event|
+          parse_log_file log_file, parser
+        }
+      end
+    }
+  end
+
+  notifier.run
 
-parser << "</events>"
-parser.finish
+  parser << "</events>"
+  parser.finish
+rescue => e
+  logger.error "#{e.backtrace.shift}: #{e.message}"
+  e.backtrace.each do |step|
+    logger.error "\tfrom #{step}"
+  end
+end
diff --git a/src/image_builder_service/image_builder_service 
b/src/image_builder_service/image_builder_service
index a1224d3..a74be9f 100755
--- a/src/image_builder_service/image_builder_service
+++ b/src/image_builder_service/image_builder_service
@@ -17,11 +17,12 @@
 # MA  02110-1301, USA.  A copy of the GNU General Public License is
 # also available at http://www.gnu.org/copyleft/gpl.html.
 
-# This service is a very early attempt at integration with the Image Builder, 
and
-# should in no way be considered either stable or production-ready.
-# In order to use this service you must have the gem installed for 
image_builder_console.
-# This can be checked out from the image_builder repo (link on 
deltacloud.org), and built
-# locally.  Then keep a terminal open to run this in and run with:
+# This service is a very early attempt at integration with the Image Builder,
+# and should in no way be considered either stable or production-ready.
+# In order to use this service you must have the gem installed for
+# image_builder_console.
+# This can be checked out from the image_builder repo (link on deltacloud.org),
+# and built locally.  Then keep a terminal open to run this in and run with:
 #   ruby image_builder_service.rb
 
 $: << File.join(File.dirname(__FILE__), "../dutils")
@@ -86,18 +87,6 @@ if daemon
   Process.daemon
 end
 
-begin
-  BUILDER_PID_FILE = "#{builder_pid_dir}/image_builder_service.pid"
-  FileUtils.mkdir_p File.dirname(BUILDER_PID_FILE)
-  open(BUILDER_PID_FILE, "w") {|f| f.write(Process.pid) }
-  File.chmod(0644, BUILDER_PID_FILE)
-rescue => e
-  logger.error "#{e.backtrace.shift}: #{e.message}"
-  e.backtrace.each do |step|
-    logger.error "\tfrom #{step}"
-  end
-end
-
 #TODO: Make this whole thing less fragile
 class ImageBuilderService
   def initialize(logger, timeout)
@@ -227,4 +216,16 @@ class ImageBuilderService
   end
 end
 
-ImageBuilderService.new(logger, timeout)
+begin
+  BUILDER_PID_FILE = "#{builder_pid_dir}/image_builder_service.pid"
+  FileUtils.mkdir_p File.dirname(BUILDER_PID_FILE)
+  open(BUILDER_PID_FILE, "w") {|f| f.write(Process.pid) }
+  File.chmod(0644, BUILDER_PID_FILE)
+
+  ImageBuilderService.new(logger, timeout)
+rescue => e
+  logger.error "#{e.backtrace.shift}: #{e.message}"
+  e.backtrace.each do |step|
+    logger.error "\tfrom #{step}"
+  end
+end
-- 
1.7.2.3

_______________________________________________
deltacloud-devel mailing list
[email protected]
https://fedorahosted.org/mailman/listinfo/deltacloud-devel

Reply via email to