mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Allow configuring pumactl with config.rb
example: echo "pidfile '/tmp/app.pid'; rackup 'config.ru'" > /etc/puma/app.rb pumactl -F /etc/puma/app.rb start # starts an app and store pid in /tmp/app.pid pumactl -F /etc/puma/app.rb stop # stops the started earlier app Integration test t2 included: rake test:integration Also fixed discrepancy in naming options :pidfile/:pid_file and :state/:status_file
This commit is contained in:
parent
228edd90e0
commit
83163c3f28
5 changed files with 56 additions and 15 deletions
|
@ -20,10 +20,10 @@ module Puma
|
||||||
@options = {}
|
@options = {}
|
||||||
|
|
||||||
opts = OptionParser.new do |o|
|
opts = OptionParser.new do |o|
|
||||||
o.banner = "Usage: pumactl (-p PID | -P pidfile | -S status_file | -C url -T token) (#{COMMANDS.join("|")})"
|
o.banner = "Usage: pumactl (-p PID | -P pidfile | -S status_file | -C url -T token | -F config.rb) (#{COMMANDS.join("|")})"
|
||||||
|
|
||||||
o.on "-S", "--state PATH", "Where the state file to use is" do |arg|
|
o.on "-S", "--state PATH", "Where the state file to use is" do |arg|
|
||||||
@options[:status_path] = arg
|
@options[:state] = arg
|
||||||
end
|
end
|
||||||
|
|
||||||
o.on "-Q", "--quiet", "Not display messages" do |arg|
|
o.on "-Q", "--quiet", "Not display messages" do |arg|
|
||||||
|
@ -31,7 +31,7 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
o.on "-P", "--pidfile PATH", "Pid file" do |arg|
|
o.on "-P", "--pidfile PATH", "Pid file" do |arg|
|
||||||
@options[:pid_file] = arg
|
@options[:pidfile] = arg
|
||||||
end
|
end
|
||||||
|
|
||||||
o.on "-p", "--pid PID", "Pid" do |arg|
|
o.on "-p", "--pid PID", "Pid" do |arg|
|
||||||
|
@ -46,6 +46,10 @@ module Puma
|
||||||
@options[:control_auth_token] = arg
|
@options[:control_auth_token] = arg
|
||||||
end
|
end
|
||||||
|
|
||||||
|
o.on "-F", "--config-file PATH", "Puma config script" do |arg|
|
||||||
|
@options[:config_file] = arg
|
||||||
|
end
|
||||||
|
|
||||||
o.on_tail("-H", "--help", "Show this message") do
|
o.on_tail("-H", "--help", "Show this message") do
|
||||||
@stdout.puts o
|
@stdout.puts o
|
||||||
exit
|
exit
|
||||||
|
@ -62,6 +66,8 @@ module Puma
|
||||||
command = argv.shift
|
command = argv.shift
|
||||||
@options[:command] = command if command
|
@options[:command] = command if command
|
||||||
|
|
||||||
|
Puma::Configuration.new(@options).load if @options[:config_file]
|
||||||
|
|
||||||
# check present of command
|
# check present of command
|
||||||
unless @options[:command]
|
unless @options[:command]
|
||||||
raise "Available commands: #{COMMANDS.join(", ")}"
|
raise "Available commands: #{COMMANDS.join(", ")}"
|
||||||
|
@ -81,12 +87,12 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_configuration
|
def prepare_configuration
|
||||||
if @options.has_key? :status_path
|
if @options.has_key? :state
|
||||||
unless File.exist? @options[:status_path]
|
unless File.exist? @options[:state]
|
||||||
raise "Status file not found: #{@options[:status_path]}"
|
raise "Status file not found: #{@options[:state]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
status = YAML.load File.read(@options[:status_path])
|
status = YAML.load File.read(@options[:state])
|
||||||
|
|
||||||
if status.kind_of?(Hash) && status.has_key?("config")
|
if status.kind_of?(Hash) && status.has_key?("config")
|
||||||
|
|
||||||
|
@ -105,12 +111,12 @@ module Puma
|
||||||
# get pid
|
# get pid
|
||||||
@options[:pid] = status["pid"].to_i
|
@options[:pid] = status["pid"].to_i
|
||||||
else
|
else
|
||||||
raise "Invalid status file: #{@options[:status_path]}"
|
raise "Invalid status file: #{@options[:state]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
elsif @options.has_key? :pid_file
|
elsif @options.has_key? :pidfile
|
||||||
# get pid from pid_file
|
# get pid from pid_file
|
||||||
@options[:pid] = File.open(@options[:pid_file]).gets.to_i
|
@options[:pid] = File.open(@options[:pidfile]).gets.to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -206,9 +212,12 @@ module Puma
|
||||||
require 'puma/cli'
|
require 'puma/cli'
|
||||||
|
|
||||||
run_args = @argv
|
run_args = @argv
|
||||||
if path = @options[:status_path]
|
if path = @options[:state]
|
||||||
run_args = ["-S", path] + run_args
|
run_args = ["-S", path] + run_args
|
||||||
end
|
end
|
||||||
|
if path = @options[:config_file]
|
||||||
|
run_args = ["-C", path] + run_args
|
||||||
|
end
|
||||||
|
|
||||||
events = Puma::Events.new @stdout, @stderr
|
events = Puma::Events.new @stdout, @stderr
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
|
ERROR=0
|
||||||
|
|
||||||
if ruby -rubygems t1.rb > /dev/null 2>&1; then
|
if ruby -rubygems t1.rb > /dev/null 2>&1; then
|
||||||
echo "t1 OK"
|
echo "t1 OK"
|
||||||
exit 0
|
|
||||||
else
|
else
|
||||||
echo "t1 FAIL"
|
echo "t1 FAIL"
|
||||||
exit 1
|
ERROR=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if ruby -rubygems t2.rb > /dev/null 2>&1; then
|
||||||
|
echo "t2 OK"
|
||||||
|
else
|
||||||
|
echo "t2 FAIL"
|
||||||
|
ERROR=2
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $ERROR
|
||||||
|
|
|
@ -8,8 +8,8 @@ sleep 1
|
||||||
|
|
||||||
log = File.read("t1-stdout")
|
log = File.read("t1-stdout")
|
||||||
|
|
||||||
File.unlink "t1-stdout"
|
File.unlink "t1-stdout" if File.file? "t1-stdout"
|
||||||
File.unlink "t1-pid"
|
File.unlink "t1-pid" if File.file? "t1-pid"
|
||||||
|
|
||||||
if log =~ %r!GET / HTTP/1\.1!
|
if log =~ %r!GET / HTTP/1\.1!
|
||||||
exit 0
|
exit 0
|
||||||
|
|
17
test/shell/t2.rb
Normal file
17
test/shell/t2.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
system "ruby -rubygems -I../../lib ../../bin/pumactl -F t2_conf.rb start"
|
||||||
|
sleep 5
|
||||||
|
system "curl http://localhost:10103/"
|
||||||
|
|
||||||
|
system "ruby -rubygems -I../../lib ../../bin/pumactl -F t2_conf.rb stop"
|
||||||
|
|
||||||
|
sleep 1
|
||||||
|
|
||||||
|
log = File.read("t2-stdout")
|
||||||
|
|
||||||
|
File.unlink "t2-stdout" if File.file? "t2-stdout"
|
||||||
|
|
||||||
|
if log =~ %r(GET / HTTP/1\.1) && !File.file?("t2-pid")
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
end
|
5
test/shell/t2_conf.rb
Normal file
5
test/shell/t2_conf.rb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
stdout_redirect "t2-stdout"
|
||||||
|
pidfile "t2-pid"
|
||||||
|
bind "tcp://0.0.0.0:10103"
|
||||||
|
rackup File.expand_path('../hello.ru', File.dirname(__FILE__))
|
||||||
|
daemonize
|
Loading…
Reference in a new issue