Class: Spawngebob::Runner

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/spawngebob/runner.rb

Constant Summary

Constants included from Constants

Constants::BASE_CONFIG_PATH, Constants::CONFIG_FILE, Constants::NGINX_CONF, Constants::NGINX_CONFD_PATH, Constants::NGINX_CONF_PATH, Constants::NGINX_DEFAULTS, Constants::NGINX_DIRS, Constants::NGINX_HTTP_LOCATION_TEMPLATE, Constants::NGINX_PATH, Constants::NGINX_PID, Constants::NGINX_SERVER_TEMPLATE, Constants::NGINX_SSL_LOCATION_TEMPLATE, Constants::NGINX_SSL_SERVER_TEMPLATE, Constants::NGINX_UPSTREAM_TEMPLATE, Constants::SCRIPT_DIR

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



43
44
45
46
47
48
49
# File 'lib/spawngebob/runner.rb', line 43

def initialize(options)
  @options = options
  @args = ARGV.dup
  @command = ARGV.shift

  self.run(options)
end

Class Method Details

.boot(options) ⇒ Object



7
8
9
10
11
12
# File 'lib/spawngebob/runner.rb', line 7

def self.boot(options)
  Spawngebob::Constants.const_set('NGINX_BIN', `which nginx 2>/dev/null`.strip)
  Spawngebob::Constants.const_set('KILL_BIN', `which kill 2>/dev/null`.strip)

  self.new(options) if has_requirements?
end

.has_requirements?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/spawngebob/runner.rb', line 14

def self.has_requirements?
  # check if nginx is installed
  if !Constants.const_defined?("NGINX_BIN")
    Utils.error "Nginx is not installed!"
  end

  # check if nginx.conf exist
  nginx_conf = File.join(NGINX_CONF_PATH, NGINX_CONF)
  if !File.exists?(nginx_conf)
    Utils.error "#{NGINX_CONF} not found in #{NGINX_CONF_PATH}"
  end

  if File.zero?(nginx_conf)
    Utils.error "#{NGINX_CONF} is empty."
  end

  # check if apps.yml exists
  apps_config = File.join(BASE_CONFIG_PATH, CONFIG_FILE)
  if !File.exists?(apps_config)
    Utils.error "#{CONFIG_FILE} not found in #{BASE_CONFIG_PATH}"
  end

  if File.zero?(apps_config)
    Utils.error "#{CONFIG_FILE} is empty."
  end

  true
end

Instance Method Details

#run(options) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/spawngebob/runner.rb', line 51

def run(options)
  case @args.shift
  when 'start'
    system "#{SCRIPT_DIR} start"
  when 'stop'
    system "#{SCRIPT_DIR} stop"
  when 'restart'
    system "#{SCRIPT_DIR} restart"
  when 'check'
    system "#{SCRIPT_DIR} status"
  when 'reload'
    system "#{SCRIPT_DIR} reload"
  when 'configure'
    Compilers::Nginx.new.prepare
  else
    puts "Unknown command! Available commands: {start|stop|restart|check|reload|configure}"
  end
end