class OptimusPrime::Cannon

Attributes

op_port[R]

Public Class Methods

fire!(port, options={}) click to toggle source
# File lib/optimus_prime.rb, line 57
def self.fire!(port, options={})
  $port = port
  self.new(options).start_server
end
new(options={}) click to toggle source
# File lib/optimus_prime.rb, line 64
def initialize(options={})
  @options = options
  @op_port = $port
end

Public Instance Methods

current_path() click to toggle source
# File lib/optimus_prime.rb, line 99
def current_path; `pwd`.chomp; end
optimus_prime_path() click to toggle source
# File lib/optimus_prime.rb, line 95
def optimus_prime_path
  File.expand_path('../', __dir__)
end
start_server() click to toggle source
# File lib/optimus_prime.rb, line 69
def start_server

  return system("echo '\nOptimus is already priming :)\n\n'") if File.exist?("#{current_path}/tmp/pids/optimus_prime.pid")

  unless File.directory?("#{current_path}/tmp/pids")
    system("echo 'Creating tmp/pid' && mkdir -p #{current_path}/tmp/pids")
  end

  unless File.exist?("#{current_path}/tmp/pids/optimus_prime.pid")
    if not `lsof -i:#{op_port}`.empty?
      return system("echo '\n\n------> Ooops looks like this port is already in use\n-------> Please kill it!!!\n'")
    end

    system("echo '\nStarting Optimus Prime\n'")
    if @options[:multi_threaded]
      puts system("thin start -c #{optimus_prime_path} -p #{op_port} -P #{current_path}/tmp/pids/optimus_prime.pid -l #{current_path}/optimus_prime.log --threaded -p 7011 --threadpool-size #{@options[:thread_pool] || 16} -d")
    else
      puts system("thin start -c #{optimus_prime_path} -p #{op_port} -P #{current_path}/tmp/pids/optimus_prime.pid -l #{current_path}/optimus_prime.log -D -d")
    end

    while :starting_server
      sleep(2) and break if File.exist?("#{current_path}/tmp/pids/optimus_prime.pid")
    end
  end
end