Class: Thin::Command
Overview
Run a command though the thin
command-line script.
Class Attribute Summary collapse
-
.script ⇒ Object
Path to the
thin
script used to control the servers.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, options = {}) ⇒ Command
constructor
A new instance of Command.
-
#run ⇒ Object
Send the command to the
thin
script. -
#shellify ⇒ Object
Turn into a runnable shell command.
Methods included from Logging
#debug, debug, debug?, #log, log, #log_error, log_error, #silent, #silent=, silent?, #trace, trace, trace?
Constructor Details
#initialize(name, options = {}) ⇒ Command
Returns a new instance of Command.
14 15 16 17 |
# File 'lib/thin/command.rb', line 14 def initialize(name, ={}) @name = name @options = end |
Class Attribute Details
.script ⇒ Object
Path to the thin
script used to control the servers. Leave this to default to use the one in the path.
11 12 13 |
# File 'lib/thin/command.rb', line 11 def script @script end |
Class Method Details
.run(*args) ⇒ Object
19 20 21 |
# File 'lib/thin/command.rb', line 19 def self.run(*args) new(*args).run end |
Instance Method Details
#run ⇒ Object
Send the command to the thin
script
24 25 26 27 28 29 30 31 32 |
# File 'lib/thin/command.rb', line 24 def run shell_cmd = shellify trace shell_cmd trap('INT') {} # Ignore INT signal to pass CTRL+C to subprocess Open3.popen3(shell_cmd) do |stdin, stdout, stderr| log stdout.gets until stdout.eof? log stderr.gets until stderr.eof? end end |
#shellify ⇒ Object
Turn into a runnable shell command
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/thin/command.rb', line 35 def shellify = @options.inject([]) do |args, (name, value)| case value when NilClass, TrueClass then args << "--#{name}" when FalseClass when Array then value.each { |v| args << "--#{name}=#{v.inspect}" } else args << "--#{name.to_s.tr('_', '-')}=#{value.inspect}" end args end raise ArgumentError, "Path to thin script can't be found, set Command.script" unless self.class.script "#{self.class.script} #{@name} #{.compact.join(' ')}" end |