Class: Karafka::Cli::Server

Inherits:
Base
  • Object
show all
Defined in:
lib/karafka/cli/server.rb

Overview

Server Karafka Cli action

Instance Attribute Summary

Attributes inherited from Base

#cli

Instance Method Summary collapse

Methods inherited from Base

bind_to, desc, #initialize, option

Constructor Details

This class inherits a constructor from Karafka::Cli::Base

Instance Method Details

#callObject

Start the Karafka server



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
# File 'lib/karafka/cli/server.rb', line 15

def call
  validate!

  puts 'Starting Karafka server'
  cli.info

  if cli.options[:daemon]
    FileUtils.mkdir_p File.dirname(cli.options[:pid])
    daemonize
  end

  # We assign active topics on a server level, as only server is expected to listen on
  # part of the topics
  Karafka::Server.consumer_groups = cli.options[:consumer_groups]

  # Remove pidfile on stop, just before the server instance is going to be GCed
  # We want to delay the moment in which the pidfile is removed as much as we can,
  # so instead of removing it after the server stops running, we rely on the gc moment
  # when this object gets removed (it is a bit later), so it is closer to the actual
  # system process end. We do that, so monitoring and deployment tools that rely on pids
  # won't alarm or start new system process up until the current one is finished
  ObjectSpace.define_finalizer(self, proc { send(:clean) })

  # After we fork, we can boot celluloid again
  Karafka::Server.run
end