cuba-bin 0.2.2 → 0.3.0
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.
- checksums.yaml +4 -4
- data/bin/cuba +23 -2
- data/lib/cuba/bin.rb +19 -3
- data/lib/cuba/bin/daemon.rb +80 -97
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 312a64509492c565429802098e203099dffb5e12
|
4
|
+
data.tar.gz: 109f742ac789908d251c9a6ff32bb110935d8b9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dadeea0017b362c2b6733b59326f71a6dae7bd4b7c06f8a4b51b4a1166bc3b30b6b89d0ff8eff30e10e560903e98447610a554d01dde8fc6c4535738758e2cd1
|
7
|
+
data.tar.gz: d2734300ea9f69c7b427397581041633bd13ae08cd774191cb7ee8825265b6654385b0fa676faa97afc7d24e28c7185456d94f297a1d263981e0bc61006d32b0
|
data/bin/cuba
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
if ARGV.empty?
|
4
|
-
puts "usage: cuba [s *args]"
|
4
|
+
puts "usage: cuba [server (s) *args] [deploy (d) *args]"
|
5
5
|
exit
|
6
6
|
end
|
7
7
|
|
@@ -11,6 +11,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
11
11
|
require "cuba/bin"
|
12
12
|
require "clap"
|
13
13
|
|
14
|
+
ENV['RACK_ENV'] ||= 'development'
|
15
|
+
|
16
|
+
env = '.env'
|
17
|
+
rack_env = "#{env}.#{ENV['RACK_ENV']}"
|
18
|
+
|
19
|
+
if File.file? rack_env
|
20
|
+
env = rack_env
|
21
|
+
elsif !File.file? env
|
22
|
+
env = false
|
23
|
+
end
|
24
|
+
|
25
|
+
if env
|
26
|
+
File.foreach env do |line|
|
27
|
+
key, value = line.split "="
|
28
|
+
ENV[key] = value.gsub('\n', '').strip
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
14
32
|
Clap.run ARGV,
|
33
|
+
"server" => Cuba::Bin.method(:server),
|
15
34
|
"s" => Cuba::Bin.method(:server),
|
16
|
-
"
|
35
|
+
"deploy" => Cuba::Bin.method(:deploy),
|
36
|
+
"d" => Cuba::Bin.method(:deploy),
|
37
|
+
"-v" => -> { puts Cuba::Bin::VERSION }
|
data/lib/cuba/bin.rb
CHANGED
@@ -3,16 +3,32 @@ require "cuba/bin/daemon"
|
|
3
3
|
|
4
4
|
module Cuba::Bin
|
5
5
|
unless defined? VERSION
|
6
|
-
VERSION = '0.
|
6
|
+
VERSION = '0.3.0'
|
7
7
|
end
|
8
8
|
|
9
9
|
extend self
|
10
10
|
|
11
11
|
def server
|
12
|
-
Daemon.new
|
12
|
+
Daemon.new.run
|
13
13
|
end
|
14
14
|
|
15
|
-
|
15
|
+
def deploy
|
16
|
+
if ENV['CUBA_BIN_DEPLOY_PATH']
|
17
|
+
require ENV['CUBA_BIN_DEPLOY_PATH']
|
18
|
+
else
|
19
|
+
%w(config/deploy deploy).each do |file|
|
20
|
+
path = Dir.pwd + "/#{file}.rb"
|
21
|
+
|
22
|
+
if File.file? path
|
23
|
+
break require path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
if defined? Deploy
|
29
|
+
Deploy.new.run
|
30
|
+
end
|
31
|
+
end
|
16
32
|
|
17
33
|
def argv
|
18
34
|
@args ||= begin
|
data/lib/cuba/bin/daemon.rb
CHANGED
@@ -1,118 +1,101 @@
|
|
1
1
|
require 'listen'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def log(msg)
|
35
|
-
$stderr.puts msg
|
36
|
-
end
|
37
|
-
|
38
|
-
def start_unicorn
|
39
|
-
ENV['RACK_ENV'] ||= 'development'
|
40
|
-
|
41
|
-
envs = {}
|
42
|
-
env = '.env'
|
43
|
-
rack_env = "#{env}.#{ENV['RACK_ENV']}"
|
44
|
-
|
45
|
-
if File.file? rack_env
|
46
|
-
env = rack_env
|
47
|
-
elsif !File.file? env
|
48
|
-
env = false
|
3
|
+
class Cuba
|
4
|
+
module Bin
|
5
|
+
class Daemon
|
6
|
+
extensions = %w(
|
7
|
+
builder coffee creole css slim erb erubis jbuilder
|
8
|
+
slim mote haml html js styl dom
|
9
|
+
less liquid mab markdown md mdown mediawiki mkd mw
|
10
|
+
nokogiri radius rb rdoc rhtml ru
|
11
|
+
sass scss str textile txt wiki yajl yml
|
12
|
+
env.*
|
13
|
+
).sort
|
14
|
+
|
15
|
+
DEFAULT_RELOAD_PATTERN = %r(\.(?:builder #{extensions.join('|')})$)
|
16
|
+
|
17
|
+
DEFAULT_FULL_RELOAD_PATTERN = /^Gemfile(?:\.lock)?$/
|
18
|
+
|
19
|
+
# todo> make configurable
|
20
|
+
IGNORE_PATTERNS = [/\.direnv/, /\.sass-cache/, /^tmp/]
|
21
|
+
|
22
|
+
attr_accessor :options, :unicorn_args
|
23
|
+
attr_accessor :unicorn_pid
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
@unicorn_args = Bin.argv
|
27
|
+
# @options, @unicorn_args = options, unicorn_args
|
28
|
+
@options = {}
|
29
|
+
options[:pattern] ||= DEFAULT_RELOAD_PATTERN
|
30
|
+
options[:full] ||= DEFAULT_FULL_RELOAD_PATTERN
|
31
|
+
options[:force_polling] ||= false
|
32
|
+
self
|
49
33
|
end
|
50
34
|
|
51
|
-
|
52
|
-
|
53
|
-
key, value = line.split "="
|
54
|
-
envs[key] = value.gsub('\n', '').strip
|
55
|
-
end
|
35
|
+
def log(msg)
|
36
|
+
$stderr.puts msg
|
56
37
|
end
|
57
38
|
|
58
|
-
|
59
|
-
|
39
|
+
def start_unicorn
|
40
|
+
@unicorn_pid = Kernel.spawn('unicorn', '-c', unicorn_config, *unicorn_args)
|
41
|
+
end
|
60
42
|
|
61
|
-
|
62
|
-
|
63
|
-
|
43
|
+
def unicorn_config
|
44
|
+
File.expand_path 'unicorn.conf.rb', File.dirname(__FILE__)
|
45
|
+
end
|
64
46
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
47
|
+
# TODO maybe consider doing like: http://unicorn.bogomips.org/SIGNALS.html
|
48
|
+
def reload_everything
|
49
|
+
Process.kill(:QUIT, unicorn_pid)
|
50
|
+
Process.wait(unicorn_pid)
|
51
|
+
start_unicorn
|
52
|
+
end
|
71
53
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
54
|
+
def shutdown
|
55
|
+
listener.stop
|
56
|
+
Process.kill(:TERM, unicorn_pid)
|
57
|
+
Process.wait(unicorn_pid)
|
58
|
+
exit
|
59
|
+
end
|
78
60
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
61
|
+
# tell unicorn to gracefully shut down workers
|
62
|
+
def hup_unicorn
|
63
|
+
log "hupping #{unicorn_pid}"
|
64
|
+
Process.kill(:HUP, unicorn_pid)
|
65
|
+
end
|
84
66
|
|
85
|
-
|
86
|
-
|
67
|
+
def handle_change(modified, added, removed)
|
68
|
+
log "File change event detected: #{{modified: modified, added: added, removed: removed}.inspect}"
|
87
69
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
70
|
+
if (modified + added + removed).index {|f| f =~ options[:full]}
|
71
|
+
reload_everything
|
72
|
+
else
|
73
|
+
hup_unicorn
|
74
|
+
end
|
92
75
|
end
|
93
|
-
end
|
94
76
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
77
|
+
def listener
|
78
|
+
@listener ||= begin
|
79
|
+
x = Listen.to(Dir.pwd, :relative_paths=>true, :force_polling=> options[:force_polling]) do |modified, added, removed|
|
80
|
+
handle_change(modified, added, removed)
|
81
|
+
end
|
100
82
|
|
101
|
-
|
102
|
-
|
103
|
-
|
83
|
+
x.only([ options[:pattern], options[:full] ])
|
84
|
+
IGNORE_PATTERNS.map{|ptrn| x.ignore(ptrn) }
|
85
|
+
x
|
86
|
+
end
|
104
87
|
end
|
105
|
-
end
|
106
88
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
89
|
+
def run
|
90
|
+
that = self
|
91
|
+
Signal.trap("INT") { |signo| that.shutdown }
|
92
|
+
Signal.trap("EXIT") { |signo| that.shutdown }
|
93
|
+
listener.start
|
94
|
+
start_unicorn
|
113
95
|
|
114
|
-
|
115
|
-
|
96
|
+
# And now we just want to keep the thread alive--we're just waiting around to get interrupted at this point.
|
97
|
+
sleep(99999) while true
|
98
|
+
end
|
116
99
|
end
|
117
100
|
end
|
118
101
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba-bin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cuba
|