[Ovirt-devel] [PATCH] Set up ovirt-agent so it starts as a daemon

Ian Main imain at redhat.com
Tue Jul 7 19:22:55 UTC 2009


This sets up ovirt-agent to start as a daemon along with dbomatic,
taskomatic etc.  While this is not ready for prime time I think it
should be ok as you still require a valid, authenticated, connection
to qpidd to access it.

Signed-off-by: Ian Main <imain at redhat.com>
---
 installer/modules/ovirt/manifests/ovirt.pp |    6 +++
 ovirt-server.spec.in                       |    5 ++
 src/ovirt-agent/ovirt-agent.rb             |   63 +++++++++++++++++++++-------
 3 files changed, 58 insertions(+), 16 deletions(-)

diff --git a/installer/modules/ovirt/manifests/ovirt.pp b/installer/modules/ovirt/manifests/ovirt.pp
index d953ebe..636cd6e 100644
--- a/installer/modules/ovirt/manifests/ovirt.pp
+++ b/installer/modules/ovirt/manifests/ovirt.pp
@@ -172,6 +172,12 @@ class ovirt::setup {
                 ensure => running
         }
 
+        service {"ovirt-agent" :
+                enable => true,
+		require => [Package[ovirt-server],Single_Exec[db_migrate]],
+                ensure => running
+        }
+
         service {"qpidd" :
                 enable => true,
                 ensure => running,
diff --git a/ovirt-server.spec.in b/ovirt-server.spec.in
index ad9dd2c..a315381 100644
--- a/ovirt-server.spec.in
+++ b/ovirt-server.spec.in
@@ -103,6 +103,7 @@ touch %{buildroot}%{_localstatedir}/log/%{name}/db-omatic.log
 
 %{__install} -Dp -m0755 %{pbuild}/conf/ovirt-host-browser %{buildroot}%{_initrddir}
 %{__install} -Dp -m0755 %{pbuild}/conf/ovirt-db-omatic %{buildroot}%{_initrddir}
+%{__install} -Dp -m0755 %{pbuild}/conf/ovirt-agent %{buildroot}%{_initrddir}
 %{__install} -Dp -m0755 %{pbuild}/conf/ovirt-host-collect %{buildroot}%{_initrddir}
 %{__install} -Dp -m0755 %{pbuild}/conf/ovirt-mongrel-rails %{buildroot}%{_initrddir}
 %{__install} -Dp -m0755 %{pbuild}/conf/ovirt-mongrel-rails.sysconf %{buildroot}%{_sysconfdir}/sysconfig/ovirt-mongrel-rails
@@ -183,6 +184,7 @@ fi
 # check this by seeing if each daemon is already installed
 %daemon_chkconfig_post -d ovirt-host-browser
 %daemon_chkconfig_post -d ovirt-db-omatic
+%daemon_chkconfig_post -d ovirt-agent
 %daemon_chkconfig_post -d ovirt-host-collect
 %daemon_chkconfig_post -d ovirt-mongrel-rails
 %daemon_chkconfig_post -d ovirt-taskomatic
@@ -192,12 +194,14 @@ fi
 if [ "$1" = 0 ] ; then
   /sbin/service ovirt-host-browser stop > /dev/null 2>&1
   /sbin/service ovirt-db-omatic stop > /dev/null 2>&1
+  /sbin/service ovirt-agent stop > /dev/null 2>&1
   /sbin/service ovirt-host-collect stop > /dev/null 2>&1
   /sbin/service ovirt-mongrel-rails stop > /dev/null 2>&1
   /sbin/service ovirt-taskomatic stop > /dev/null 2>&1
   /sbin/service ovirt-vnc-proxy stop > /dev/null 2>&1
   /sbin/chkconfig --del ovirt-host-browser
   /sbin/chkconfig --del ovirt-db-omatic
+  /sbin/chkconfig --del ovirt-agent
   /sbin/chkconfig --del ovirt-host-collect
   /sbin/chkconfig --del ovirt-mongrel-rails
   /sbin/chkconfig --del ovirt-taskomatic
@@ -212,6 +216,7 @@ fi
 %{_bindir}/ovirt-vm2node
 %{_initrddir}/ovirt-host-browser
 %{_initrddir}/ovirt-db-omatic
+%{_initrddir}/ovirt-agent
 %{_initrddir}/ovirt-host-collect
 %{_initrddir}/ovirt-mongrel-rails
 %{_initrddir}/ovirt-taskomatic
diff --git a/src/ovirt-agent/ovirt-agent.rb b/src/ovirt-agent/ovirt-agent.rb
index ae55e3f..62834b0 100755
--- a/src/ovirt-agent/ovirt-agent.rb
+++ b/src/ovirt-agent/ovirt-agent.rb
@@ -23,6 +23,12 @@ require 'ovirt/controllers/task_controller'
 
 include Daemonize
 
+class Logger
+  def format_message(severity, timestamp, progname, msg)
+    "#{severity} #{timestamp} (#{$$}) #{msg}\n"
+  end
+end
+
 # Monkey patch
 class Qmf::SchemaObjectClass
   attr_reader :id
@@ -80,16 +86,47 @@ class OvirtAgent < Qmf::AgentHandler
 
   include Ovirt::SchemaParser
 
-  def initialize(host)
+  $logfile = '/var/log/ovirt-server/ovirt-agent.log'
 
-    ensure_credentials
+  def initialize()
 
-    # FIXME: Use RAILS_DEFAULT_LOGGER
-    @logger = Logger.new(STDERR)
-    @logger.level = Logger::DEBUG
+    ensure_credentials
 
     server, port = nil
     sleepy = 5
+
+    do_daemon = true
+
+    opts = OptionParser.new do |opts|
+      opts.on("-h", "--help", "Print help message") do
+        puts opts
+        exit
+      end
+      opts.on("-n", "--nodaemon", "Run interactively (useful for debugging)") do |n|
+        do_daemon = false
+      end
+    end
+    begin
+      opts.parse!(ARGV)
+    rescue OptionParser::InvalidOption
+      puts opts
+      exit
+    end
+
+    if do_daemon
+      # This gets around a problem with paths for the database stuff.
+      # Normally daemonize would chdir to / but the paths for the database
+      # stuff are relative so it breaks it.. It's either this or rearrange
+      # things so the db stuff is included after daemonizing.
+      pwd = Dir.pwd
+      daemonize
+      Dir.chdir(pwd)
+      @logger = Logger.new($logfile)
+    else
+      @logger = Logger.new(STDERR)
+    end
+    @logger.level = Logger::DEBUG
+
     while true do
       server, port = get_srv('qpidd', 'tcp')
       break if server
@@ -99,12 +136,12 @@ class OvirtAgent < Qmf::AgentHandler
     end
 
     @settings = Qmf::ConnectionSettings.new
-    #@settings.server = server
+    @settings.host = server
+    # FIXME: Bug in swig!
     #@settings.port = port
-    #@settings.mechanism = 'GSSAPI'
+    @settings.mechanism = 'GSSAPI'
 
-    @settings.host = host
-    @logger.info "Connect to broker on #{@settings.host}"
+    @logger.info "Connecting to broker on #{@settings.host}.."
 
     @connection = Qmf::Connection.new(@settings)
     @agent = Qmf::Agent.new(self)
@@ -243,11 +280,5 @@ class OvirtAgent < Qmf::AgentHandler
   end
 end
 
-if ARGV.size == 1
-  broker = ARGV[0]
-else
-  broker = "localhost"
-end
-ovirt_agent = OvirtAgent.new(broker)
-
+ovirt_agent = OvirtAgent.new
 ovirt_agent.mainloop
-- 
1.6.0.6




More information about the ovirt-devel mailing list