Class: ConsulBridge::RunBridge

Inherits:
Object
  • Object
show all
Includes:
Metaractor
Defined in:
lib/consul_bridge/run_bridge.rb

Instance Method Summary collapse

Instance Method Details

#callObject



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
50
51
52
53
54
55
# File 'lib/consul_bridge/run_bridge.rb', line 17

def call
  Concurrent.use_stdlib_logger(Logger::DEBUG) if verbose

  self_read, self_write = IO.pipe
  %w(INT TERM).each do |sig|
    begin
      trap sig do
        self_write.puts(sig)
      end
    rescue ArgumentError
      puts "Signal #{sig} not supported"
    end
  end

  begin
    bootstrap_actor = BootstrapConsulActor.spawn(
      :bootstrap_consul,
      bucket: bucket,
      join_all: join_all
    )
    bootstrap_actor << :bootstrap

    MonitorDockerEventsActor.spawn(
      :monitor_docker_events,
      bootstrap_actor: bootstrap_actor,
      container_name: container_name
    )

    while readable_io = IO.select([self_read])
      signal = readable_io.first[0].gets.strip
      handle_signal(signal)
    end

  rescue Interrupt
    puts 'Exiting'
    # actors are cleaned up in at_exit handler
    exit 0
  end
end