refresh 0.0.1 → 0.1.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: fd12a9239caeed1d258fc23fafdb8a1919b09c5c
4
- data.tar.gz: 26d36a9f7b18916a42f361aa84d690f31dcc0090
3
+ metadata.gz: 38d1b5dafadabbe768db8ff57a8137dfaf15e05e
4
+ data.tar.gz: be6a97828d8ebff39ea609ad8fd234158105312a
5
5
  SHA512:
6
- metadata.gz: c26191d326fcb626243b04cf0f4063c14781af645f95e0faafcba9b6029877ee369f876866cf4d69e6ad60cce56d3cd5fd5cbccf50d5713f1f5df8938331c2a7
7
- data.tar.gz: 5b8baabb29af8d2bae08fa3a4e6729c4ba612c7ab46d5583b21d5721be7792630ecc19eb74c82de61810fa57e4e578c1b19e40eb36b56b53835eec12390c092b
6
+ metadata.gz: 33a9d6de02b056fb4224559065adc552a9fa391fd9c0c1fd445154d1abc63196ddaf20d739642e6866cb9194dddc3ce5072fb5ee9929c750278b1211e532e3f0
7
+ data.tar.gz: bd89feca1fd9a2e6dd07b7a8a1d1bed44a4f5530f2c96f1d82410931a5d9c2a9131de1adc9e083ee1b8ac3cb8e6d3aacdf7aa0c89478e838a181c5034f5b4472
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require 'refresh'
7
+
8
+ Refresh.server
@@ -1,5 +1,10 @@
1
1
  require "refresh/version"
2
+ require "refresh/daemon"
2
3
 
3
4
  module Refresh
4
- # Your code goes here...
5
+ extend self
6
+
7
+ def server
8
+ Daemon.new(ARGV).run
9
+ end
5
10
  end
@@ -0,0 +1,99 @@
1
+ require 'listen'
2
+
3
+ module Refresh
4
+ class Daemon
5
+ extensions = %w(
6
+ builder coffee creole css slim erb erubis jbuilder
7
+ slim mote haml html js styl dom
8
+ less liquid mab markdown md mdown mediawiki mkd mw
9
+ nokogiri radius rb rdoc rhtml ru
10
+ sass scss str textile txt wiki yajl yml
11
+ env.*
12
+ ).sort
13
+
14
+ DEFAULT_RELOAD_PATTERN = %r(\.(?:builder #{extensions.join('|')})$)
15
+
16
+ DEFAULT_FULL_RELOAD_PATTERN = /^Gemfile(?:\.lock)?$/
17
+
18
+ # todo> make configurable
19
+ IGNORE_PATTERNS = [/\.direnv/, /\.sass-cache/, /^tmp/]
20
+
21
+ attr_accessor :options, :unicorn_args
22
+ attr_accessor :unicorn_pid
23
+
24
+ def initialize argv
25
+ @unicorn_args = argv
26
+ # @options, @unicorn_args = options, unicorn_args
27
+ @options = {}
28
+ options[:pattern] ||= DEFAULT_RELOAD_PATTERN
29
+ options[:full] ||= DEFAULT_FULL_RELOAD_PATTERN
30
+ options[:force_polling] ||= false
31
+ self
32
+ end
33
+
34
+ def log(msg)
35
+ $stderr.puts msg
36
+ end
37
+
38
+ def start_unicorn
39
+ @unicorn_pid = Kernel.spawn('unicorn', '-c', unicorn_config, *unicorn_args)
40
+ end
41
+
42
+ def unicorn_config
43
+ File.expand_path 'unicorn.conf.rb', File.dirname(__FILE__)
44
+ end
45
+
46
+ # TODO maybe consider doing like: http://unicorn.bogomips.org/SIGNALS.html
47
+ def reload_everything
48
+ Process.kill(:QUIT, unicorn_pid)
49
+ Process.wait(unicorn_pid)
50
+ start_unicorn
51
+ end
52
+
53
+ def shutdown
54
+ listener.stop
55
+ Process.kill(:TERM, unicorn_pid)
56
+ Process.wait(unicorn_pid)
57
+ exit
58
+ end
59
+
60
+ # tell unicorn to gracefully shut down workers
61
+ def hup_unicorn
62
+ log "hupping #{unicorn_pid}"
63
+ Process.kill(:HUP, unicorn_pid)
64
+ end
65
+
66
+ def handle_change(modified, added, removed)
67
+ log "File change event detected: #{{modified: modified, added: added, removed: removed}.inspect}"
68
+
69
+ if (modified + added + removed).index {|f| f =~ options[:full]}
70
+ reload_everything
71
+ else
72
+ hup_unicorn
73
+ end
74
+ end
75
+
76
+ def listener
77
+ @listener ||= begin
78
+ x = Listen.to(Dir.pwd, :relative_paths=>true, :force_polling=> options[:force_polling]) do |modified, added, removed|
79
+ handle_change(modified, added, removed)
80
+ end
81
+
82
+ x.only([ options[:pattern], options[:full] ])
83
+ IGNORE_PATTERNS.map{|ptrn| x.ignore(ptrn) }
84
+ x
85
+ end
86
+ end
87
+
88
+ def run
89
+ that = self
90
+ Signal.trap("INT") { |signo| that.shutdown }
91
+ Signal.trap("EXIT") { |signo| that.shutdown }
92
+ listener.start
93
+ start_unicorn
94
+
95
+ # And now we just want to keep the thread alive--we're just waiting around to get interrupted at this point.
96
+ sleep(99999) while true
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,64 @@
1
+ worker_processes Integer(ENV["REFRESH_WORKERS"] || 1)
2
+ timeout Integer(ENV['REFRESH_TIMEOUT'] || 30)
3
+ listen Integer(ENV['REFRESH_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
@@ -1,3 +1,3 @@
1
1
  module Refresh
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Refresh::VERSION
9
9
  spec.authors = ["cj"]
10
10
  spec.email = ["cjlazell@gmail.com"]
11
- spec.summary = %q{refresh}
12
- spec.description = %q{refresh}
11
+ spec.summary = %q{auto refresh/reload your ruby code/site}
12
+ spec.description = %q{auto refresh/reload your ruby code/site}
13
13
  spec.homepage = ""
14
14
  spec.license = "MIT"
15
15
 
@@ -18,6 +18,9 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
+ spec.add_dependency "listen"
22
+ spec.add_dependency "unicorn"
23
+
21
24
  spec.add_development_dependency "bundler", "~> 1.5"
22
25
  spec.add_development_dependency "rake"
23
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refresh
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - cj
@@ -10,6 +10,34 @@ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2014-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: listen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: unicorn
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,10 +66,11 @@ dependencies:
38
66
  - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
- description: refresh
69
+ description: auto refresh/reload your ruby code/site
42
70
  email:
43
71
  - cjlazell@gmail.com
44
- executables: []
72
+ executables:
73
+ - refresh
45
74
  extensions: []
46
75
  extra_rdoc_files: []
47
76
  files:
@@ -50,7 +79,10 @@ files:
50
79
  - LICENSE.txt
51
80
  - README.md
52
81
  - Rakefile
82
+ - bin/refresh
53
83
  - lib/refresh.rb
84
+ - lib/refresh/daemon.rb
85
+ - lib/refresh/unicorn.conf.rb
54
86
  - lib/refresh/version.rb
55
87
  - refresh.gemspec
56
88
  homepage: ''
@@ -76,5 +108,5 @@ rubyforge_project:
76
108
  rubygems_version: 2.2.2
77
109
  signing_key:
78
110
  specification_version: 4
79
- summary: refresh
111
+ summary: auto refresh/reload your ruby code/site
80
112
  test_files: []