Ian Main
2009-Jul-07 19:22 UTC
[Ovirt-devel] [PATCH] Set up ovirt-agent so it starts as a daemon
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
Ian Main
2009-Jul-07 20:29 UTC
[Ovirt-devel] [PATCH] Set up ovirt-agent so it starts as a daemon
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. This update adds the conf/ovirt-agent start/stop script. Signed-off-by: Ian Main <imain at redhat.com> --- conf/ovirt-agent | 52 +++++++++++++++++++++++ installer/modules/ovirt/manifests/ovirt.pp | 6 +++ ovirt-server.spec.in | 5 ++ src/ovirt-agent/ovirt-agent.rb | 63 +++++++++++++++++++++------- 4 files changed, 110 insertions(+), 16 deletions(-) create mode 100755 conf/ovirt-agent diff --git a/conf/ovirt-agent b/conf/ovirt-agent new file mode 100755 index 0000000..1067a24 --- /dev/null +++ b/conf/ovirt-agent @@ -0,0 +1,52 @@ +#!/bin/bash +# +# +# ovirt-agent startup script for ovirt-agent +# +# chkconfig: - 97 03 +# description: ovirt-agent provides the QMF API for ovirt VM manager. +# + +[ -r /etc/sysconfig/ovirt-rails ] && . /etc/sysconfig/ovirt-rails + +export RAILS_ENV="${RAILS_ENV:-production}" + +DAEMON=/usr/share/ovirt-server/ovirt-agent/ovirt-agent.rb + +. /etc/init.d/functions + +start() { + echo -n "Starting ovirt-agent: " + daemon $DAEMON + RETVAL=$? + echo +} + +stop() { + echo -n "Shutting down ovirt-agent: " + killproc ovirt-agent.rb + RETVAL=$? + echo +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + status) + status $DAEMON + RETVAL=$? + ;; + *) + echo "Usage: ovirt-agent {start|stop|restart|status}" + exit 1 + ;; +esac +exit $RETVAL 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
Reasonably Related Threads
- [PATCH server] added ovirt vnc proxy server, to proxy vnc request to managed vms
- [PATCH server] oVirt server single network installer
- [PATCH server] Starting of new ovirt QMF API.
- [PATCH server] Added support for remote logging with rsyslog-gssapi to server.
- [PATCH server] added ovirt-wait4service and invokation in installer to wait for psql/ldap