class Procodile::Process

Constants

MUTEX

Attributes

command[RW]
config[R]
log_color[RW]
name[R]
options[RW]
removed[RW]

Public Class Methods

new(config, name, command, options = {}) click to toggle source
# File lib/procodile/process.rb, line 15
def initialize(config, name, command, options = {})
  @config = config
  @name = name
  @command = command
  @options = options
  @log_color = 0
  @instance_index = 0
end

Public Instance Methods

allocate_port_from() click to toggle source

Return the first port that ports should be allocated from for this process

# File lib/procodile/process.rb, line 116
def allocate_port_from
  @options['allocate_port_from']
end
correct_quantity?(quantity) click to toggle source

Is the given quantity suitable for this process?

# File lib/procodile/process.rb, line 184
def correct_quantity?(quantity)
  if self.restart_mode == 'start-term'
    quantity >= self.quantity
  else
    self.quantity == quantity
  end
end
create_instance(supervisor) click to toggle source

Create a new instance

# File lib/procodile/process.rb, line 158
def create_instance(supervisor)
  Instance.new(supervisor, self, get_instance_id)
end
default_log_file_name() click to toggle source

Return the defualt log file name

# File lib/procodile/process.rb, line 78
def default_log_file_name
  @options['log_file_name'] || "#{@name}.log"
end
default_log_path() click to toggle source

Return the log path for this process if no log path is provided and split logs is enabled

# File lib/procodile/process.rb, line 86
def default_log_path
  if @config.log_root
    File.join(@config.log_root, default_log_file_name)
  else
    nil
  end
end
environment_variables() click to toggle source

Return all environment variables for this process

# File lib/procodile/process.rb, line 37
def environment_variables
  global_variables = @config.environment_variables
  process_vars = @config.process_options[@name] ? @config.process_options[@name]['env'] || {} : {}
  process_local_vars = @config.local_process_options[@name] ? @config.local_process_options[@name]['env'] || {} : {}
  global_variables.merge(process_vars.merge(process_local_vars)).each_with_object({}) do |(key, value), hash|
    hash[key.to_s] = value.to_s
  end
end
generate_instances(supervisor, quantity = self.quantity) click to toggle source

Generate an array of new instances for this process (based on its quantity)

# File lib/procodile/process.rb, line 151
def generate_instances(supervisor, quantity = self.quantity)
  quantity.times.map { |i| create_instance(supervisor) }
end
get_instance_id() click to toggle source

Increase the instance index and return

# File lib/procodile/process.rb, line 27
def get_instance_id
  MUTEX.synchronize do
    @instance_index = 0 if @instance_index == 10000
    @instance_index += 1
  end
end
log_path() click to toggle source

Return the path where log output for this process should be written to. If none, output will be written to the supervisor log.

# File lib/procodile/process.rb, line 71
def log_path
  @options['log_path'] ? File.expand_path(@options['log_path'], @config.root) : default_log_path
end
max_respawns() click to toggle source

The maximum number of times this process can be respawned in the given period

# File lib/procodile/process.rb, line 56
def max_respawns
  @options['max_respawns'] ? @options['max_respawns'].to_i : 5
end
network_protocol() click to toggle source

Return the network protocol for this process

# File lib/procodile/process.rb, line 144
def network_protocol
  @options['network_protocol'] || 'tcp'
end
proxy?() click to toggle source

Is this process enabled for proxying?

# File lib/procodile/process.rb, line 123
def proxy?
  @options.has_key?('proxy_port')
end
proxy_address() click to toggle source

Return the port for the proxy to listen on for this process type

# File lib/procodile/process.rb, line 137
def proxy_address
  proxy? ? @options['proxy_address'] || '127.0.0.1' : nil
end
proxy_port() click to toggle source

Return the port for the proxy to listen on for this process type

# File lib/procodile/process.rb, line 130
def proxy_port
  proxy? ? @options['proxy_port'].to_i : nil
end
quantity() click to toggle source

How many instances of this process should be started

# File lib/procodile/process.rb, line 49
def quantity
  @options['quantity'] || 1
end
respawn_window() click to toggle source

The respawn window. One hour by default.

# File lib/procodile/process.rb, line 63
def respawn_window
  @options['respawn_window'] ? @options['respawn_window'].to_i : 3600
end
restart_mode() click to toggle source

Defines how this process should be restarted

start-term = start new instances and send term to children usr1 = just send a usr1 signal to the current instance usr2 = just send a usr2 signal to the current instance term-start = stop the old instances, when no longer running, start a new one

# File lib/procodile/process.rb, line 109
def restart_mode
  @options['restart_mode'] || 'term-start'
end
term_signal() click to toggle source

Return the signal to send to terminate the process

# File lib/procodile/process.rb, line 97
def term_signal
  @options['term_signal'] || 'TERM'
end
to_hash() click to toggle source

Return a hash

# File lib/procodile/process.rb, line 165
def to_hash
  {
    :name => self.name,
    :log_color => self.log_color,
    :quantity => self.quantity,
    :max_respawns => self.max_respawns,
    :respawn_window => self.respawn_window,
    :command => self.command,
    :restart_mode => self.restart_mode,
    :log_path => self.log_path,
    :removed => self.removed ? true : false,
    :proxy_port => proxy_port,
    :proxy_address => proxy_address
  }
end