Class: Nginxtra::Actions::Start

Inherits:
Object
  • Object
show all
Includes:
Nginxtra::Action
Defined in:
lib/nginxtra/actions/start.rb

Overview

The Nginxtra::Actions::Compile class encapsulates starting nginx with the specified configuration file. It also makes sure that nginx has been compiled with the correct options.

Instance Method Summary collapse

Methods included from Nginxtra::Action

#daemon, #initialize

Instance Method Details

#compileObject

Invoke nginx compilation, to ensure it is up to date.



24
25
26
# File 'lib/nginxtra/actions/start.rb', line 24

def compile
  Nginxtra::Actions::Compile.new(@thor, @config).compile
end

#no_need_to_startObject

Notify the user that nginx is already started.



41
42
43
# File 'lib/nginxtra/actions/start.rb', line 41

def no_need_to_start
  @thor.say "nginx is already started"
end

#save_config_filesObject

Save nginx config files to the proper config file path.



29
30
31
32
33
34
35
36
37
38
# File 'lib/nginxtra/actions/start.rb', line 29

def save_config_files
  files = @config.files
  raise Nginxtra::Error::MissingNginxConfig unless files.include? "nginx.conf"

  @thor.inside Nginxtra::Config.config_dir do
    files.each do |filename|
      @thor.create_file filename, @config.file_contents(filename), force: true
    end
  end
end

#should_start?Boolean

Determine if we should even bother starting. This returns true if the user forced, or if nginx is already running.

Returns:

  • (Boolean)


47
48
49
50
# File 'lib/nginxtra/actions/start.rb', line 47

def should_start?
  return true if force?
  !Nginxtra::Config.nginx_running?
end

#startObject

First, ensure nginx has been compiled, then make sure configuration is correct, and finally start nginx and note the start time.



12
13
14
15
16
17
18
19
20
21
# File 'lib/nginxtra/actions/start.rb', line 12

def start
  without_force do
    compile
  end

  return no_need_to_start unless should_start?
  save_config_files
  start_nginx
  update_last_start
end

#start_nginxObject

Start nginx as a daemon, unless –no-daemon is provided.



53
54
55
56
57
58
59
# File 'lib/nginxtra/actions/start.rb', line 53

def start_nginx
  if @thor.options["daemon"]
    daemon :start
  else
    exec [Nginxtra::Config.nginx_executable, "nginx"]
  end
end

#update_last_startObject

Update the last nginx start time.



62
63
64
# File 'lib/nginxtra/actions/start.rb', line 62

def update_last_start
  Nginxtra::Status[:last_start_time] = Time.now
end