Skip to content

Commit

Permalink
Use a unix socket temp path for the status url by default
Browse files Browse the repository at this point in the history
  • Loading branch information
evanphx committed Dec 5, 2011
1 parent 455c874 commit 559830a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/puma/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,17 @@ def setup_options
@options[:state] = arg
end

o.on "--status URL", "The bind url to use for the status server" do |arg|
@options[:status_address] = arg
o.on "--status [URL]", "The bind url to use for the status server" do |arg|
if arg
@options[:status_address] = arg
else
require 'tmpdir'

t = (Time.now.to_f * 1000).to_i
path = "#{Dir.tmpdir}/puma-status-#{t}-#{$$}"

@options[:status_address] = "unix://#{path}"
end
end

end
Expand Down
17 changes: 17 additions & 0 deletions test/test_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ def test_status_stop
t.join
end

def test_tmp_status
url = "tcp://127.0.0.1:8232"
cli = Puma::CLI.new ["--state", @tmp_path, "--status"]
cli.parse_options
cli.write_state

data = YAML.load_file(@tmp_path)

assert_equal Process.pid, data["pid"]

url = data["status_address"]

m = %r!unix://(.*)!.match(url)

assert m, "'#{url}' is not a URL"
end

def test_state
url = "tcp://127.0.0.1:8232"
cli = Puma::CLI.new ["--state", @tmp_path, "--status", url]
Expand Down

0 comments on commit 559830a

Please sign in to comment.