This repository has been archived by the owner on Jan 24, 2020. It is now read-only.
/
nginx.rb
70 lines (59 loc) · 1.39 KB
/
nginx.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
require "tmpdir"
require "rubygems"
require "language_pack"
require "language_pack/base"
class LanguagePack::Nginx < LanguagePack::Base
OPENRESTY_STABLE_VERSION = "1.0.15.10"
def self.use?
File.exist?("nginx.conf")
end
def name
"OpenResty"
end
def default_addons
['shared-database:5mb']
end
def default_config_vars
{
"LANG" => "en_US.UTF-8",
"PATH" => default_path
}
end
def default_process_types
{
"web" => 'ruby run.rb'
}
end
def compile
download_openresty
FileUtils.mkdir_p "logs"
File.open("run.rb", "w") do |file|
file.puts <<-APPLICATION
#!/usr/bin/env ruby
conf_file = File.read("nginx.conf")
conf_file.gsub!(/\\$ENV_(\\w+)/) do
ENV[$1]
end
File.open(".env_nginx.conf","w") do |file|
file.puts conf_file
end
`nginx -c \\`pwd\\`/.env_nginx.conf -g "daemon off;"`
APPLICATION
end
end
private
def download_openresty
openresty_path = "openresty"
topic "Installing OpenResty version #{OPENRESTY_STABLE_VERSION}"
unless cache_load(openresty_path)
puts "Downloading OpenResty binary"
Dir.chdir(build_path) do
run("curl #{VENDOR_URL}/openresty_nginx-#{OPENRESTY_STABLE_VERSION}.tar.gz -s -o - | tar zxf -")
cache_store(openresty_path)
end
end
end
def default_path
"bin:/bin:/usr/local/bin:/usr/bin:/bin:/app/openresty/nginx/sbin"
end
end