Class: Freyr::Command
- Inherits:
-
Object
- Object
- Freyr::Command
- Extended by:
- Forwardable
- Defined in:
- lib/freyr/command.rb
Instance Attribute Summary collapse
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Class Method Summary collapse
Instance Method Summary collapse
- #command ⇒ Object
-
#initialize(service, command = nil, args = {}) ⇒ Command
constructor
A new instance of Command.
- #kill!(sig = nil) ⇒ Object
- #pid(force = false) ⇒ Object
- #restart! ⇒ Object
- #run! ⇒ Object
Constructor Details
#initialize(service, command = nil, args = {}) ⇒ Command
Returns a new instance of Command.
8 9 10 |
# File 'lib/freyr/command.rb', line 8 def initialize(service, command=nil, args = {}) @service = service end |
Instance Attribute Details
#service ⇒ Object (readonly)
Returns the value of attribute service.
6 7 8 |
# File 'lib/freyr/command.rb', line 6 def service @service end |
Class Method Details
.add_service_method(*methods) ⇒ Object
161 162 |
# File 'lib/freyr/command.rb', line 161 def add_service_method *methods end |
Instance Method Details
#command ⇒ Object
15 16 17 |
# File 'lib/freyr/command.rb', line 15 def command info.start end |
#kill!(sig = nil) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/freyr/command.rb', line 53 def kill!(sig=nil) require_admin sig ||= info.stop_sig || 'KILL' Freyr.logger.debug("sending signal to process") {"Signal: #{sig}, PID: #{pid}"} if pid(true) Process.kill(sig, pid) end end |
#pid(force = false) ⇒ Object
64 65 66 |
# File 'lib/freyr/command.rb', line 64 def pid force = false @service.pid_file.pid(force) end |
#restart! ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/freyr/command.rb', line 68 def restart! require_admin if info.restart chdir system(info.restart) elsif info.restart_sig kill!(info.restart_sig) else run! end end |
#run! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/freyr/command.rb', line 19 def run! raise "no start command found for service #{name}" unless command kill! if service.alive? require_admin total_time = Time.now Freyr.logger.debug("attempting to run command") {command.inspect} pid = spawn(command) str = "Starting #{info.name} with #{command.inspect}" OUT.puts '',str, '='*str.length Process.detach(pid) pid = service.pid_file.wait_for_pid OUT.puts "PID of new #{info.name} process is #{pid}" if info.ping pinger = Pinger.new(@service) pinger.wait_for_resp { @service.alive? } end if @service.alive? OUT.puts "Launch took about #{(Time.now-total_time).ceil} seconds" pid else OUT.puts "#{info.name} service wasn't launched correctly. For details see: #{info.log}" end end |