Class: QEMU::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/qemu/daemon.rb

Constant Summary collapse

@@log_directory =
"log"
@@run_directory =
"tmp"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Daemon

Returns a new instance of Daemon.



18
19
20
21
# File 'lib/qemu/daemon.rb', line 18

def initialize(attributes = {})
  attributes = attributes.merge(:name => "qemu", :run_dir => self.class.run_directory, :log_dir => self.class.log_directory)
  attributes.each { |k,v| send "#{k}=", v }
end

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



16
17
18
# File 'lib/qemu/daemon.rb', line 16

def arguments
  @arguments
end

#commandObject

Returns the value of attribute command.



16
17
18
# File 'lib/qemu/daemon.rb', line 16

def command
  @command
end

#envObject

Returns the value of attribute env.



16
17
18
# File 'lib/qemu/daemon.rb', line 16

def env
  @env
end

#log_dirObject

Returns the value of attribute log_dir.



16
17
18
# File 'lib/qemu/daemon.rb', line 16

def log_dir
  @log_dir
end

#nameObject

Returns the value of attribute name.



16
17
18
# File 'lib/qemu/daemon.rb', line 16

def name
  @name
end

#run_dirObject

Returns the value of attribute run_dir.



16
17
18
# File 'lib/qemu/daemon.rb', line 16

def run_dir
  @run_dir
end

Class Method Details

.log_directoryObject



7
8
9
# File 'lib/qemu/daemon.rb', line 7

def self.log_directory
  @@log_directory
end

.run_directoryObject



12
13
14
# File 'lib/qemu/daemon.rb', line 12

def self.run_directory
  @@run_directory
end

Instance Method Details

#arguments_to(command) ⇒ Object



35
36
37
# File 'lib/qemu/daemon.rb', line 35

def arguments_to(command)
  [ command.to_s, "--", *arguments ]
end

#optionsObject



31
32
33
# File 'lib/qemu/daemon.rb', line 31

def options
  { :app_name => name, :dir_mode => :normal, :dir => run_dir, :mode => :exec, :log_dir => log_dir, :log_output => true }
end

#options_to(command) ⇒ Object



39
40
41
# File 'lib/qemu/daemon.rb', line 39

def options_to(command)
  options.merge :ARGV => arguments_to(command)
end

#startObject



43
44
45
46
47
48
# File 'lib/qemu/daemon.rb', line 43

def start
  fork do
    env.each { |k,v| ENV[k] = v } if env
    Daemons.run command, options_to(:start)
  end
end

#stopObject



50
51
52
# File 'lib/qemu/daemon.rb', line 50

def stop
  Daemons.run command, options_to(:stop)
end