Module: Griffin::Engine::Worker

Defined in:
lib/griffin/engine/worker.rb

Instance Method Summary collapse

Instance Method Details

#before_forkObject



10
11
12
# File 'lib/griffin/engine/worker.rb', line 10

def before_fork
  server.core.before_run(worker_id)
end

#initializeObject



6
7
8
# File 'lib/griffin/engine/worker.rb', line 6

def initialize
  @socket_manager = ServerEngine::SocketManager::Client.new(server.socket_manager_path)
end

#install_signal_handlersObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/griffin/engine/worker.rb', line 34

def install_signal_handlers
  w = self
  ServerEngine::SignalThread.new do |st|
    st.trap(ServerEngine::Signals::GRACEFUL_STOP) { |s| w.stop(s) }
    st.trap(ServerEngine::Signals::IMMEDIATE_STOP, 'SIG_DFL')

    st.trap(ServerEngine::Signals::GRACEFUL_RESTART) { |s| w.stop(s) }
    st.trap(ServerEngine::Signals::IMMEDIATE_RESTART, 'SIG_DFL')

    st.trap(ServerEngine::Signals::RELOAD) {
      w.logger.reopen!
      w.reload
    }
    st.trap(ServerEngine::Signals::DETACH) { |s| w.stop(s) }

    st.trap(ServerEngine::Signals::DUMP) { w.dump }
  end
end

#runObject



14
15
16
17
18
19
20
# File 'lib/griffin/engine/worker.rb', line 14

def run
  @lsock = @socket_manager.listen_tcp(config[:bind], config[:port])
  @lsock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
  server.core.run(@lsock)
ensure
  @lsock.close if @lsock
end

#stop(signal = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/griffin/engine/worker.rb', line 22

def stop(signal = nil)
  kind = case signal
         when ServerEngine::Signals::GRACEFUL_STOP then Griffin::Server::GRACEFUL_SHUTDOWN
         when ServerEngine::Signals::IMMEDIATE_STOP then Griffin::Server::FORCE_SHUTDOWN
         when ServerEngine::Signals::GRACEFUL_RESTART then Griffin::Server::GRACEFUL_RESTART
         else Griffin::Server::GRACEFUL_SHUTDOWN
         end
  server.core.shutdown(kind)
end