Class: Nginx::Server

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

Direct Known Subclasses

Proxy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Server.



45
46
47
48
49
50
# File 'lib/nginx/server.rb', line 45

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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



52
53
54
# File 'lib/nginx/server.rb', line 52

def dir
  @dir
end

Class Method Details

.from_file(file, **all) ⇒ Object



41
42
43
# File 'lib/nginx/server.rb', line 41

def self.from_file file, **all
  new (IO.read file), **all
end

Instance Method Details

#access_logObject



70
71
72
# File 'lib/nginx/server.rb', line 70

def access_log
  'access.log'
end

#error_logObject



66
67
68
# File 'lib/nginx/server.rb', line 66

def error_log
  'error.log'
end

#pidObject



74
75
76
# File 'lib/nginx/server.rb', line 74

def pid
  IO.read(pidfile).to_i
end

#pidfileObject



78
79
80
# File 'lib/nginx/server.rb', line 78

def pidfile
  'nginx.pid'
end

#startObject



54
55
56
57
58
59
# File 'lib/nginx/server.rb', line 54

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



61
62
63
# File 'lib/nginx/server.rb', line 61

def stop
  `kill #{@nginx_pid}`
end