Skip to content

Commit

Permalink
Add ability to daemonize fakes3 server. Fixes jubos#109.
Browse files Browse the repository at this point in the history
  • Loading branch information
jchristi committed Jul 23, 2015
1 parent c359b2c commit 9c599c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/fakes3/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CLI < Thor
method_option :limit, :aliases => '-l', :type => :string, :desc => 'Rate limit for serving (ie. 50K, 1.0M)'
method_option :sslcert, :type => :string, :desc => 'Path to SSL certificate'
method_option :sslkey, :type => :string, :desc => 'Path to SSL certificate key'
method_option :daemonize, :type => :boolean, :aliases => '-d', :required => false, :desc => 'Daemonize the server process. Defaults to false.'

def server
store = nil
Expand Down Expand Up @@ -47,13 +48,14 @@ def server
address = options[:address] || '0.0.0.0'
ssl_cert_path = options[:sslcert]
ssl_key_path = options[:sslkey]
daemonize = options[:daemonize] || false

if (ssl_cert_path.nil? && !ssl_key_path.nil?) || (!ssl_cert_path.nil? && ssl_key_path.nil?)
abort "If you specify an SSL certificate you must also specify an SSL certificate key"
end

puts "Loading FakeS3 with #{root} on port #{options[:port]} with hostname #{hostname}"
server = FakeS3::Server.new(address,options[:port],store,hostname,ssl_cert_path,ssl_key_path)
server = FakeS3::Server.new(address,options[:port],store,hostname,ssl_cert_path,ssl_key_path,daemonize)
server.serve
end

Expand Down
4 changes: 3 additions & 1 deletion lib/fakes3/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,14 @@ def dump_request(request)


class Server
def initialize(address,port,store,hostname,ssl_cert_path,ssl_key_path)
def initialize(address,port,store,hostname,ssl_cert_path,ssl_key_path,daemonize)
@address = address
@port = port
@store = store
@hostname = hostname
@ssl_cert_path = ssl_cert_path
@ssl_key_path = ssl_key_path
@daemonize = daemonize || false
webrick_config = {
:BindAddress => @address,
:Port => @port
Expand All @@ -525,6 +526,7 @@ def initialize(address,port,store,hostname,ssl_cert_path,ssl_key_path)
}
)
end
WEBrick::Daemon.start if @daemonize
@server = WEBrick::HTTPServer.new(webrick_config)
end

Expand Down

0 comments on commit 9c599c0

Please sign in to comment.