blue-unicorn 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/blue-unicorn.gemspec +24 -0
- data/lib/blue/unicorn.rb +59 -0
- data/lib/blue/unicorn/capistrano/integration.rb +28 -0
- data/lib/blue/unicorn/version.rb +5 -0
- data/templates/monit.conf.erb +5 -0
- data/templates/unicorn.cfg.erb +108 -0
- data/templates/unicorn.init.erb +75 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Josh Sharpe
|
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,29 @@
|
|
1
|
+
# Blue::Unicorn
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'blue-unicorn'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install blue-unicorn
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'blue/unicorn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "blue-unicorn"
|
8
|
+
spec.version = Blue::Unicorn::VERSION
|
9
|
+
spec.authors = ["Josh Sharpe"]
|
10
|
+
spec.email = ["josh.m.sharpe@gmail.com"]
|
11
|
+
spec.description = %q{A Unicorn plugin for the Blue deployment framework}
|
12
|
+
spec.summary = %q{Adds init scripts and monitoring for Unicorn}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
24
|
+
|
data/lib/blue/unicorn.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "blue/unicorn/version"
|
2
|
+
require "blue/unicorn/capistrano/integration"
|
3
|
+
|
4
|
+
module Blue
|
5
|
+
module Unicorn
|
6
|
+
|
7
|
+
Blue::Gems.require('blue-unicorn')
|
8
|
+
|
9
|
+
def self.configure
|
10
|
+
Blue.configure({
|
11
|
+
:unicorn => {}
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
def unicorn(options = {})
|
16
|
+
file "/etc/init.d/unicorn",
|
17
|
+
:ensure => :present,
|
18
|
+
:mode => '744',
|
19
|
+
:owner => Blue.config.user,
|
20
|
+
:content => template(File.join(File.dirname(__FILE__), '..', '..', 'templates', 'unicorn.init.erb'), binding)
|
21
|
+
|
22
|
+
file Blue::Unicorn.cfg_path,
|
23
|
+
:ensure => :present,
|
24
|
+
:mode => '744',
|
25
|
+
:owner => Blue.config.user,
|
26
|
+
:content => template(File.join(File.dirname(__FILE__), '..', '..', 'templates', 'unicorn.cfg.erb'), binding)
|
27
|
+
|
28
|
+
if Blue.const_defined?(:Monit)
|
29
|
+
file "/etc/monit/conf.d/unicorn.conf",
|
30
|
+
:ensure => :present,
|
31
|
+
:mode => '700',
|
32
|
+
:backup => false,
|
33
|
+
:content => template(File.join(File.dirname(__FILE__), '..', '..', 'templates', 'monit.conf.erb'), binding),
|
34
|
+
:notify => service('monit')
|
35
|
+
elsif Blue.const_defined?(:God)
|
36
|
+
# Define this yo'self homie.
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.pid_path
|
41
|
+
File.join(Blue.rails_current, 'pids/unicorn.master.pid')
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.cfg_path
|
45
|
+
File.join(Blue.shared_path, 'config/unicorn.cfg')
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.included(klass)
|
49
|
+
klass.add_role(:app)
|
50
|
+
klass.add_role(:unicorn)
|
51
|
+
klass.class_eval do
|
52
|
+
recipe :unicorn
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
Blue::Unicorn.configure
|
59
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Blue
|
2
|
+
module Unicorn
|
3
|
+
module Capistrano
|
4
|
+
module Integration
|
5
|
+
def self.load(capistrano_config)
|
6
|
+
capistrano_config.load do
|
7
|
+
|
8
|
+
namespace :blue do
|
9
|
+
namespace :unicorn do
|
10
|
+
desc "Trigger Unicorn restarts"
|
11
|
+
task :restart do
|
12
|
+
run "/etc/init.d/unicorn restart"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
after 'deploy:create_symlink', 'blue:unicorn:restart'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if Capistrano::Configuration.instance
|
26
|
+
Blue::Unicorn::Capistrano::Integration.load(Capistrano::Configuration.instance)
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,5 @@
|
|
1
|
+
check process unicorn_master
|
2
|
+
with pidfile <%= Blue::Unicorn.pid_path %>
|
3
|
+
start program = "/etc/init.d/unicorn start" as uid <%= Blue.config.user %> and gid <%= Blue.config.group %> with timeout 60 seconds
|
4
|
+
stop program = "/etc/init.d/unicorn stop" as uid <%= Blue.config.user %> and gid <%= Blue.config.group %> with timeout 60 seconds
|
5
|
+
|
@@ -0,0 +1,108 @@
|
|
1
|
+
# Sample verbose configuration file for Unicorn (not Rack)
|
2
|
+
#
|
3
|
+
# This configuration file documents many features of Unicorn
|
4
|
+
# that may not be needed for some applications. See
|
5
|
+
# http://unicorn.bogomips.org/examples/unicorn.conf.minimal.rb
|
6
|
+
# for a much simpler configuration file.
|
7
|
+
#
|
8
|
+
# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete
|
9
|
+
# documentation.
|
10
|
+
|
11
|
+
# Use at least one worker per core if you're on a dedicated server,
|
12
|
+
# more will usually help for _short_ waits on databases/caches.
|
13
|
+
worker_processes 2
|
14
|
+
|
15
|
+
# Since Unicorn is never exposed to outside clients, it does not need to
|
16
|
+
# run on the standard HTTP port (80), there is no reason to start Unicorn
|
17
|
+
# as root unless it's from system init scripts.
|
18
|
+
# If running the master process as root and the workers as an unprivileged
|
19
|
+
# user, do this to switch euid/egid in the workers (also chowns logs):
|
20
|
+
# user "unprivileged_user", "unprivileged_group"
|
21
|
+
|
22
|
+
# Help ensure your application will always spawn in the symlinked
|
23
|
+
# "current" directory that Capistrano sets up.
|
24
|
+
working_directory "<%= Blue.rails_current %>" # available in 0.94.0+
|
25
|
+
|
26
|
+
# listen on both a Unix domain socket and a TCP port,
|
27
|
+
# we use a shorter backlog for quicker failover when busy
|
28
|
+
# listen "/tmp/.sock", :backlog => 64
|
29
|
+
# listen 8080, :tcp_nopush => true
|
30
|
+
listen <%= Blue.config.unicorn.port || 8080 %>, :tcp_nopush => true
|
31
|
+
|
32
|
+
# nuke workers after 30 seconds instead of 60 seconds (the default)
|
33
|
+
timeout <%= Blue.config.unicorn.timeout || 30 %>
|
34
|
+
|
35
|
+
# feel free to point this anywhere accessible on the filesystem
|
36
|
+
pid "<%= Blue::Unicorn.pid_path %>"
|
37
|
+
|
38
|
+
# By default, the Unicorn logger will write to stderr.
|
39
|
+
# Additionally, ome applications/frameworks log to stderr or stdout,
|
40
|
+
# so prevent them from going to /dev/null when daemonized here:
|
41
|
+
stderr_path "<%= Blue.rails_current %>/log/unicorn.stderr.log"
|
42
|
+
stdout_path "<%= Blue.rails_current %>/log/unicorn.stdout.log"
|
43
|
+
|
44
|
+
# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
|
45
|
+
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
|
46
|
+
preload_app true
|
47
|
+
GC.respond_to?(:copy_on_write_friendly=) and
|
48
|
+
GC.copy_on_write_friendly = true
|
49
|
+
|
50
|
+
# Enable this flag to have unicorn test client connections by writing the
|
51
|
+
# beginning of the HTTP headers before calling the application. This
|
52
|
+
# prevents calling the application for connections that have disconnected
|
53
|
+
# while queued. This is only guaranteed to detect clients on the same
|
54
|
+
# host unicorn runs on, and unlikely to detect disconnects even on a
|
55
|
+
# fast LAN.
|
56
|
+
check_client_connection false
|
57
|
+
|
58
|
+
before_exec do |server|
|
59
|
+
ENV['BUNDLE_GEMFILE'] = "<%= Blue.rails_current %>/Gemfile"
|
60
|
+
end
|
61
|
+
|
62
|
+
before_fork do |server, worker|
|
63
|
+
# the following is highly recomended for Rails + "preload_app true"
|
64
|
+
# as there's no need for the master process to hold a connection
|
65
|
+
defined?(ActiveRecord::Base) and
|
66
|
+
ActiveRecord::Base.connection.disconnect!
|
67
|
+
|
68
|
+
# The following is only recommended for memory/DB-constrained
|
69
|
+
# installations. It is not needed if your system can house
|
70
|
+
# twice as many worker_processes as you have configured.
|
71
|
+
#
|
72
|
+
# # This allows a new master process to incrementally
|
73
|
+
# # phase out the old master process with SIGTTOU to avoid a
|
74
|
+
# # thundering herd (especially in the "preload_app false" case)
|
75
|
+
# # when doing a transparent upgrade. The last worker spawned
|
76
|
+
# # will then kill off the old master process with a SIGQUIT.
|
77
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
78
|
+
if old_pid != server.pid
|
79
|
+
begin
|
80
|
+
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
81
|
+
Process.kill(sig, File.read(old_pid).to_i)
|
82
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
83
|
+
end
|
84
|
+
end
|
85
|
+
#
|
86
|
+
# Throttle the master from forking too quickly by sleeping. Due
|
87
|
+
# to the implementation of standard Unix signal handlers, this
|
88
|
+
# helps (but does not completely) prevent identical, repeated signals
|
89
|
+
# from being lost when the receiving process is busy.
|
90
|
+
sleep 1
|
91
|
+
end
|
92
|
+
|
93
|
+
after_fork do |server, worker|
|
94
|
+
# per-process listener ports for debugging/admin/migrations
|
95
|
+
# addr = "127.0.0.1:#{9293 + worker.nr}"
|
96
|
+
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
|
97
|
+
|
98
|
+
# the following is *required* for Rails + "preload_app true",
|
99
|
+
defined?(ActiveRecord::Base) and
|
100
|
+
ActiveRecord::Base.establish_connection
|
101
|
+
|
102
|
+
# if preload_app is true, then you may also want to check and
|
103
|
+
# restart any other shared sockets/descriptors such as Memcached,
|
104
|
+
# and Redis. TokyoCabinet file handles are safe to reuse
|
105
|
+
# between any number of forked children (assuming your kernel
|
106
|
+
# correctly implements pread()/pwrite() system calls)
|
107
|
+
end
|
108
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
TIMEOUT=60
|
6
|
+
APP_ROOT=<%= Blue.rails_current %>
|
7
|
+
PID=<%= Blue::Unicorn.pid_path %>
|
8
|
+
CMD="bundle exec unicorn_rails -D -E production -c <%= Blue::Unicorn.cfg_path %>"
|
9
|
+
|
10
|
+
set -u
|
11
|
+
|
12
|
+
old_pid="$PID.oldbin"
|
13
|
+
|
14
|
+
cd $APP_ROOT || exit 1
|
15
|
+
|
16
|
+
sig () {
|
17
|
+
test -s "$PID" && kill -$1 `cat $PID`
|
18
|
+
}
|
19
|
+
|
20
|
+
oldsig () {
|
21
|
+
test -s $old_pid && kill -$1 `cat $old_pid`
|
22
|
+
}
|
23
|
+
|
24
|
+
case $1 in
|
25
|
+
start)
|
26
|
+
sig 0 && echo >&2 "Already running" && exit 0
|
27
|
+
$CMD
|
28
|
+
;;
|
29
|
+
stop)
|
30
|
+
sig QUIT && exit 0
|
31
|
+
echo >&2 "Not running"
|
32
|
+
;;
|
33
|
+
force-stop)
|
34
|
+
sig TERM && exit 0
|
35
|
+
echo >&2 "Not running"
|
36
|
+
;;
|
37
|
+
reload)
|
38
|
+
sig HUP && echo reloaded OK && exit 0
|
39
|
+
echo >&2 "Couldn't reload, starting '$CMD' instead"
|
40
|
+
$CMD
|
41
|
+
;;
|
42
|
+
restart)
|
43
|
+
sig USR2 && echo restarted OK && exit 0
|
44
|
+
echo >&2 "Couldn't restart, starting '$CMD' instead"
|
45
|
+
$CMD
|
46
|
+
;;
|
47
|
+
upgrade)
|
48
|
+
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
|
49
|
+
then
|
50
|
+
n=$TIMEOUT
|
51
|
+
while test -s $old_pid && test $n -ge 0
|
52
|
+
do
|
53
|
+
printf '.' && sleep 1 && n=$(( $n - 1 ))
|
54
|
+
done
|
55
|
+
echo
|
56
|
+
|
57
|
+
if test $n -lt 0 && test -s $old_pid
|
58
|
+
then
|
59
|
+
echo >&2 "$old_pid still exists after $TIMEOUT seconds"
|
60
|
+
exit 1
|
61
|
+
fi
|
62
|
+
exit 0
|
63
|
+
fi
|
64
|
+
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
|
65
|
+
$CMD
|
66
|
+
;;
|
67
|
+
reopen-logs)
|
68
|
+
sig USR1
|
69
|
+
;;
|
70
|
+
*)
|
71
|
+
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
|
72
|
+
exit 1
|
73
|
+
;;
|
74
|
+
esac
|
75
|
+
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blue-unicorn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Josh Sharpe
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-05-24 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 3
|
32
|
+
version: "1.3"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description: A Unicorn plugin for the Blue deployment framework
|
50
|
+
email:
|
51
|
+
- josh.m.sharpe@gmail.com
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
61
|
+
- LICENSE.txt
|
62
|
+
- README.md
|
63
|
+
- Rakefile
|
64
|
+
- blue-unicorn.gemspec
|
65
|
+
- lib/blue/unicorn.rb
|
66
|
+
- lib/blue/unicorn/capistrano/integration.rb
|
67
|
+
- lib/blue/unicorn/version.rb
|
68
|
+
- templates/monit.conf.erb
|
69
|
+
- templates/unicorn.cfg.erb
|
70
|
+
- templates/unicorn.init.erb
|
71
|
+
homepage: ""
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project:
|
100
|
+
rubygems_version: 1.8.24
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Adds init scripts and monitoring for Unicorn
|
104
|
+
test_files: []
|
105
|
+
|