nginxbrew 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b2f5664ba79c8666cfbbe84bc5439cc5927479fd
4
+ data.tar.gz: 5a6ecb595b467736b8bdc30950e1ec5516dbb36d
5
+ SHA512:
6
+ metadata.gz: 053144c4e831fa606289cbd9482c136d15d69ae8de4c4b803f2738bb41c411cb6561b81bb428b4c8ba0c8988aba223ae834267b2e386bc0de3e7c6e2a4b525c8
7
+ data.tar.gz: e1927c314e0373385570ba85d582e458990e6b7c0f65337a4fd3d87c532289e997226c7ae94eb805f2c8fe4caf74fad4e2d979598cb510f8ebdadf7897c35279
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nginxbrew.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 takumakanari@nerima_fedora
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # Nginxbrew
2
+
3
+ Nginxbrew is a tool to install multi-version of nginx/nginxopenresty into your machine.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'nginxbrew'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install nginxbrew
20
+
21
+ ## Quick start Guide
22
+
23
+ You can install new nginx build by specifying the version as follows
24
+
25
+ $ nginxbrew install 1.7.6
26
+
27
+ "1.7.6" is the version of nginx.
28
+
29
+ If you need to install openresty,
30
+
31
+ $ nginxbrew install openresty-1.7.0.1
32
+
33
+
34
+ After the command execution, ~/nginxbrew will be created into your machine and nginx is installed as follows
35
+
36
+ ~/nginxbrew/bin/nginx -- current sbin
37
+ ~/nginxbrew/logs/<version> -- logfiles
38
+ ~/nginxbrew/versions/ngx-<version>/nginx.conf -- root config file
39
+ ~/nginxbrew/versions/ngx-<version> -- configs, sbin|pid of each version
40
+ ~/nginxbrew/versions/ngx-<version>/user/share -- $prefix directory of each version
41
+
42
+ Then you can start up nginx by command which same as original nginx as follows
43
+
44
+ $ ~/nginxbrew/bin/nginx
45
+ $ ~/nginxbrew/bin/nginx -s reload
46
+
47
+
48
+ If you want to use this nginx for default, add new line to .bashrc like as follows.
49
+
50
+ $ echo "export PATH=$PATH:~/nginxbrew/bin" >> ~/.bashrc
51
+ $ source ~/.bashrc
52
+
53
+ Then there are 2 nginxes are activated in your machine, you can confirm it by the command
54
+
55
+ $ nginxbrew list
56
+
57
+ You can switch to other version of nginx as follows
58
+
59
+ $ nginxbrew use <version>
60
+
61
+ If you want to use openresty-1.7.0.1 from other version of nginx, you can do this as follows,
62
+
63
+ $ nginxbrew use openresty-1.7.0.1
64
+
65
+ ## Customize configuration
66
+
67
+ You can customize Nginxbrew behavior by changing ENV.
68
+
69
+ NGINXBREW_HOME # change nginxbrew root directory from ~/nginxbrew to somewhere
70
+ NGINXBREW_USER # linux user for nginx
71
+ NGINXBREW_GROUP # linux group for nginx
72
+
73
+ You can change directory/options for nginx if you write configfile for nginxbrew.
74
+
75
+ The following my_config.rb is configuration to share $prefix of nginx & nginx.conf troughout all builds of nginx.
76
+
77
+ ```ruby
78
+ Nginxbrew.configure do |config|
79
+ config.ngx_prefix = File.join(config.home_dir, "share")
80
+ config.ngx_conf_path = File.join(config.home_dir, "share/nginx.conf")
81
+ config.ngx_configure =<<-EOF
82
+ # --- options for ./configure, starts from ./configure ...
83
+ EOF
84
+ end
85
+ ```
86
+
87
+
88
+ after that, specify path to config file which you wrote as follows
89
+
90
+ $ export NGINXBREW_CONFIG=/path/to/my_config.rb
91
+
92
+
93
+ then nginxbrew starts to using this configuration.
94
+
95
+ ## TODO
96
+
97
+ - write tests completely
98
+ - share nginx.conf for every versions
99
+ - list up available nginx versions like as follows
100
+
101
+ $ nginxbrew nginxes
102
+
103
+ - installable without specifying minor version of nginx like as follows
104
+
105
+ $ nginxbrew install 1.7 # head of 1.7 will be installed
106
+
107
+ ## Contributing
108
+
109
+ 1. Fork it ( https://github.com/[my-github-username]/nginxbrew/fork )
110
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
111
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
112
+ 4. Push to the branch (`git push origin my-new-feature`)
113
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/nginxbrew ADDED
@@ -0,0 +1,57 @@
1
+ #!/usr/bin/env ruby
2
+ require "nginxbrew"
3
+
4
+ usage =<<-EOF
5
+ Usage: nginxbrew [-v] [-h] command [<args>]
6
+
7
+ -v, --version Print the version and exit.
8
+ -h, --help Print this help.
9
+
10
+ Available subcommands:
11
+ install <version> Install nginx with specified version.
12
+ use <version> Switch nginx into specified version.
13
+ list Show list of installed nginx versions
14
+
15
+ Optional environments:
16
+ NGINXBREW_HOME Path to nginxbrew (will be) installed, ~/nginxbrew is default.
17
+ NGINXBREW_USER User for nginx (enabled in `install`), "nginx" is default.
18
+ NGINXBREW_GROUP Group for nginx (enable in `install`), "nginx" is default.
19
+ NGINXBREW_DEBUG if 1, use DEBUG level for logging.
20
+ NGINXBREW_CONFIG /path/to/configfile written in ruby DSL for build nginx.
21
+ EOF
22
+
23
+
24
+ if ARGV.include?("-h") || ARGV.include?("--help") || ARGV.size == 0
25
+ puts usage
26
+ exit 0
27
+ end
28
+
29
+ if ARGV.include?("-v") || ARGV.include?("--version")
30
+ require "nginxbrew/version"
31
+ puts "nginxbrew #{Nginxbrew::VERSION}"
32
+ exit 0
33
+ end
34
+
35
+
36
+ ENV["HOME"] ||= File.dirname(__FILE__) # recover $HOME if empty
37
+
38
+
39
+ begin
40
+ command = ARGV.shift
41
+ case command
42
+ when "install", "use"
43
+ version = ARGV.shift
44
+ raise Exception.new("version is required!") unless version
45
+ Nginxbrew.run(:"#{command}", envs={ "VERSION" => version })
46
+ when "list"
47
+ Nginxbrew.run(:list)
48
+ else
49
+ raise Exception.new("Unknown command '#{command}'")
50
+ end
51
+ rescue SystemExit => e # from rake.abort
52
+ exit 255
53
+ rescue Exception => e
54
+ $stderr.puts "ERROR: #{e.message}"
55
+ exit 255
56
+ end
57
+
@@ -0,0 +1,61 @@
1
+ module Nginxbrew
2
+
3
+ class << self
4
+ attr_accessor :config
5
+ end
6
+
7
+ def self.configure
8
+ yield config
9
+ end
10
+
11
+ class Configuration
12
+ NGX_URL = "http://nginx.org/download"
13
+ OPENRESTY_URL = "http://openresty.org/download"
14
+
15
+ attr_accessor :ngx_configure, :ngx_conf_path, :ngx_prefix
16
+ attr_reader :ngx_user, :ngx_group, :nginx_log_dir,
17
+ :builtfile, :dist_to, :tarball, :src, :url, :home_dir, :ngx_sbin_path
18
+
19
+ def initialize(opts={})
20
+ @home_dir = opts[:home_dir]
21
+ @dist_dir = opts[:dist_dir]
22
+ @ngx_version = opts[:ngx_version]
23
+ @is_openresty = opts[:is_openresty]
24
+ @ngx_user = opts[:ngx_user]
25
+ @ngx_group = opts[:ngx_group]
26
+ @dist_to = File.join(@dist_dir, "ngx-#{@ngx_version}")
27
+ @nginx_log_dir = File.join(@home_dir, "logs", @ngx_version)
28
+ @src = opts[:src]
29
+ @tarball = "#{@src}.tar.gz"
30
+ @url = "#{@is_openresty ? OPENRESTY_URL : NGX_URL}/#{@tarball}"
31
+ @ngx_sbin_path = File.join(@dist_to, "bin/nginx")
32
+ @builtfile = File.join(@dist_to, "built")
33
+ @ngx_configure = nil
34
+ @ngx_conf_path = File.join(@dist_to, "nginx.conf")
35
+ @ngx_prefix = File.join(@dist_to, "user/share")
36
+ end
37
+
38
+ def configure_command
39
+ return @ngx_configure if @ngx_configure
40
+ cmd =<<-EOF
41
+ ./configure \
42
+ --user=#{@ngx_user} \
43
+ --group=#{@ngx_group} \
44
+ --prefix=#{@ngx_prefix} \
45
+ --sbin-path=#{@ngx_sbin_path} \
46
+ --conf-path=#{@ngx_conf_path} \
47
+ --error-log-path=#{@nginx_log_dir}/error.log \
48
+ --http-log-path=#{@nginx_log_dir}/access.log \
49
+ --http-client-body-temp-path=#{@dist_to}/tmp/client_body \
50
+ --http-proxy-temp-path=#{@dist_to}/tmp/proxy \
51
+ --http-fastcgi-temp-path=#{@dist_to}/tmp/fastcgi \
52
+ --http-uwsgi-temp-path=#{@dist_to}/tmp/uwsgi \
53
+ --pid-path=#{@dist_to}/run/nginx.pid
54
+ EOF
55
+ cmd.split(" ").join(" ")
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+
@@ -0,0 +1,5 @@
1
+ Nginxbrew.configure do |config|
2
+ # config.ngx_prefix = File.join(config.home_dir, "share")
3
+ # config.ngx_conf_path = File.join(config.home_dir, "share/nginx.conf")
4
+ end
5
+
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env ruby
2
+ require "logger"
3
+ require "pathname"
4
+ require "fileutils"
5
+
6
+
7
+ $logger = Logger.new(STDOUT)
8
+ $logger.level = (ENV["NGINXBREW_DEBUG"].to_i == 1) ? Logger::DEBUG : Logger::ERROR
9
+
10
+
11
+ def package_name_from(version)
12
+ "ngx-#{version}"
13
+ end
14
+
15
+
16
+ def version_from_package(name)
17
+ prefix = "ngx-"
18
+ idx = name.index(prefix)
19
+ abort "Invalid name #{name}" if idx < 0
20
+ name.slice(prefix.size, name.size - 1)
21
+ end
22
+
23
+
24
+ def installed_packages(root)
25
+ Pathname.new(root).children.select{|e| e.directory? }.inject({}) do |memo, d|
26
+ version = version_from_package(File.basename(d))
27
+ memo[version] = d
28
+ memo
29
+ end
30
+ end
31
+
32
+
33
+ def sh_exc(cmd, *opts)
34
+ line = cmd
35
+ line += " " + opts.join(" ")
36
+ $logger.debug("exec: #{line}")
37
+ sh line
38
+ end
39
+
40
+
41
+ OPENRESTY = "openresty-"
42
+
43
+ HOME_DIR = ENV["NGINXBREW_HOME"] || File.join(ENV["HOME"], "nginxbrew")
44
+ VERSION = ENV["VERSION"]
45
+ NGINX_USER = ENV["NGINXBREW_USER"] || "nginx"
46
+ NGINX_GROUP = ENV["NGINXBREW_GROUP"] || "nginx"
47
+
48
+ CONFIG_FILE = ENV["NGINXBREW_CONFIG"]
49
+ if CONFIG_FILE && !FileTest.file?(CONFIG_FILE)
50
+ raise Exception.new("Specified configuration file #{CONFIG_FILE} is not found")
51
+ end
52
+
53
+
54
+ SOURCE_DIR = "#{HOME_DIR}/src"
55
+ DIST_DIR = "#{HOME_DIR}/versions"
56
+ BIN_DIR = "#{HOME_DIR}/bin"
57
+ NGINX_CURRENT_BIN_NAME = "#{BIN_DIR}/nginx"
58
+
59
+
60
+ [HOME_DIR, SOURCE_DIR, BIN_DIR, DIST_DIR].each do |dir|
61
+ directory dir
62
+ end
63
+
64
+
65
+ if VERSION
66
+ require "nginxbrew/config/base"
67
+
68
+ is_openresty = VERSION.index(OPENRESTY) == 0
69
+ version_ = VERSION
70
+ version_ = version_.slice(OPENRESTY.size, version_.size - 1) if is_openresty
71
+
72
+ Nginxbrew.config = Nginxbrew::Configuration.new(
73
+ :home_dir => HOME_DIR,
74
+ :dist_dir => DIST_DIR,
75
+ :ngx_version => VERSION,
76
+ :is_openresty => is_openresty,
77
+ :src => is_openresty ? "ngx_openresty-#{version_}" : "nginx-#{version_}",
78
+ :ngx_user => NGINX_USER,
79
+ :ngx_group => NGINX_GROUP
80
+ )
81
+
82
+ require "nginxbrew/config/default"
83
+ require CONFIG_FILE if CONFIG_FILE
84
+ $logger.debug(Nginxbrew.config.inspect)
85
+
86
+ config = Nginxbrew.config
87
+
88
+ directory config.dist_to
89
+
90
+ TARBALL_DOWNLOADED_TO = File.join(SOURCE_DIR, config.tarball)
91
+ SOURCE_EXTRACTED_TO = File.join(SOURCE_DIR, config.src)
92
+
93
+ desc "get nginx tarball version:#{VERSION}"
94
+ file TARBALL_DOWNLOADED_TO => SOURCE_DIR do
95
+ Dir.chdir(SOURCE_DIR) do
96
+ sh_exc("wget", config.url)
97
+ end
98
+ end
99
+
100
+
101
+ desc "extract tarball, #{SOURCE_EXTRACTED_TO} will be created"
102
+ directory SOURCE_EXTRACTED_TO => TARBALL_DOWNLOADED_TO do
103
+ Dir.chdir(SOURCE_DIR) do
104
+ sh_exc("tar", "zxf", TARBALL_DOWNLOADED_TO)
105
+ end
106
+ end
107
+
108
+
109
+ desc "do build/install, after that create file:built to keep status of build"
110
+ file config.builtfile => [SOURCE_EXTRACTED_TO, config.dist_to] do
111
+ Dir.chdir(SOURCE_EXTRACTED_TO) do
112
+ [config.configure_command, "gmake", "gmake install"].each do |cmd|
113
+ sh_exc(cmd)
114
+ end
115
+ end
116
+ sh_exc("touch", config.builtfile)
117
+ end
118
+
119
+
120
+ desc "install nginx"
121
+ task :install => [config.builtfile] do
122
+ if installed_packages(DIST_DIR).size == 1
123
+ $logger.debug("this is first install, use this version as default")
124
+ Rake::Task[:use].invoke
125
+ end
126
+ end
127
+
128
+
129
+ desc "switch nginx version"
130
+ task :use => [BIN_DIR, :chown] do
131
+ abort "version:#{VERSION} is not installed!" unless FileTest.directory?(config.dist_to)
132
+ FileUtils.ln_s(config.ngx_sbin_path, NGINX_CURRENT_BIN_NAME, :force => true)
133
+ $stdout.puts("#{VERSION} default to use")
134
+ $stdout.puts("bin: #{config.ngx_sbin_path}")
135
+ end
136
+ end
137
+
138
+
139
+ desc "chown to sudo user or normal user"
140
+ task :chown do
141
+ sudo_user = ENV["SUDO_USER"]
142
+ user = ENV["USER"]
143
+ if sudo_user && sudo_user != user
144
+ [HOME_DIR, DIST_DIR, BIN_DIR].each do |dir|
145
+ sh_exc("chown", "-R", sudo_user, dir)
146
+ end
147
+ end
148
+ end
149
+
150
+
151
+ desc "list installed nginx"
152
+ task :list => DIST_DIR do
153
+ used_version = nil
154
+ if FileTest.file?(NGINX_CURRENT_BIN_NAME)
155
+ target_path = File.readlink(NGINX_CURRENT_BIN_NAME)
156
+ path_list = target_path.split("/")
157
+ 2.times {|i| path_list.pop } # remove bin/nginx
158
+ used_version = version_from_package(path_list.pop)
159
+ end
160
+ installed_packages(DIST_DIR).keys.sort.each do |v|
161
+ prefix = (v == used_version) ? "*" : " "
162
+ $stdout.puts("#{prefix} #{v}")
163
+ end
164
+ end
165
+
@@ -0,0 +1,3 @@
1
+ module Nginxbrew
2
+ VERSION = "0.0.3"
3
+ end
data/lib/nginxbrew.rb ADDED
@@ -0,0 +1,14 @@
1
+ require "nginxbrew/version"
2
+ require "rake"
3
+
4
+ module Nginxbrew
5
+
6
+ def run(command, env={})
7
+ env.each{|k, v| ENV[k] = v }
8
+ require "nginxbrew/tasks"
9
+ Rake::Task[command].invoke
10
+ end
11
+
12
+ module_function :run
13
+ end
14
+
data/nginxbrew.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'nginxbrew/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "nginxbrew"
8
+ spec.version = Nginxbrew::VERSION
9
+ spec.authors = ["takumakanari"]
10
+ spec.email = ["chemtrails.t@gmail.com"]
11
+ spec.summary = "Multi installation for nginx."
12
+ spec.description = "Nginxbrew is a tool for install multi-version of nginx/nginxopenresty into your local environment."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables << "nginxbrew"
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nginxbrew
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - takumakanari
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Nginxbrew is a tool for install multi-version of nginx/nginxopenresty
42
+ into your local environment.
43
+ email:
44
+ - chemtrails.t@gmail.com
45
+ executables:
46
+ - nginxbrew
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/nginxbrew
56
+ - lib/nginxbrew.rb
57
+ - lib/nginxbrew/config/base.rb
58
+ - lib/nginxbrew/config/default.rb
59
+ - lib/nginxbrew/tasks.rb
60
+ - lib/nginxbrew/version.rb
61
+ - nginxbrew.gemspec
62
+ homepage: ''
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.4.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Multi installation for nginx.
86
+ test_files: []