Class: Zeus::Server::ForkedProcess

Inherits:
Object
  • Object
show all
Defined in:
lib/zeus/server/forked_process.rb

Overview

base class for Stage and Acceptor

Direct Known Subclasses

Stage

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(server) ⇒ ForkedProcess

Returns a new instance of ForkedProcess.



8
9
10
# File 'lib/zeus/server/forked_process.rb', line 8

def initialize(server)
  @server = server
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/zeus/server/forked_process.rb', line 6

def name
  @name
end

#pidObject (readonly)

Returns the value of attribute pid.



7
8
9
# File 'lib/zeus/server/forked_process.rb', line 7

def pid
  @pid
end

Instance Method Details

#after_notifyObject



75
76
# File 'lib/zeus/server/forked_process.rb', line 75

def after_notify
end

#after_setupObject



63
64
# File 'lib/zeus/server/forked_process.rb', line 63

def after_setup
end

#before_setupObject



60
61
# File 'lib/zeus/server/forked_process.rb', line 60

def before_setup
end

#descendent_acceptorsObject

Raises:

  • (NotImplementedError)


16
17
18
# File 'lib/zeus/server/forked_process.rb', line 16

def descendent_acceptors
  raise NotImplementedError
end

#newly_loaded_featuresObject



51
52
53
54
# File 'lib/zeus/server/forked_process.rb', line 51

def newly_loaded_features
  old_features = defined?($previously_loaded_features) ? $previously_loaded_features : []
  ($LOADED_FEATURES + @server.extra_features) - old_features
end

#notify_feature(feature) ⇒ Object



12
13
14
# File 'lib/zeus/server/forked_process.rb', line 12

def notify_feature(feature)
  @server.__CHILD__stage_has_feature(@name, feature)
end

#notify_new_featuresObject



66
67
68
69
70
71
72
73
# File 'lib/zeus/server/forked_process.rb', line 66

def notify_new_features
  new_features = newly_loaded_features()
  $previously_loaded_features ||= []
  $previously_loaded_features |= new_features
  Thread.new {
    new_features.each { |f| notify_feature(f) }
  }
end

#notify_startedObject



24
25
26
27
# File 'lib/zeus/server/forked_process.rb', line 24

def notify_started
  @server.__CHILD__stage_starting_with_pid(@name, Process.pid)
  Zeus.ui.info("starting #{process_type} `#{@name}`")
end

#notify_terminatedObject



29
30
31
32
# File 'lib/zeus/server/forked_process.rb', line 29

def notify_terminated
  # @server.__CHILD__stage_terminating(@name)
  Zeus.ui.info("killing #{process_type} `#{@name}`")
end

#process_typeObject



20
21
22
# File 'lib/zeus/server/forked_process.rb', line 20

def process_type
  raise "NotImplementedError"
end

#run(close_parent_sockets = false) ⇒ Object

TODO: This just got really ugly and needs a refactor more than ever.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/zeus/server/forked_process.rb', line 79

def run(close_parent_sockets = false)
  @pid = fork {
    before_setup
    setup_forked_process(close_parent_sockets)

    Zeus.run_after_fork!

    after_setup
    notify_new_features

    after_notify
    runloop!
  }
end

#runloop!Object

Raises:

  • (NotImplementedError)


56
57
58
# File 'lib/zeus/server/forked_process.rb', line 56

def runloop!
  raise NotImplementedError
end

#setup_forked_process(close_parent_sockets) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/zeus/server/forked_process.rb', line 34

def setup_forked_process(close_parent_sockets)
  @server.__CHILD__close_parent_sockets if close_parent_sockets

  notify_started

  $0 = "zeus #{process_type}: #{@name}"

  trap("INT") { exit }
  trap("TERM") {
    notify_terminated
    exit
  }

  defined?(ActiveRecord::Base) and ActiveRecord::Base.clear_all_connections!

end