Class: Waw::Commands::StartCommand

Inherits:
Command show all
Defined in:
lib/waw/commands/start_command.rb

Instance Attribute Summary

Attributes inherited from Command

#trace, #verbosity

Instance Method Summary collapse

Methods inherited from Command

#add_options, #exit, #info, #initialize, #options, #run, #shell_exec, #verbose

Constructor Details

This class inherits a constructor from Waw::Commands::Command

Instance Method Details

#__run(requester_file, arguments) ⇒ Object

Runs the sub-class defined command



51
52
53
54
55
# File 'lib/waw/commands/start_command.rb', line 51

def __run(requester_file, arguments)
  waw_start(requester_file)[0].join
rescue Interrupt => ex
  info "waw-start stopping now... ciao!"
end


7
8
9
10
11
# File 'lib/waw/commands/start_command.rb', line 7

def banner
  <<-EOF
    Usage: [waw-]start [options]
  EOF
end

#check_command_policyObject

Start command is always safe



14
15
16
# File 'lib/waw/commands/start_command.rb', line 14

def check_command_policy
  true
end

#waw_start(requester_file, verbose = true) ⇒ Object

Executes the waw-start command and returns the running thread



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/waw/commands/start_command.rb', line 19

def waw_start(requester_file, verbose = true)
  waw_kernel = Waw.autoload(requester_file)
  t = Thread.new(waw_kernel) do |app|
    begin
      server = Rack::Handler::Mongrel
    rescue LoadError => e
      server = Rack::Handler::WEBrick
    end
    options = {:Port => app.config.web_port, :Host => "0.0.0.0", :AccessLog => []}
    server.run app, options
  end
  try, ok = 0, false
  begin
    info "Attempting to reach the web server..." if verbose
    ::Net::HTTP.get(URI.parse(waw_kernel.config.web_base))
    ok = true
  rescue Errno::ECONNREFUSED => ex
    sleep 0.1
  end until (ok or (try += 1)>10)
  if ok
    if verbose
      info "Your web application has been started successfully"
      info "Have a look at #{waw_kernel.config.web_base}"
      info "Enjoy waw!"
    end
    [t, waw_kernel]
  else
    raise Waw::Error, "Unable to reach the web server after having been started"
  end
end