Module: Kryten::Daemon
- Included in:
- BackgroundTask
- Defined in:
- lib/kryten/daemon.rb
Instance Attribute Summary collapse
-
#worker ⇒ Object
readonly
Returns the value of attribute worker.
-
#workers ⇒ Object
Returns the value of attribute workers.
Instance Method Summary collapse
- #log_path ⇒ Object
- #mixed ⇒ Object
- #running ⇒ Object
- #setup ⇒ Object
- #shutdown ⇒ Object
- #start_work ⇒ Object
- #status ⇒ Object
- #stop_work ⇒ Object
Instance Attribute Details
#worker ⇒ Object (readonly)
Returns the value of attribute worker.
4 5 6 |
# File 'lib/kryten/daemon.rb', line 4 def worker @worker end |
#workers ⇒ Object
Returns the value of attribute workers.
5 6 7 |
# File 'lib/kryten/daemon.rb', line 5 def workers @workers end |
Instance Method Details
#log_path ⇒ Object
33 34 35 |
# File 'lib/kryten/daemon.rb', line 33 def log_path "/tmp/#{name}.log" end |
#mixed ⇒ Object
37 38 39 40 |
# File 'lib/kryten/daemon.rb', line 37 def mixed @mixed = true self end |
#running ⇒ Object
68 69 70 |
# File 'lib/kryten/daemon.rb', line 68 def running worker && worker.running? || false end |
#setup ⇒ Object
7 8 9 10 11 12 13 |
# File 'lib/kryten/daemon.rb', line 7 def setup super if workers log 'starting workers' workers.each(&:start_work) end end |
#shutdown ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/kryten/daemon.rb', line 42 def shutdown if @mixed && workers workers.each(&:stop_running) elsif workers workers.each { |w| fork { w.shutdown }} Process.waitall end worker.stop_all if worker end |
#start_work ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kryten/daemon.rb', line 15 def start_work if worker && worker.running? log 'worker already running' return false end = { dir_mode: :script, dir: '/tmp/', log_output: false, backtrace: false, multiple: false, ARGV: ['start'] } @worker.start_all if @worker @worker ||= Daemons.run_proc(name, ) { start } end |
#status ⇒ Object
64 65 66 |
# File 'lib/kryten/daemon.rb', line 64 def status worker && worker.show_status || 'off' end |
#stop_work ⇒ Object
52 53 54 |
# File 'lib/kryten/daemon.rb', line 52 def stop_work stop_running end |