Class: OptimusPrime::Cannon

Inherits:
Object
  • Object
show all
Defined in:
lib/optimus_prime.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Cannon

Returns a new instance of Cannon.



64
65
66
67
# File 'lib/optimus_prime.rb', line 64

def initialize(options={})
  @options = options
  @op_port = $port
end

Instance Attribute Details

#op_portObject (readonly)

Returns the value of attribute op_port.



62
63
64
# File 'lib/optimus_prime.rb', line 62

def op_port
  @op_port
end

Class Method Details

.fire!(port, options = {}) ⇒ Object



57
58
59
60
# File 'lib/optimus_prime.rb', line 57

def self.fire!(port, options={})
  $port = port
  self.new(options).start_server
end

Instance Method Details

#current_pathObject



99
# File 'lib/optimus_prime.rb', line 99

def current_path; `pwd`.chomp; end

#optimus_prime_pathObject



95
96
97
# File 'lib/optimus_prime.rb', line 95

def optimus_prime_path
  File.expand_path('../', __dir__)
end

#start_serverObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# 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