Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Run as a Background Process #249

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,26 @@ To run the server, you must specify a root, a port, and your license key.

fakes3 -r /mnt/fakes3_root -p 4567 --license YOUR_LICENSE_KEY

### Running in the background

To run the server as a daemon process (in the background), use the -d flag. You can optionally specify where to write any output with the --output option.

fakes3 -r /mnt/fakes3_root -p 4567 --license YOUR_LICENSE_KEY -d

## Licensing

As of the latest version, we are licensing with Super Source. To get a license, visit:

https://supso.org/projects/fake-s3
https://supso.org/projects/fake-s3

Depending on your company's size, the license may be free. It is also free for individuals.

You pass the license key to Fake S3 with the command line option --license YOUR_LICENSE_KEY.

## Connecting to Fake S3

Take a look at the test cases to see client example usage. For now, Fake S3 is
mainly tested with s3cmd, aws-s3 gem, and right_aws. There are plenty more
Take a look at the test cases to see client example usage. For now, Fake S3 is
mainly tested with s3cmd, aws-s3 gem, and right_aws. There are plenty more
libraries out there, and please do mention if other clients work or not.

Here is a running list of [supported clients](https://github.com/jubos/fake-s3/wiki/Supported-Clients "Supported Clients")
Expand Down
10 changes: 7 additions & 3 deletions lib/fakes3/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class CLI < Thor
method_option :root, :type => :string, :aliases => '-r', :required => true
method_option :port, :type => :numeric, :aliases => '-p', :required => true
method_option :address, :type => :string, :aliases => '-a', :required => false, :desc => "Bind to this address. Defaults to all IP addresses of the machine."
method_option :hostname, :type => :string, :aliases => '-H', :desc => "The root name of the host. Defaults to s3.amazonaws.com."
method_option :hostname, :type => :string, :aliases => '-H', :desc => "The root name of the host. Defaults to s3.amazonaws.com."
method_option :quiet, :type => :boolean, :aliases => '-q', :desc => "Quiet; do not write anything to standard output."
method_option :daemon, :type => :boolean, :aliases => '-d', :desc => "Run the server process as a daemon (in the background). Defaults to false."
method_option :output, :type => :string, :desc => "Optional file to log server output to. Only used if running as a daemon with -d."
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'
Expand Down Expand Up @@ -41,7 +43,7 @@ def server
warn license_message
end
end

store = nil
if options[:root]
root = File.expand_path(options[:root])
Expand Down Expand Up @@ -80,13 +82,15 @@ def server
address = options[:address]
ssl_cert_path = options[:sslcert]
ssl_key_path = options[:sslkey]
daemon = options[:daemon] || false
output = options[:output] || nil

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 Fake S3 with #{root} on port #{options[:port]} with hostname #{hostname}" unless options[:quiet]
server = FakeS3::Server.new(address,options[:port],store,hostname,ssl_cert_path,ssl_key_path, quiet: !!options[:quiet], cors_options: cors_options)
server = FakeS3::Server.new(address, options[:port], store, hostname, ssl_cert_path, ssl_key_path, quiet: !!options[:quiet], cors_options: cors_options, daemon: daemon, output: output)
server.serve
end

Expand Down
6 changes: 6 additions & 0 deletions lib/fakes3/server.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'time'
require 'webrick'
require 'webrick/https'
require 'webrick/log'
require 'openssl'
require 'securerandom'
require 'cgi'
Expand Down Expand Up @@ -582,8 +583,13 @@ def initialize(address, port, store, hostname, ssl_cert_path, ssl_key_path, extr
:Logger => WEBrick::Log.new("/dev/null"),
:AccessLog => []
)
elsif extra_options[:daemon] && extra_options[:output]
webrick_config.merge!(
:Logger => WEBrick::Log.new(extra_options[:output])
)
end

WEBrick::Daemon.start if extra_options[:daemon]
@server = WEBrick::HTTPServer.new(webrick_config)
end

Expand Down