Module: Kryten::Daemon

Included in:
BackgroundTask
Defined in:
lib/kryten/daemon.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#workerObject (readonly)

Returns the value of attribute worker.



4
5
6
# File 'lib/kryten/daemon.rb', line 4

def worker
  @worker
end

#workersObject

Returns the value of attribute workers.



5
6
7
# File 'lib/kryten/daemon.rb', line 5

def workers
  @workers
end

Instance Method Details

#log_pathObject



33
34
35
# File 'lib/kryten/daemon.rb', line 33

def log_path
  "/tmp/#{name}.log"
end

#mixedObject



37
38
39
40
# File 'lib/kryten/daemon.rb', line 37

def mixed
  @mixed = true
  self
end

#runningObject



68
69
70
# File 'lib/kryten/daemon.rb', line 68

def running
  worker && worker.running? || false
end

#setupObject



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

#shutdownObject



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_workObject



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

  options = {
    dir_mode: :script,
    dir: '/tmp/',
    log_output: false,
    backtrace: false,
    multiple: false,
    ARGV: ['start']
  }
  @worker.start_all if @worker
  @worker ||= Daemons.run_proc(name, options) { start }
end

#statusObject



64
65
66
# File 'lib/kryten/daemon.rb', line 64

def status
  worker && worker.show_status || 'off'
end

#stop_workObject



52
53
54
# File 'lib/kryten/daemon.rb', line 52

def stop_work
  stop_running
end