Class: ConfigTool

Inherits:
Object
  • Object
show all
Includes:
Mongrel::Command::Base
Defined in:
lib/mongrel_config/init.rb

Instance Method Summary collapse

Instance Method Details

#configureObject



8
9
10
11
12
13
14
15
16
# File 'lib/mongrel_config/init.rb', line 8

def configure 
  options [ 
           ['-c', '--chdir PATH', "Change to dir before starting (will be expanded)", :@cwd, Dir.pwd],
           ['-P', '--pid FILE', "Where to write the PID", :@pid_file, "log/mongrel.pid"],
           ['-h', '--host ADDR', "Host to bind to for server", :@host, "0.0.0.0"],
           ['-p', '--port NUMBER', "Port to bind to", :@port, "3001"],
           ['-u', '--uri URI', "Where to put your config tool", :@uri, "/config"]
  ]
end

#runObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/mongrel_config/init.rb', line 31

def run
  # must require this here since rails and camping don't like eachother
  require 'mongrel_config/app'

  resources = GemPlugin::Manager.instance.resource "mongrel_config", "/"
  $PID_FILE = @pid_file

  $server = Mongrel::Camping::start(@host,@port,@uri,Configure)

  puts "** Configure is running at http://#{@host}:#{@port}#{@uri}"
  if RUBY_PLATFORM !~ /mswin/
    trap("INT") { 
      $server.stop 
    }
    puts "Use CTRL-C to quit."
  else
    puts "Use CTRL-Pause/Break to quit."
  end

  # add our log directory
  $server.register("/log", Mongrel::DirHandler.new("log"))
  $server.register("/config/resources", Mongrel::DirHandler.new(resources))

  $server.acceptor.join
end

#validateObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mongrel_config/init.rb', line 18

def validate
  valid?(@uri, "Must give a uri")
  valid?(@port && @port.to_i > 0, "Must give a valid port")
  valid?(@host, "Host IP to bind must be given")

  valid_dir? @cwd, "Cannot change to a directory that doesn't exist"
  Dir.chdir @cwd
  valid_dir? "log", "Log directory does not exist"

  return @valid
end