Class: Librr::Runner

Inherits:
Object
  • Object
show all
Includes:
Logger::ClassLogger
Defined in:
lib/librr/runner.rb

Instance Method Summary collapse

Methods included from Logger::ClassLogger

#debug, #info, #logger

Instance Method Details

#clear_pidObject



56
57
58
59
# File 'lib/librr/runner.rb', line 56

def clear_pid
  filename = Settings::PID_FILE
  File.delete(filename) rescue nil
end

#run!Object



15
16
17
18
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
# File 'lib/librr/runner.rb', line 15

def run!
  self.clear_pid
  @stoping = false

  EventMachine.run do
    trap("SIGINT") do
      return if @stoping
      @stoping = true

      EM.stop
      self.info "eventmachine stopping.."
      # todo commandline still show ^C?
      self.clear_pid
    end

    indexer = Librr::Indexer.new
    monitor = Librr::DirMonitor.new
    server  = Librr::CmdServer.new

    monitor.init(indexer: indexer)
    server.init(indexer: indexer, monitor: monitor)

    indexer.start do
      monitor.start do
        server.start do
          self.info "daemon started"
          self.write_pid
        end
      end
    end

  end

  self.info "eventmachine stopped."
end

#write_pidObject



51
52
53
54
# File 'lib/librr/runner.rb', line 51

def write_pid
  filename = Settings::PID_FILE
  File.open(filename, 'w+'){ |f| f.write(Process.pid.to_s) }
end