mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
make pumactl restart
start puma if not running
This commit is contained in:
parent
f9fc59bb7e
commit
274350a2e6
1 changed files with 31 additions and 23 deletions
|
@ -18,7 +18,7 @@ module Puma
|
||||||
@stdout = stdout
|
@stdout = stdout
|
||||||
@stderr = stderr
|
@stderr = stderr
|
||||||
@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) (#{COMMANDS.join("|")})"
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.order!(argv) { |a| opts.terminate a }
|
opts.order!(argv) { |a| opts.terminate a }
|
||||||
|
|
||||||
command = argv.shift
|
command = argv.shift
|
||||||
@options[:command] = command if command
|
@options[:command] = command if command
|
||||||
|
|
||||||
|
@ -68,14 +68,14 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
unless COMMANDS.include? @options[:command]
|
unless COMMANDS.include? @options[:command]
|
||||||
raise "Invalid command: #{@options[:command]}"
|
raise "Invalid command: #{@options[:command]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
rescue => e
|
rescue => e
|
||||||
@stdout.puts e.message
|
@stdout.puts e.message
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
def message(msg)
|
def message(msg)
|
||||||
@stdout.puts msg unless @options[:quiet_flag]
|
@stdout.puts msg unless @options[:quiet_flag]
|
||||||
end
|
end
|
||||||
|
@ -116,7 +116,7 @@ module Puma
|
||||||
|
|
||||||
def send_request
|
def send_request
|
||||||
uri = URI.parse @options[:control_url]
|
uri = URI.parse @options[:control_url]
|
||||||
|
|
||||||
# create server object by scheme
|
# create server object by scheme
|
||||||
@server = case uri.scheme
|
@server = case uri.scheme
|
||||||
when "tcp"
|
when "tcp"
|
||||||
|
@ -161,7 +161,7 @@ module Puma
|
||||||
message "Command #{@options[:command]} sent success"
|
message "Command #{@options[:command]} sent success"
|
||||||
message response.last if @options[:command] == "stats"
|
message response.last if @options[:command] == "stats"
|
||||||
end
|
end
|
||||||
|
|
||||||
@server.close
|
@server.close
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -173,7 +173,12 @@ module Puma
|
||||||
begin
|
begin
|
||||||
Process.getpgid pid
|
Process.getpgid pid
|
||||||
rescue SystemCallError
|
rescue SystemCallError
|
||||||
raise "No pid '#{pid}' found"
|
if @options[:command] == "restart"
|
||||||
|
@options.delete(:command)
|
||||||
|
start
|
||||||
|
else
|
||||||
|
raise "No pid '#{pid}' found"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
case @options[:command]
|
case @options[:command]
|
||||||
|
@ -202,23 +207,10 @@ module Puma
|
||||||
end
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
if @options[:command] == "start"
|
start if @options[:command] == "start"
|
||||||
require 'puma/cli'
|
|
||||||
|
|
||||||
run_args = @argv
|
|
||||||
if path = @options[:status_path]
|
|
||||||
run_args = ["-S", path] + run_args
|
|
||||||
end
|
|
||||||
|
|
||||||
events = Puma::Events.new @stdout, @stderr
|
|
||||||
|
|
||||||
cli = Puma::CLI.new run_args, events
|
|
||||||
cli.run
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
prepare_configuration
|
prepare_configuration
|
||||||
|
|
||||||
if is_windows?
|
if is_windows?
|
||||||
send_request
|
send_request
|
||||||
else
|
else
|
||||||
|
@ -229,5 +221,21 @@ module Puma
|
||||||
message e.message
|
message e.message
|
||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def start
|
||||||
|
require 'puma/cli'
|
||||||
|
|
||||||
|
run_args = @argv
|
||||||
|
if path = @options[:status_path]
|
||||||
|
run_args = ["-S", path] + run_args
|
||||||
|
end
|
||||||
|
|
||||||
|
events = Puma::Events.new @stdout, @stderr
|
||||||
|
|
||||||
|
cli = Puma::CLI.new run_args, events
|
||||||
|
cli.run
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue