# File lib/cloudmasterd/syncer.rb, line 148
  def run
    # Wait until the DB is there to establish the connection
    until File.exists?("/var/lib/cloudmaster.db") do
      sleep 10
    end

    ActiveRecord::Base.logger = Logger.new('/var/log/cloudmasterd-sync.log', 5, 1024000)
    ActiveRecord::Base.colorize_logging = false

    # Setup the database connection
    ActiveRecord::Base.establish_connection(
        :adapter => "sqlite3",
        :dbfile  => "/var/lib/cloudmaster.db"
    )

    # Constantly keep the database in sync
    while true do
      begin
        Syncer::lock { sync_memory }
        Syncer::lock { sync_state }
        Syncer::lock { sync_owners }
      rescue Exception => e
        puts "ERROR: An error occured during syncing - #{e.to_s}"
      end

      sleep 5
    end
  end