guard-unicorn 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - ree
4
+ - 1.8.7
5
+ - 1.9.2
6
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in guard-santorini.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Guard::Unicorn [![Build Status](https://secure.travis-ci.org/xhr/guard-unicorn.png)](http://travis-ci.org/#!/xhr/guard-unicorn)
2
+
3
+ `Guard::Unicorn` automatically restarts the Unicorn server using [Guard] [gu].
4
+
5
+ [gu]: https://github.com/guard/guard
6
+
7
+
8
+ ## Installation
9
+
10
+ Using Rubygems:
11
+
12
+ $ gem install guard-unicorn
13
+
14
+ Using Bundler, add this to your `Gemfile`, preferably in the `development` group:
15
+
16
+ ```ruby
17
+ group :development
18
+ gem 'guard-unicorn'
19
+ end
20
+ ```
21
+
22
+ Add a sample Guard definition to your `Guardfile`:
23
+
24
+ $ guard init unicorn
25
+
26
+
27
+ ## Guard General Usage
28
+
29
+ Please read the [guard usage doc] [gd] in order to find out more about Guard and
30
+ how to use Guards. There is also [a Railscast about Guard] [gc], created by Ryan
31
+ Bates.
32
+
33
+ [gd]: https://github.com/guard/guard/blob/master/README.md
34
+ [gc]: http://railscasts.com/episodes/264-guard
35
+
36
+ It is recommended that you also install the [ruby-gntp] [gntp] on Mac OS X,
37
+ [libnotify] [ln] on Linux, FreeBSD or Solaris or [rb-notifu] [notifu] in order
38
+ to have graphical notifications.
39
+
40
+ [gntp]: https://rubygems.org/gems/ruby_gntp
41
+ [ln]: https://rubygems.org/gems/libnotify
42
+ [notifu]: https://rubygems.org/gems/rb-notifu
43
+
44
+
45
+ ## Guardfile
46
+
47
+ ```ruby
48
+ guard :unicorn, :daemonized => true, :config_file => "config/unicorn.rb", :pid_file => "tmp/pids/unicorn.pid"
49
+ ```
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << "test"
7
+ t.test_files = FileList['test/**/test_*.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "guard/unicorn/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "guard-unicorn"
7
+ s.version = Guard::UnicornVersion::VERSION
8
+ s.authors = ["Andrei Maxim"]
9
+ s.email = ["andrei@andreimaxim.ro"]
10
+ s.homepage = "https://github.com/xhr/guard-unicorn"
11
+ s.summary = "Guard for Unicorn"
12
+ s.description = "Guard plug-in that allows you to restart Unicorn"
13
+
14
+ s.rubyforge_project = "guard-unicorn"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "guard"
22
+
23
+ s.add_development_dependency "rake"
24
+ s.add_development_dependency "bundler"
25
+ s.add_development_dependency "minitest"
26
+ s.add_development_dependency "guard"
27
+ end
@@ -0,0 +1,108 @@
1
+ require 'guard'
2
+ require 'guard/guard'
3
+
4
+ require 'guard/unicorn/version'
5
+
6
+ module Guard
7
+ class Unicorn < Guard
8
+
9
+ # Initialize a Guard.
10
+ # @param [Array<Guard::Watcher>] watchers the Guard file watchers
11
+ # @param [Hash] options the custom Guard options
12
+ def initialize(watchers = [], options = {})
13
+ if watchers.empty?
14
+ watchers << Watcher.new( /^app\/(controllers|models|helpers)\/.+\.rb$/ )
15
+ watchers << Watcher.new( /^lib\/.+\.rb$/ )
16
+ end
17
+
18
+ @run_as_daemon = options.fetch(:daemonize, false)
19
+
20
+ @pid_path = File.join("tmp", "pids", "unicorn.pid")
21
+ @config_path = File.join("config", "unicorn.rb")
22
+
23
+ super
24
+ end
25
+
26
+ # Call once when Guard starts. Please override initialize method to init stuff.
27
+ # @raise [:task_has_failed] when start has failed
28
+ def start
29
+ info "Starting Unicorn..."
30
+
31
+ start_unicorn
32
+ end
33
+
34
+ # Called when `stop|quit|exit|s|q|e + enter` is pressed (when Guard quits).
35
+ # @raise [:task_has_failed] when stop has failed
36
+ def stop
37
+ info "Stopping everything"
38
+ stop_unicorn
39
+ end
40
+
41
+ # Called when `reload|r|z + enter` is pressed.
42
+ # This method should be mainly used for "reload" (really!) actions like reloading passenger/spork/bundler/...
43
+ # @raise [:task_has_failed] when reload has failed
44
+ def reload
45
+ info "Stopping everything"
46
+ restart_unicorn
47
+ end
48
+
49
+ # Called when just `enter` is pressed
50
+ # This method should be principally used for long action like running all specs/tests/...
51
+ # @raise [:task_has_failed] when run_all has failed
52
+ def run_all
53
+ end
54
+
55
+ # Called on file(s) modifications that the Guard watches.
56
+ # @param [Array<String>] paths the changes files or paths
57
+ # @raise [:task_has_failed] when run_on_change has failed
58
+ def run_on_change(paths)
59
+ restart_unicorn
60
+ end
61
+
62
+ # Called on file(s) deletions that the Guard watches.
63
+ # @param [Array<String>] paths the deleted files or paths
64
+ # @raise [:task_has_failed] when run_on_change has failed
65
+ def run_on_deletion(paths)
66
+ end
67
+
68
+ private
69
+ def start_unicorn
70
+ # Make sure unicorn is stopped
71
+ stop_unicorn
72
+
73
+ cmd = []
74
+ cmd << "unicorn_rails"
75
+ cmd << "-c #{@config_path}"
76
+ cmd << "-D" if daemonize?
77
+
78
+ @pid = Process.fork do
79
+ system "#{cmd.join " "}"
80
+ info "Unicorn started."
81
+ end
82
+ end
83
+
84
+ def restart_unicorn
85
+ Process.kill "HUP", pid
86
+ end
87
+
88
+ def stop_unicorn
89
+ Process.kill("QUIT", pid) if Process.getpgid(pid)
90
+ end
91
+
92
+ def pid
93
+ return @pid if @pid
94
+
95
+ if File.exists?(@pid_path)
96
+ @pid = File.open(@pid_path) { |f| f.gets.to_i }
97
+ end
98
+ end
99
+
100
+ def info(msg)
101
+ UI.info(msg)
102
+ end
103
+
104
+ def daemonize?
105
+ @run_as_daemon
106
+ end
107
+ end
108
+ end
@@ -0,0 +1 @@
1
+ guard :santorini, :daemonize => true
@@ -0,0 +1,5 @@
1
+ module Guard
2
+ module UnicornVersion
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+
11
+ require 'minitest/autorun'
12
+
13
+ require 'guard/unicorn'
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-unicorn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andrei Maxim
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: &70228360993640 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70228360993640
25
+ - !ruby/object:Gem::Dependency
26
+ name: rake
27
+ requirement: &70228360993160 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70228360993160
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70228360992620 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70228360992620
47
+ - !ruby/object:Gem::Dependency
48
+ name: minitest
49
+ requirement: &70228360992080 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70228360992080
58
+ - !ruby/object:Gem::Dependency
59
+ name: guard
60
+ requirement: &70228360991540 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70228360991540
69
+ description: Guard plug-in that allows you to restart Unicorn
70
+ email:
71
+ - andrei@andreimaxim.ro
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .travis.yml
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - guard-unicorn.gemspec
82
+ - lib/guard/unicorn.rb
83
+ - lib/guard/unicorn/templates/Guardfile
84
+ - lib/guard/unicorn/version.rb
85
+ - test/test_helper.rb
86
+ homepage: https://github.com/xhr/guard-unicorn
87
+ licenses: []
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ requirements: []
105
+ rubyforge_project: guard-unicorn
106
+ rubygems_version: 1.8.17
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Guard for Unicorn
110
+ test_files:
111
+ - test/test_helper.rb