Class: Nginx::Server

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

Instance Method Summary collapse

Constructor Details

#initialize(template, dir: "/tmp/nginx.#{Process.pid}.#{SecureRandom.uuid}") ⇒ Server

Returns a new instance of Server.



8
9
10
11
12
# File 'lib/nginx/server.rb', line 8

def initialize template,
  dir: "/tmp/nginx.#{Process.pid}.#{SecureRandom.uuid}"
  @dir = Pathname dir; @dir.mkpath
  create_config template
end

Instance Method Details

#access_logObject



29
30
31
# File 'lib/nginx/server.rb', line 29

def access_log
  'access.log'
end

#error_logObject



25
26
27
# File 'lib/nginx/server.rb', line 25

def error_log
  'error.log'
end

#pidObject



33
34
35
# File 'lib/nginx/server.rb', line 33

def pid
  'nginx.pid'
end

#startObject



14
15
16
17
18
19
# File 'lib/nginx/server.rb', line 14

def start
  @nginx_pid = suppress_output do
    spawn "nginx -c nginx.conf -p #{@dir} -g 'daemon off;'"
  end; at_exit { stop }
  @nginx_pid
end

#stopObject



21
22
23
# File 'lib/nginx/server.rb', line 21

def stop
  `kill #{@nginx_pid}`
end