Class: Zeusd::Daemon
Instance Attribute Summary collapse
-
#child_process ⇒ Object
readonly
Returns the value of attribute child_process.
-
#cwd ⇒ Object
readonly
Returns the value of attribute cwd.
-
#interpreter ⇒ Object
readonly
Returns the value of attribute interpreter.
-
#log_file ⇒ Object
readonly
Returns the value of attribute log_file.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Daemon
constructor
A new instance of Daemon.
- #loaded? ⇒ Boolean
- #process ⇒ Object
- #restart!(options = {}) ⇒ Object
- #socket_file ⇒ Object
- #start!(options = {}) ⇒ Object
- #stop! ⇒ Object
- #verbose? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Daemon
Returns a new instance of Daemon.
29 30 31 32 33 |
# File 'lib/zeusd/daemon.rb', line 29 def initialize( = {}) @cwd = Pathname.new([:cwd] || Dir.pwd).realpath @verbose = !![:verbose] @interpreter = Interpreter.new end |
Instance Attribute Details
#child_process ⇒ Object (readonly)
Returns the value of attribute child_process.
10 11 12 |
# File 'lib/zeusd/daemon.rb', line 10 def child_process @child_process end |
#cwd ⇒ Object (readonly)
Returns the value of attribute cwd.
10 11 12 |
# File 'lib/zeusd/daemon.rb', line 10 def cwd @cwd end |
#interpreter ⇒ Object (readonly)
Returns the value of attribute interpreter.
10 11 12 |
# File 'lib/zeusd/daemon.rb', line 10 def interpreter @interpreter end |
#log_file ⇒ Object (readonly)
Returns the value of attribute log_file.
10 11 12 |
# File 'lib/zeusd/daemon.rb', line 10 def log_file @log_file end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
10 11 12 |
# File 'lib/zeusd/daemon.rb', line 10 def verbose @verbose end |
Instance Method Details
#loaded? ⇒ Boolean
75 76 77 |
# File 'lib/zeusd/daemon.rb', line 75 def loaded? interpreter.complete? end |
#process ⇒ Object
71 72 73 |
# File 'lib/zeusd/daemon.rb', line 71 def process @process ||= Process.all.find {|p| !!p.command[/zeus.*start$/] && p.cwd == cwd } end |
#restart!(options = {}) ⇒ Object
49 50 51 |
# File 'lib/zeusd/daemon.rb', line 49 def restart!( = {}) stop!.start!() end |
#socket_file ⇒ Object
83 84 85 |
# File 'lib/zeusd/daemon.rb', line 83 def socket_file cwd.join('.zeus.sock') end |
#start!(options = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/zeusd/daemon.rb', line 35 def start!( = {}) start_child_process! @process = Zeusd::Process.find(child_process.pid) if .fetch(:block, false) sleep(0.1) until loaded? end self ensure run_hook :after_start! end |
#stop! ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/zeusd/daemon.rb', line 53 def stop! return self unless process # Kill process tree and wait for exits process.kill!(:recursive => true, :wait => true) # Check for remaining processes if[process, process.descendants].flatten.select(&:alive?).any? raise DaemonException, "Unable to KILL processes: " + alive_processes.join(', ') end @process = nil self ensure run_hook :after_stop! end |
#verbose? ⇒ Boolean
87 88 89 |
# File 'lib/zeusd/daemon.rb', line 87 def verbose? !!verbose end |