Class: ReverseProxy::Proxy::Nginx
- Inherits:
-
Generic
- Object
- Generic
- ReverseProxy::Proxy::Nginx
show all
- Defined in:
- lib/reverse_proxy/proxy/nginx.rb
Instance Attribute Summary collapse
Attributes inherited from Generic
#application, #binds, #config, #lock, #pid, #server
Instance Method Summary
collapse
Methods inherited from Generic
#id, #initialize, #log
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class ReverseProxy::Proxy::Generic
Instance Attribute Details
#nginx_executable ⇒ Object
Returns the value of attribute nginx_executable.
11
12
13
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 11
def nginx_executable
@nginx_executable
end
|
#stage ⇒ Object
Returns the value of attribute stage.
10
11
12
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 10
def stage
@stage
end
|
Instance Method Details
#basic_command ⇒ Object
63
64
65
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 63
def basic_command
"#{nginx_executable} -p #{config.dir} -c #{config.file.relative_path_from config.dir}"
end
|
#hijack {|Bind.new(application.socket)| ... } ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 48
def hijack
@binds += server.binds.select{|x| x.match(/^tcp:/)}
server.binds = server.binds.reject{|x| x.match(/^tcp:/) }
@binds << server.default_bind if @binds.empty?
@binds = @binds.map{|b|Bind.new(b)}
yield Bind.new(application.socket)
log "Nginx listenens at #{@binds.map{|b|b.tcp.to_nginx}.join(", ")}"
end
|
#listen ⇒ Object
57
58
59
60
61
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 57
def listen
@binds.collect do |bind|
bind.tcp.to_nginx
end
end
|
#prepare ⇒ Object
13
14
15
16
17
18
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 13
def prepare
Bind::Formatter.add :upstream, ->(data) { "#{data.scheme}:#{data.data}"}
Bind::Formatter.add :nginx, ->(data) { "#{data.data}"}
@stage = :initialized
@nginx_executable = "nginx"
end
|
#reload ⇒ Object
40
41
42
43
44
45
46
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 40
def reload
return unless config.updated?
start unless started?
log "Reload Nginx"
config.write
`#{reload_command}`
end
|
#reload_command ⇒ Object
66
67
68
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 66
def reload_command
"#{basic_command} -s reload"
end
|
#restart ⇒ Object
35
36
37
38
39
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 35
def restart
log "Restart NGinx"
stop
start
end
|
#start ⇒ Object
20
21
22
23
24
25
26
27
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 20
def start
sleep(Random.rand*0.1)
return if config.written?
config.write
log "Start Nginx, #{start_command}"
at_exit{ log "Stop Nginx"; stop }
Thread.new { `#{start_command}` }
end
|
#start_command ⇒ Object
72
73
74
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 72
def start_command
"#{basic_command}"
end
|
#stop ⇒ Object
29
30
31
32
33
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 29
def stop
return unless started?
`#{stop_command}`
config.clean
end
|
#stop_command ⇒ Object
69
70
71
|
# File 'lib/reverse_proxy/proxy/nginx.rb', line 69
def stop_command
"#{basic_command} -s quit"
end
|