Module: Messagebus::Swarm::Controller::ProcessManagementConcerns

Included in:
Messagebus::Swarm::Controller
Defined in:
lib/messagebus/swarm/controller.rb

Overview

:nodoc: all

Defined Under Namespace

Classes: DroneForker, DroneThreader

Constant Summary collapse

STOP_PARENT_PROCESSING_SIGNALS =

We capture INT (ctrl-c) and TERM (default signal kill sends).

%w(INT TERM)
STOP_SUBPROCESS_SIGNAL =
'TERM'

Instance Method Summary collapse

Instance Method Details

#start_drones(swarm_control_logger, fork_or_not, drones) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# File 'lib/messagebus/swarm/controller.rb', line 213

def start_drones(swarm_control_logger, fork_or_not, drones)
  swarm_control_logger.info("Booting drones fork=#{!!fork_or_not}")
  booter = if fork_or_not
    DroneForker.new(drones)
  else
    DroneThreader.new(drones)
  end

  STOP_PARENT_PROCESSING_SIGNALS.each do |signal|
    Signal.trap(signal) do
      swarm_control_logger.info("Stopping drones")
      booter.stop
    end
  end
  booter.start
  booter
end

#stop_drones(pid) ⇒ Object



209
210
211
# File 'lib/messagebus/swarm/controller.rb', line 209

def stop_drones(pid)
  Process.kill(STOP_PARENT_PROCESSING_SIGNALS[0], pid)
end