mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Add pidfile support. Fixes #18
This commit is contained in:
parent
c4d29698c4
commit
6daeb06688
2 changed files with 37 additions and 1 deletions
|
@ -51,6 +51,10 @@ module Puma
|
|||
o.on "-b", "--bind URI", "URI to bind to (tcp:// and unix:// only)" do |arg|
|
||||
@binds << arg
|
||||
end
|
||||
|
||||
o.on "--pidfile PATH", "Use PATH as a pidfile" do |arg|
|
||||
@options[:pidfile] = arg
|
||||
end
|
||||
end
|
||||
|
||||
@parser.banner = "puma <options> <rackup file>"
|
||||
|
@ -72,8 +76,20 @@ module Puma
|
|||
end
|
||||
end
|
||||
|
||||
def run
|
||||
def write_pid
|
||||
if path = @options[:pidfile]
|
||||
File.open(path, "w") do |f|
|
||||
f.puts Process.pid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parse_options
|
||||
@parser.parse! @argv
|
||||
end
|
||||
|
||||
def run
|
||||
parse_options
|
||||
|
||||
@rackup = ARGV.shift || "config.ru"
|
||||
|
||||
|
@ -82,6 +98,7 @@ module Puma
|
|||
end
|
||||
|
||||
load_rackup
|
||||
write_pid
|
||||
|
||||
if @binds.empty?
|
||||
@options[:Host] ||= DefaultTCPHost
|
||||
|
|
19
test/test_cli.rb
Normal file
19
test/test_cli.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
require 'test/unit'
|
||||
require 'puma/cli'
|
||||
require 'tempfile'
|
||||
|
||||
class TestCLI < Test::Unit::TestCase
|
||||
def setup
|
||||
@pid_file = Tempfile.new("puma-test")
|
||||
@pid_path = @pid_file.path
|
||||
@pid_file.close!
|
||||
end
|
||||
|
||||
def test_pid_file
|
||||
cli = Puma::CLI.new ["--pidfile", @pid_path]
|
||||
cli.parse_options
|
||||
cli.write_pid
|
||||
|
||||
assert_equal File.read(@pid_path).strip.to_i, Process.pid
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue