Skip to content
Browse files

Add -p option to pumactl

  • Loading branch information...
1 parent dd494de commit 930093029524e5673ff68f49d9b00666fd7afc4f @evanphx evanphx committed
Showing with 28 additions and 12 deletions.
  1. +28 −12 lib/puma/control_cli.rb
View
40 lib/puma/control_cli.rb
@@ -20,7 +20,7 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@options = {}
opts = OptionParser.new do |o|
- o.banner = "Usage: pumactl (-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("|")})"
o.on "-S", "--state PATH", "Where the state file to use is" do |arg|
@options[:status_path] = arg
@@ -34,6 +34,10 @@ def initialize(argv, stdout=STDOUT, stderr=STDERR)
@options[:pid_file] = arg
end
+ o.on "-p", "--pid PID", "Pid" do |arg|
+ @options[:pid] = arg.to_i
+ end
+
o.on "-C", "--control-url URL", "The bind url to use for the control server" do |arg|
@options[:control_url] = arg
end
@@ -115,13 +119,13 @@ def send_request
# create server object by scheme
@server = case uri.scheme
- when "tcp"
- TCPSocket.new uri.host, uri.port
- when "unix"
- UNIXSocket.new "#{uri.host}#{uri.path}"
- else
- raise "Invalid scheme: #{uri.scheme}"
- end
+ when "tcp"
+ TCPSocket.new uri.host, uri.port
+ when "unix"
+ UNIXSocket.new "#{uri.host}#{uri.path}"
+ else
+ raise "Invalid scheme: #{uri.scheme}"
+ end
if @options[:command] == "status"
message "Puma is started"
@@ -151,17 +155,29 @@ def send_request
end
def send_signal
- Process.getpgid(@options[:pid])
+ unless pid = @options[:pid]
+ raise "Neither pid nor control url available"
+ end
+
+ begin
+ Process.getpgid pid
+ rescue SystemCallError
+ raise "No pid '#{pid}' found"
+ end
case @options[:command]
when "restart"
- Process.kill("SIGUSR2", @options[:pid])
+ Process.kill "SIGUSR2", pid
when "halt"
- Process.kill("QUIT", @options[:pid])
+ Process.kill "QUIT", pid
when "stop"
- Process.kill("SIGTERM", @options[:pid])
+ Process.kill "SIGTERM", pid
+
+ when "stats"
+ puts "Stats not available via pid only"
+ return
else
message "Puma is started"

0 comments on commit 9300930

Please sign in to comment.
Something went wrong with that request. Please try again.