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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1626abc9ea3d27fadf54ac21bb2b94043bd9d18
4
- data.tar.gz: d68bc5330a8670fcaa788117eee8d4e85fa13909
3
+ metadata.gz: 40ca208dff5233dbc4567d43f43603c788c9d1e0
4
+ data.tar.gz: 46ed27b965f1eb00bf4a1b4daa9d69f6afd3a698
5
5
  SHA512:
6
- metadata.gz: 634b934289fcc14feba6b8045530298dab0b16cc0d91687e3cdb2b5e1672a803dd1190a00b35568bdd34868c805962941e34da163006bf6cc9445ad09974fa6e
7
- data.tar.gz: c7c2f14d49e3f5e3abc38e63676826cbef5f6a80404e53fb6471c2898f2229b419a5180cf121cc36b472f5e0f29f1230eca8aa5de97b08b3146e6f4d5b2105e9
6
+ metadata.gz: ba703159dc22a19284daf85a313bf36aa007267614694d5c62e648dad48c19bb9c45e3be7cc97ac984c28fcc8e66be4280a2b9c44a68b2a3a50aa9f06771b885
7
+ data.tar.gz: 97928c130416dc6a056496f739c4843cae5efd899caada5e97a930c82995afdcd5ff5450c5c28c552f24293fc44e10788b91d5d56068f36d3687bafbe975e9e2
data/cuba-bin.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency "cuba"
22
22
  spec.add_dependency "clap"
23
- spec.add_dependency "puma"
23
+ spec.add_dependency "unicorn"
24
24
  spec.add_dependency "listen"
25
25
 
26
26
  spec.add_development_dependency "bundler", "~> 1.3"
data/lib/cuba/bin.rb CHANGED
@@ -3,7 +3,7 @@ require "cuba/bin/daemon"
3
3
 
4
4
  module Cuba::Bin
5
5
  unless defined? VERSION
6
- VERSION = '0.1.1'
6
+ VERSION = '0.2.0'
7
7
  end
8
8
 
9
9
  extend self
@@ -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, :puma_args
22
- attr_accessor :puma_pid
21
+ attr_accessor :options, :unicorn_args
22
+ attr_accessor :unicorn_pid
23
23
 
24
- def initialize(puma_args)
25
- puma_args.concat ['-w', '1'] unless puma_args.include? '-w'
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 start_puma
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
- @puma_pid = Kernel.spawn(envs, 'puma', *puma_args)
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://puma.bogomips.org/SIGNALS.html
65
+ # TODO maybe consider doing like: http://unicorn.bogomips.org/SIGNALS.html
65
66
  def reload_everything
66
- Process.kill(:QUIT, puma_pid)
67
- Process.wait(puma_pid)
68
- start_puma
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, puma_pid)
74
- Process.wait(puma_pid)
74
+ Process.kill(:TERM, unicorn_pid)
75
+ Process.wait(unicorn_pid)
75
76
  exit
76
77
  end
77
78
 
78
- # tell puma to gracefully shut down workers
79
- def graceful_restart
80
- Process.kill(:SIGUSR1, puma_pid)
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
- graceful_restart
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
- start_puma
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.1.1
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: puma
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