Class: SSL::Start

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

Instance Method Summary collapse

Instance Method Details

#configureObject



11
12
13
14
15
16
17
18
19
# File 'lib/mongrel_in_a_tunnel/init.rb', line 11

def configure
  options [
    ['', '--ssl-cert', 'Specify the SSL certificate to use', :@ssl_cert, '/opt/local/etc/stunnel/stunnel.pem'],
    ['', '--ssl-port', 'Port to listen for HTTPS requests', :@ssl_port, 443],
    ['', '--ssl-listen', 'IP address to listen on', :@ssl_listen, '127.0.0.1'],
    ['-p', '--port', 'port for mongrel', :@port, 3000],
    ['-e', '--environment', 'RAILS_ENV', :@environment, nil]
  ]
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
56
57
58
# File 'lib/mongrel_in_a_tunnel/init.rb', line 31

def run
  # generate config file and pass the file descriptor to the stunnel process
  
  # launch stunnel
  puts "Listening for SSL requests on #{@ssl_listen}:#{@ssl_port}"
  Kernel.fork do
    `stunnel #{stunnel_config} -f`
  end

  args = []
  args << "start"
  args << "-e #{@environment}" if @environment
  args << "-p #{@port}"
  
  begin
    command = GemPlugin::Manager.instance.create("/commands/mongrel::start", :argv => args)
  rescue OptionParser::InvalidOption
    STDERR.puts "#$! for command '#{cmd_name}'"
    STDERR.puts "Try #{cmd_name} -h to get help."
    return false
  rescue
    STDERR.puts "ERROR RUNNING '#{cmd_name}': #$!"
    STDERR.puts "Use help command to get help"
    return false
  end
  # run mongrel
  command.run
end

#stunnel_configObject



27
28
29
# File 'lib/mongrel_in_a_tunnel/init.rb', line 27

def stunnel_config
  GemPlugin::Manager.instance.resource "mongrel_in_a_tunnel", "/stunnel.conf"
end

#validateObject



21
22
23
24
25
# File 'lib/mongrel_in_a_tunnel/init.rb', line 21

def validate
  @ssl_port = @ssl_port.to_i
  valid? (@ssl_port > 0 && @ssl_port < 65000), true
  return @valid
end