Class: Guard::Nginx

Inherits:
Plugin
  • Object
show all
Defined in:
lib/guard/nginx.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Nginx

Returns a new instance of Nginx.



9
10
11
12
13
# File 'lib/guard/nginx.rb', line 9

def initialize(options)
  UI.info "hello path: #{Dir.pwd}"
  Dir.mkdir("#{tmp_path}/config") unless Dir.exist?("#{tmp_path}/config")
  super
end

Instance Method Details

#reloadObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/guard/nginx.rb', line 34

def reload
  UI.info 'reload'
  if pid
    generate_config

    UI.info "Sending HUP signal to Nginx (reloading #{pid})"
    ::Process.kill('HUP', pid)
    true
  end
end

#run_allObject



45
46
47
# File 'lib/guard/nginx.rb', line 45

def run_all
  reload
end

#run_on_change(_paths) ⇒ Object



49
50
51
# File 'lib/guard/nginx.rb', line 49

def run_on_change(_paths)
  true
end

#startObject



15
16
17
18
19
20
21
22
# File 'lib/guard/nginx.rb', line 15

def start
  # ensure config - create tmp file
  UI.info "Starting Nginx on port #{port}"
  generate_config

  IO.popen("#{executable} -c #{tmp_path}/config/nginx.conf", 'w+')
  UI.info 'Nginx started' if $CHILD_STATUS.success?
end

#stopObject



24
25
26
27
28
29
30
31
32
# File 'lib/guard/nginx.rb', line 24

def stop
  puts pid
  if pid
    UI.info "Sending TERM signal to Nginx (#{pid})"
    FileUtils.rm "#{tmp_path}/config/nginx.conf"
    ::Process.kill('TERM', pid)
    true
  end
end