Class: ToasterAppService

Inherits:
XMLRPC::Server
  • Object
show all
Defined in:
lib/toaster/toaster_app_service.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ ToasterAppService

Returns a new instance of ToasterAppService.



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/toaster/toaster_app_service.rb', line 80

def initialize(*args)
  super(*args)
  @app = Toaster::ToasterApp.new
  @methods = ["chefsolo", "clean", "download", "exec", "lxc", 
    "proto", "runchef", "runtest", "runtests", "testinit", "time"
  ]
  @methods.each do |method|
    add_handler(method) { |*args|
      exception = nil
      out = capture_stdout do
        begin
          @app.send(method, *args)
        rescue Object => ex
          exception = ex
        end
      end
      if exception
        puts "#{exception} - #{exception.backtrace.join("\n")}"
        puts "stdout: #{out}"
        puts "-----"
        raise exception
      end
      out
    }
  end
end

Class Method Details

.service_started?Boolean

Returns:

  • (Boolean)


110
111
112
113
# File 'lib/toaster/toaster_app_service.rb', line 110

def self.service_started?()
  output = `ps aux | grep -v "ps aux" | grep ruby | grep toaster_app_service`
  return output.strip != ""
end

.start_serviceObject



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/toaster/toaster_app_service.rb', line 115

def self.start_service()
  if !service_started?()
    dir = File.expand_path(File.dirname(__FILE__))
    Util.write("/tmp/toaster.service.loop.sh",
      "#!/bin/bash\n " +
      "cd #{dir}\n " +
      "while [ 1 ]; do\n " +
      "ruby toaster_app_service.rb do_start_service -v\n " +
      "done",
    true)
    `chmod +x /tmp/toaster.service.loop.sh`
    cmd = "cd #{dir} && screen -m -d bash /tmp/toaster.service.loop.sh"
    puts "INFO: Starting test service in the background (using screen), using port #{$service_port}."
    `#{cmd}`
  else
    puts "INFO: Another test service instance is already running on this host."
  end
end

Instance Method Details

#startObject



106
107
108
# File 'lib/toaster/toaster_app_service.rb', line 106

def start()
  serve()
end