cuba-bin 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cuba-bin.gemspec +1 -1
- data/lib/cuba/bin.rb +1 -1
- data/lib/cuba/bin/daemon.rb +23 -21
- data/lib/cuba/bin/unicorn.conf.rb +64 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 40ca208dff5233dbc4567d43f43603c788c9d1e0
|
4
|
+
data.tar.gz: 46ed27b965f1eb00bf4a1b4daa9d69f6afd3a698
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba703159dc22a19284daf85a313bf36aa007267614694d5c62e648dad48c19bb9c45e3be7cc97ac984c28fcc8e66be4280a2b9c44a68b2a3a50aa9f06771b885
|
7
|
+
data.tar.gz: 97928c130416dc6a056496f739c4843cae5efd899caada5e97a930c82995afdcd5ff5450c5c28c552f24293fc44e10788b91d5d56068f36d3687bafbe975e9e2
|
data/cuba-bin.gemspec
CHANGED
data/lib/cuba/bin.rb
CHANGED
data/lib/cuba/bin/daemon.rb
CHANGED
@@ -18,14 +18,12 @@ module Cuba::Bin
|
|
18
18
|
# todo> make configurable
|
19
19
|
IGNORE_PATTERNS = [/\.direnv/, /\.sass-cache/, /^tmp/]
|
20
20
|
|
21
|
-
attr_accessor :options, :
|
22
|
-
attr_accessor :
|
21
|
+
attr_accessor :options, :unicorn_args
|
22
|
+
attr_accessor :unicorn_pid
|
23
23
|
|
24
|
-
def initialize(
|
25
|
-
|
26
|
-
|
27
|
-
@puma_args = puma_args
|
28
|
-
# @options, @puma_args = options, puma_args
|
24
|
+
def initialize(unicorn_args)
|
25
|
+
@unicorn_args = unicorn_args
|
26
|
+
# @options, @unicorn_args = options, unicorn_args
|
29
27
|
@options = {}
|
30
28
|
options[:pattern] ||= DEFAULT_RELOAD_PATTERN
|
31
29
|
options[:full] ||= DEFAULT_FULL_RELOAD_PATTERN
|
@@ -33,12 +31,11 @@ module Cuba::Bin
|
|
33
31
|
self
|
34
32
|
end
|
35
33
|
|
36
|
-
|
37
34
|
def log(msg)
|
38
35
|
$stderr.puts msg
|
39
36
|
end
|
40
37
|
|
41
|
-
def
|
38
|
+
def start_unicorn
|
42
39
|
ENV['RACK_ENV'] ||= 'development'
|
43
40
|
|
44
41
|
envs = {}
|
@@ -58,26 +55,31 @@ module Cuba::Bin
|
|
58
55
|
end
|
59
56
|
end
|
60
57
|
|
61
|
-
@
|
58
|
+
@unicorn_pid = Kernel.spawn(envs, 'unicorn', '-c', unicorn_config, *unicorn_args)
|
59
|
+
end
|
60
|
+
|
61
|
+
def unicorn_config
|
62
|
+
File.expand_path 'unicorn.conf.rb', File.dirname(__FILE__)
|
62
63
|
end
|
63
64
|
|
64
|
-
# TODO maybe consider doing like: http://
|
65
|
+
# TODO maybe consider doing like: http://unicorn.bogomips.org/SIGNALS.html
|
65
66
|
def reload_everything
|
66
|
-
Process.kill(:QUIT,
|
67
|
-
Process.wait(
|
68
|
-
|
67
|
+
Process.kill(:QUIT, unicorn_pid)
|
68
|
+
Process.wait(unicorn_pid)
|
69
|
+
start_unicorn
|
69
70
|
end
|
70
71
|
|
71
72
|
def shutdown
|
72
73
|
listener.stop
|
73
|
-
Process.kill(:TERM,
|
74
|
-
Process.wait(
|
74
|
+
Process.kill(:TERM, unicorn_pid)
|
75
|
+
Process.wait(unicorn_pid)
|
75
76
|
exit
|
76
77
|
end
|
77
78
|
|
78
|
-
# tell
|
79
|
-
def
|
80
|
-
|
79
|
+
# tell unicorn to gracefully shut down workers
|
80
|
+
def hup_unicorn
|
81
|
+
log "hupping #{unicorn_pid}"
|
82
|
+
Process.kill(:HUP, unicorn_pid)
|
81
83
|
end
|
82
84
|
|
83
85
|
def handle_change(modified, added, removed)
|
@@ -86,7 +88,7 @@ module Cuba::Bin
|
|
86
88
|
if (modified + added + removed).index {|f| f =~ options[:full]}
|
87
89
|
reload_everything
|
88
90
|
else
|
89
|
-
|
91
|
+
hup_unicorn
|
90
92
|
end
|
91
93
|
end
|
92
94
|
|
@@ -107,7 +109,7 @@ module Cuba::Bin
|
|
107
109
|
Signal.trap("INT") { |signo| that.shutdown }
|
108
110
|
Signal.trap("EXIT") { |signo| that.shutdown }
|
109
111
|
listener.start
|
110
|
-
|
112
|
+
start_unicorn
|
111
113
|
|
112
114
|
# And now we just want to keep the thread alive--we're just waiting around to get interrupted at this point.
|
113
115
|
sleep(99999) while true
|
@@ -0,0 +1,64 @@
|
|
1
|
+
worker_processes Integer(ENV["CUBA_BIN_WORKERS"] || 2)
|
2
|
+
timeout Integer(ENV['CUBA_BIN_TIMEOUT'] || 30)
|
3
|
+
listen Integer(ENV['CUBA_BIN_PORT'] || 8080)
|
4
|
+
|
5
|
+
# combine Ruby 2.0.0dev or REE with "preload_app true" for memory savings
|
6
|
+
# http://rubyenterpriseedition.com/faq.html#adapt_apps_for_cow
|
7
|
+
preload_app true
|
8
|
+
GC.respond_to?(:copy_on_write_friendly=) and
|
9
|
+
GC.copy_on_write_friendly = true
|
10
|
+
|
11
|
+
# Enable this flag to have unicorn test client connections by writing the
|
12
|
+
# beginning of the HTTP headers before calling the application. This
|
13
|
+
# prevents calling the application for connections that have disconnected
|
14
|
+
# while queued. This is only guaranteed to detect clients on the same
|
15
|
+
# host unicorn runs on, and unlikely to detect disconnects even on a
|
16
|
+
# fast LAN.
|
17
|
+
check_client_connection false
|
18
|
+
|
19
|
+
before_fork do |server, worker|
|
20
|
+
# the following is highly recomended for Rails + "preload_app true"
|
21
|
+
# as there's no need for the master process to hold a connection
|
22
|
+
defined?(ActiveRecord::Base) and
|
23
|
+
ActiveRecord::Base.connection.disconnect!
|
24
|
+
|
25
|
+
# The following is only recommended for memory/DB-constrained
|
26
|
+
# installations. It is not needed if your system can house
|
27
|
+
# twice as many worker_processes as you have configured.
|
28
|
+
#
|
29
|
+
# This allows a new master process to incrementally
|
30
|
+
# phase out the old master process with SIGTTOU to avoid a
|
31
|
+
# thundering herd (especially in the "preload_app false" case)
|
32
|
+
# when doing a transparent upgrade. The last worker spawned
|
33
|
+
# will then kill off the old master process with a SIGQUIT.
|
34
|
+
old_pid = "#{server.config[:pid]}.oldbin"
|
35
|
+
if old_pid != server.pid
|
36
|
+
begin
|
37
|
+
sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU
|
38
|
+
Process.kill(sig, File.read(old_pid).to_i)
|
39
|
+
rescue Errno::ENOENT, Errno::ESRCH
|
40
|
+
end
|
41
|
+
end
|
42
|
+
#
|
43
|
+
# Throttle the master from forking too quickly by sleeping. Due
|
44
|
+
# to the implementation of standard Unix signal handlers, this
|
45
|
+
# helps (but does not completely) prevent identical, repeated signals
|
46
|
+
# from being lost when the receiving process is busy.
|
47
|
+
# sleep 1
|
48
|
+
end
|
49
|
+
|
50
|
+
after_fork do |server, worker|
|
51
|
+
# per-process listener ports for debugging/admin/migrations
|
52
|
+
# addr = "127.0.0.1:#{9293 + worker.nr}"
|
53
|
+
# server.listen(addr, :tries => -1, :delay => 5, :tcp_nopush => true)
|
54
|
+
|
55
|
+
# the following is *required* for Rails + "preload_app true",
|
56
|
+
defined?(ActiveRecord::Base) and
|
57
|
+
ActiveRecord::Base.establish_connection
|
58
|
+
|
59
|
+
# if preload_app is true, then you may also want to check and
|
60
|
+
# restart any other shared sockets/descriptors such as Memcached,
|
61
|
+
# and Redis. TokyoCabinet file handles are safe to reuse
|
62
|
+
# between any number of forked children (assuming your kernel
|
63
|
+
# correctly implements pread()/pwrite() system calls)
|
64
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba-bin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cj
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: unicorn
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- cuba-bin.gemspec
|
112
112
|
- lib/cuba/bin.rb
|
113
113
|
- lib/cuba/bin/daemon.rb
|
114
|
+
- lib/cuba/bin/unicorn.conf.rb
|
114
115
|
homepage: ''
|
115
116
|
licenses:
|
116
117
|
- MIT
|