Class: DockerBoss::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/docker_boss/cli.rb

Instance Method Summary collapse

Instance Method Details

#onceObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/docker_boss/cli.rb', line 16

def once
  setup_logging
  read_config
  begin
    engine.refresh_and_trigger
  rescue Docker::Error::DockerError => e
    DockerBoss.logger.fatal "Error communicating with Docker: #{e.message}"
    exit 1
  end
end

#watchObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/docker_boss/cli.rb', line 33

def watch
  setup_logging
  read_config

  thw = engine.event_loop

  Daemons.daemonize if options[:daemonize]

  begin
    engine.refresh_and_trigger
    thw.next_wait.join
  rescue Docker::Error::DockerError => e
    DockerBoss.logger.fatal "Error communicating with Docker: #{e.message}"
    exit 1
  rescue SignalException => e
    case Signal.signame(e.signo)
    when "TERM", "INT"
      DockerBoss.logger.info "Received SIGTERM/SIGINT, shutting down."
      exit 0
    else
      DockerBoss.logger.fatal "Fatal unhandled signal in event loop: #{Signal.signame(e.signo)}"
      e.backtrace.each { |line| DockerBoss.logger.fatal "    #{line}" }
    end
  rescue Exception => e
    DockerBoss.logger.fatal "Fatal unhandled exception in event loop: #{e.class.name} -> #{e.message}"
    e.backtrace.each { |line| DockerBoss.logger.fatal "    #{line}" }
    exit 1
  end
end