Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ability to restart by reexecing and pumactl to use it
This allows all existing requests to finish, but does not keep the same socket alive across the exec, so this is not a graceful as it could be.
- Loading branch information
Showing
6 changed files
with
199 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ cli = Puma::CLI.new ARGV | |
begin | ||
cli.run | ||
rescue => e | ||
raise e if $DEBUG | ||
STDERR.puts e.message | ||
exit 1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env ruby | ||
|
||
require 'puma/control_cli' | ||
|
||
cli = Puma::ControlCLI.new ARGV | ||
|
||
begin | ||
cli.run | ||
rescue => e | ||
STDERR.puts e.message | ||
exit 1 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
require 'optparse' | ||
|
||
require 'puma/const' | ||
require 'yaml' | ||
require 'uri' | ||
|
||
require 'socket' | ||
|
||
module Puma | ||
class ControlCLI | ||
|
||
def initialize(argv) | ||
@argv = argv | ||
end | ||
|
||
def setup_options | ||
@parser = OptionParser.new do |o| | ||
o.on "-S", "--state PATH", "Where the state file to use is" do |arg| | ||
@path = arg | ||
end | ||
end | ||
end | ||
|
||
def connect | ||
if str = @state['status_address'] | ||
uri = URI.parse str | ||
case uri.scheme | ||
when "tcp" | ||
return TCPSocket.new uri.host, uri.port | ||
when "unix" | ||
path = "#{uri.host}#{uri.path}" | ||
return UNIXSocket.new path | ||
else | ||
raise "Invalid URI: #{str}" | ||
end | ||
end | ||
|
||
raise "No status address configured" | ||
end | ||
|
||
def run | ||
setup_options | ||
|
||
@parser.parse! @argv | ||
|
||
@state = YAML.load_file(@path) | ||
|
||
cmd = @argv.shift | ||
|
||
meth = "command_#{cmd}" | ||
|
||
if respond_to?(meth) | ||
__send__(meth) | ||
else | ||
raise "Unknown command: #{cmd}" | ||
end | ||
end | ||
|
||
def command_pid | ||
puts "#{@state['pid']}" | ||
end | ||
|
||
def command_stop | ||
sock = connect | ||
sock << "GET /stop HTTP/1.0\r\n\r\n" | ||
rep = sock.read | ||
|
||
body = rep.split("\r\n").last | ||
if body != '{ "status": "ok" }' | ||
raise "Invalid response: '#{body}'" | ||
else | ||
puts "Requested stop from server" | ||
end | ||
end | ||
|
||
def command_halt | ||
sock = connect | ||
s << "GET /halt HTTP/1.0\r\n\r\n" | ||
rep = s.read | ||
|
||
body = rep.split("\r\n").last | ||
if body != '{ "status": "ok" }' | ||
raise "Invalid response: '#{body}'" | ||
else | ||
puts "Requested halt from server" | ||
end | ||
end | ||
|
||
def command_restart | ||
sock = connect | ||
sock << "GET /restart HTTP/1.0\r\n\r\n" | ||
rep = sock.read | ||
|
||
body = rep.split("\r\n").last | ||
if body != '{ "status": "ok" }' | ||
raise "Invalid response: '#{body}'" | ||
else | ||
puts "Requested restart from server" | ||
end | ||
end | ||
|
||
def command_stats | ||
sock = connect | ||
s << "GET /stats HTTP/1.0\r\n\r\n" | ||
rep = s.read | ||
|
||
body = rep.split("\r\n").last | ||
|
||
puts body | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters