unicorn-standby 0.1.0

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: db8801e81300cbc0c2994eed089b1dacbfa8b26e
4
+ data.tar.gz: 82c98aa28c3baec1a459fddb2b8d5e0ee6fa0100
5
+ SHA512:
6
+ metadata.gz: 21a26b243dfc35a48fc690c9c7445d370aa8a523b8591752a4d051b740b2309460306bb87b6b8e436d92bc32384551c5833f1ac6b7302ffb71db15297aa41111
7
+ data.tar.gz: 410784567cc5571ce7496ab7741dcf01208b5b13d06e5738c5783422628e14c2c279019d5baebb1d6d41bfe9ec7adf78683827047165eb5c53baea99d85c0653
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in unicorn-standby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tsukasa OISHI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Unicorn::Standby
2
+
3
+ Unicorn Standby to standby to reach the request.
4
+ If you use many rack applications (such as microservices) in development environments, Unicorn Standby saves memory consumption of your computer.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ group :development do
12
+ gem 'unicorn-standby'
13
+ end
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ ## Usage
21
+
22
+ Use ```unicorn-stanby``` command insted of ```unicorn```.
23
+
24
+ ```
25
+ bundle exec unicorn-standby -c config/unicorn.rb -D
26
+ ```
27
+
28
+ ## License
29
+
30
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
31
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "unicorn/standby"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'unicorn/standby'
3
+ load Gem.bin_path('unicorn', 'unicorn')
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'unicorn/standby'
3
+ load Gem.bin_path('unicorn', 'unicorn_rails')
@@ -0,0 +1,5 @@
1
+ module Unicorn
2
+ module Standby
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,100 @@
1
+ require "unicorn/standby/version"
2
+ require 'unicorn'
3
+
4
+ module Unicorn
5
+ module Standby
6
+ EXIT_SIGS = [:QUIT, :TERM, :INT]
7
+ private_constant :EXIT_SIGS
8
+
9
+ def start
10
+ @_wakeup ? super : self
11
+ end
12
+
13
+ def join
14
+ @_wakeup ? super : standby
15
+ end
16
+
17
+ private
18
+
19
+ def inherit_listeners!
20
+ super unless @_wakeup
21
+ end
22
+
23
+ def bind_new_listeners!
24
+ super unless @_wakeup
25
+ end
26
+
27
+ def standby
28
+ self.pid = config[:pid]
29
+
30
+ proc_name 'master (standby)'
31
+
32
+ kill_old_master
33
+ ready_standby_trap
34
+
35
+ inherit_listeners!
36
+ bind_new_listeners!
37
+
38
+ logger.info "standby ready"
39
+ notice_to_grandparent
40
+
41
+ IO.select(self.class.const_get(:LISTENERS))
42
+
43
+ turn_on
44
+ end
45
+
46
+ def kill_old_master
47
+ old_pid = "#{config[:pid]}.oldbin"
48
+ if File.exists?(old_pid) && pid != old_pid
49
+ sig = :QUIT
50
+ logger.info "Sending #{sig} signal to old unicorn master..."
51
+ Process.kill(sig, File.read(old_pid).to_i)
52
+ end
53
+ rescue Errno::ENOENT, Errno::ESRCH
54
+ end
55
+
56
+ def ready_standby_trap
57
+ (unicorn_queue_sigs - EXIT_SIGS).each do |signal|
58
+ Signal.trap(signal) {}
59
+ end
60
+
61
+ EXIT_SIGS.each do |signal|
62
+ Signal.trap(signal) { standby_shutdown }
63
+ end
64
+ end
65
+
66
+ def notice_to_grandparent
67
+ return unless @ready_pipe
68
+
69
+ begin
70
+ @ready_pipe.syswrite($$.to_s)
71
+ rescue => e
72
+ logger.warn("grandparent died too soon?: #{e.message} (#{e.class})")
73
+ end
74
+ @ready_pipe = @ready_pipe.close rescue nil
75
+ end
76
+
77
+ def turn_on
78
+ logger.info "standby master wake up..."
79
+ @_wakeup = true
80
+ start.join
81
+ end
82
+
83
+ def standby_shutdown
84
+ unlink_pid_safe(pid) if pid
85
+ exit 0
86
+ end
87
+
88
+ def unicorn_queue_sigs
89
+ if self.class.const_defined?(:QUEUE_SIGS)
90
+ self.class.const_get(:QUEUE_SIGS)
91
+ else
92
+ @queue_sigs || []
93
+ end
94
+ end
95
+ end
96
+ end
97
+
98
+ unless Unicorn::HttpServer.ancestors.include?(Unicorn::Standby)
99
+ Unicorn::HttpServer.__send__(:prepend , Unicorn::Standby)
100
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'unicorn/standby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "unicorn-standby"
8
+ spec.version = Unicorn::Standby::VERSION
9
+ spec.authors = ["Tsukasa OISHI"]
10
+ spec.email = ["tsukasa.oishi@gmail.com"]
11
+
12
+ spec.summary = %q{Unicorn Standby to standby to reach the request}
13
+ spec.description = %q{Unicorn Standby to standby to reach the request}
14
+ spec.homepage = "https://github.com/tsukasaoishi/unicorn-standby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "unicorn", ">= 4.8.0", "< 5.1.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.10"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest"
27
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unicorn-standby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tsukasa OISHI
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-12-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unicorn
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.8.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: 5.1.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 4.8.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: 5.1.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.10'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.10'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: minitest
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: Unicorn Standby to standby to reach the request
76
+ email:
77
+ - tsukasa.oishi@gmail.com
78
+ executables:
79
+ - unicorn-standby
80
+ - unicorn_rails-standby
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - ".gitignore"
85
+ - ".travis.yml"
86
+ - CODE_OF_CONDUCT.md
87
+ - Gemfile
88
+ - LICENSE.txt
89
+ - README.md
90
+ - Rakefile
91
+ - bin/console
92
+ - bin/setup
93
+ - exe/unicorn-standby
94
+ - exe/unicorn_rails-standby
95
+ - lib/unicorn/standby.rb
96
+ - lib/unicorn/standby/version.rb
97
+ - unicorn-standby.gemspec
98
+ homepage: https://github.com/tsukasaoishi/unicorn-standby
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Unicorn Standby to standby to reach the request
122
+ test_files: []