Class: Nginxbrew::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/nginxbrew/config/base.rb

Constant Summary collapse

NGX_URL =
"http://nginx.org/download"
OPENRESTY_URL =
"http://openresty.org/download"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Configuration

Returns a new instance of Configuration.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/nginxbrew/config/base.rb', line 22

def initialize(opts={})
    @home_dir = opts[:home_dir]
    @dist_dir = opts[:dist_dir]
    @ngx_version = opts[:ngx_version]
    @is_openresty = opts[:is_openresty]
    @package_name = opts[:package_name]
    @dist_to = File.join(@dist_dir, @package_name)
    @nginx_log_dir = File.join(@home_dir, "logs", @package_name)
    @src = src_name(@ngx_version, @is_openresty)
    @tarball = "#{@src}.tar.gz"
    @url = "#{@is_openresty ? OPENRESTY_URL : NGX_URL}/#{@tarball}"
    @ngx_sbin_path = File.join(@dist_to, "bin/nginx")
    @builtfile = File.join(@dist_to, "built")
    @ngx_conf_path = File.join(@dist_to, "nginx.conf")
    @ngx_configure = {}
    @ngx_prefix = @dist_to
    @ngx_user = "nginx"
    @ngx_group = "nginx"
end

Instance Attribute Details

#builtfileObject (readonly)

Returns the value of attribute builtfile.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def builtfile
  @builtfile
end

#dist_dirObject (readonly)

Returns the value of attribute dist_dir.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def dist_dir
  @dist_dir
end

#dist_toObject (readonly)

Returns the value of attribute dist_to.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def dist_to
  @dist_to
end

#home_dirObject (readonly)

Returns the value of attribute home_dir.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def home_dir
  @home_dir
end

#is_openrestyObject (readonly)

Returns the value of attribute is_openresty.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def is_openresty
  @is_openresty
end

#nginx_log_dirObject (readonly)

Returns the value of attribute nginx_log_dir.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def nginx_log_dir
  @nginx_log_dir
end

#ngx_conf_pathObject

Returns the value of attribute ngx_conf_path.



17
18
19
# File 'lib/nginxbrew/config/base.rb', line 17

def ngx_conf_path
  @ngx_conf_path
end

#ngx_configureObject

Returns the value of attribute ngx_configure.



17
18
19
# File 'lib/nginxbrew/config/base.rb', line 17

def ngx_configure
  @ngx_configure
end

#ngx_groupObject

Returns the value of attribute ngx_group.



17
18
19
# File 'lib/nginxbrew/config/base.rb', line 17

def ngx_group
  @ngx_group
end

#ngx_prefixObject

Returns the value of attribute ngx_prefix.



17
18
19
# File 'lib/nginxbrew/config/base.rb', line 17

def ngx_prefix
  @ngx_prefix
end

#ngx_sbin_pathObject (readonly)

Returns the value of attribute ngx_sbin_path.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def ngx_sbin_path
  @ngx_sbin_path
end

#ngx_userObject

Returns the value of attribute ngx_user.



17
18
19
# File 'lib/nginxbrew/config/base.rb', line 17

def ngx_user
  @ngx_user
end

#ngx_versionObject (readonly)

Returns the value of attribute ngx_version.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def ngx_version
  @ngx_version
end

#package_nameObject (readonly)

Returns the value of attribute package_name.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def package_name
  @package_name
end

#srcObject (readonly)

Returns the value of attribute src.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def src
  @src
end

#tarballObject (readonly)

Returns the value of attribute tarball.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def tarball
  @tarball
end

#urlObject (readonly)

Returns the value of attribute url.



19
20
21
# File 'lib/nginxbrew/config/base.rb', line 19

def url
  @url
end

Instance Method Details

#configure_commandObject



42
43
44
45
46
47
48
# File 'lib/nginxbrew/config/base.rb', line 42

def configure_command
    dest = ["./configure"]
    configure_options.inject(dest) do |memo, opt|
        memo << "#{opt[0]}" + (opt[1].nil? ? "" : "=#{opt[1]}")
        memo
    end.join(" ")
end

#configure_optionsObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/nginxbrew/config/base.rb', line 50

def configure_options
    cmd =<<-EOF
        --user=#{@ngx_user} \
        --group=#{@ngx_group} \
        --prefix=#{@ngx_prefix} \
        --sbin-path=#{@ngx_sbin_path} \
        --conf-path=#{@ngx_conf_path} \
        --error-log-path=#{@nginx_log_dir}/error.log \
        --http-log-path=#{@nginx_log_dir}/access.log \
        --http-client-body-temp-path=#{@home_dir}/tmp/client_body \
        --http-proxy-temp-path=#{@home_dir}/tmp/proxy \
        --pid-path=#{@home_dir}/run/nginx.pid
    EOF
    dest = cmd.split(" ").inject({}) do |memo, opt|
        kv = opt.split("=")
        memo[kv[0]] = (kv.size == 2) ? kv[1] : nil
        memo
    end
    dest.merge!(@ngx_configure) if @ngx_configure
    dest
end