guard-passenger 0.1.0 → 0.2.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.
@@ -1,6 +1,6 @@
1
1
  = Guard::Passenger
2
2
 
3
- Guard::Passenger is the useful development server solution. The guard automatically starts passenger and intelligently restarts the server when needed.
3
+ Guard::Passenger is the useful development server solution. The guard automatically starts Passenger and intelligently restarts the server when needed.
4
4
 
5
5
  == Install
6
6
 
@@ -24,36 +24,36 @@ Please read {guard usage doc}[http://github.com/guard/guard#readme]
24
24
 
25
25
  == Guardfile
26
26
 
27
- Passenger guard can be really be adapted to all kind of rack project with passenger.
27
+ Passenger guard can be really be adapted to all kind of rack project with Passenger.
28
28
  Please read {guard doc}[http://github.com/guard/guard#readme] for more info about Guardfile DSL.
29
29
 
30
30
  === Standard rails app
31
31
 
32
32
  guard 'passenger' do
33
- watch('lib/.*\.rb')
34
- watch('config/.*\.rb')
33
+ watch(%|lib/.*\.rb|)
34
+ watch(%|config/.*\.rb|)
35
35
  end
36
36
 
37
37
  === Passenger standalone
38
38
 
39
- To use passenger standalone you can pass options to the guard. Guard::Passenger will start passenger on startup and take it down on exit.
40
- By default passenger standalone is deactivated and port is set to 3000.
39
+ Passenger standalone is used as default. You can pass options to the guard to disable or configure it. Guard::Passenger will start Passenger on startup and take it down on exit.
40
+ By default Passenger standalone is activated and port is set to 3000.
41
41
 
42
- guard 'passenger', :standalone => true, :port => 3001 do
43
- watch('lib/.*\.rb')
44
- watch('config/.*\.rb')
45
- end
42
+ === Ping
43
+
44
+ You can choose to ping localhost:port(/path) after Passenger has been restarted, it's done asynchronously so it won't block other guards execution. If you set :ping to true, it will ping localhost:3000/, it you set :ping to a String, it will append the path to localhost:3000/ for the ping.
45
+ If the ping responds with a non-5XX response, Passenger is considered as running, otherwise, there is probably a problem with Passenger.
46
46
 
47
47
  === Guard options
48
48
 
49
49
  Guard::Passenger accepts some options for configuration.
50
50
 
51
- # :standalone boolean run passenger standalone (default: true)
52
- # :port integer using the given port (default: 3000)
53
- # :env string framework environment (default: development)
54
- # :touch string path to check if restart was successful (default: /) (false = off)
51
+ # :standalone boolean run Passenger standalone (default: true)
52
+ # :port integer using the given port (default: 3000)
53
+ # :env string framework environment (default: development)
54
+ # :ping boolean or string ping localhost after Passenger restart (default: false)
55
55
 
56
- guard 'passenger', :standalone => false, :port => 3001, :env => 'production', :touch => '/users/all' do
56
+ guard 'passenger', :standalone => false, :port => 3001, :env => 'production', :ping => '/foo' do
57
57
  end
58
58
 
59
59
  == Development
@@ -65,4 +65,7 @@ Pull requests are very welcome! Make sure your patches are well tested. Please c
65
65
 
66
66
  == Authors
67
67
 
68
- {Fabio Kuhn}[http://github.com/mordaroso]
68
+ {Fabio Kuhn}[https://github.com/mordaroso]
69
+
70
+ {Contributors}[https://github.com/mordaroso/guard-passenger/contributors]
71
+ {Forks}[https://github.com/mordaroso/guard-passenger/network/members]
@@ -4,79 +4,64 @@ require 'rubygems'
4
4
 
5
5
  module Guard
6
6
  class Passenger < Guard
7
-
7
+
8
8
  autoload :Runner, 'guard/passenger/runner'
9
- autoload :Toucher, 'guard/passenger/toucher'
10
-
11
- attr_reader :port, :env, :touch
12
-
9
+ autoload :Pinger, 'guard/passenger/pinger'
10
+
11
+ attr_reader :port, :env, :ping
12
+
13
13
  def standalone?
14
14
  @standalone
15
15
  end
16
-
17
- # ================
18
- # = Guard method =
19
- # ================
20
-
16
+
17
+ # =================
18
+ # = Guard methods =
19
+ # =================
20
+
21
21
  def initialize(watchers = [], options = {})
22
22
  super
23
23
  @standalone = options[:standalone].nil? ? true : options[:standalone]
24
- @port = options[:port].nil? ? 3000 : options[:port]
25
- @env = options[:env].nil? ? 'development' : options[:env]
26
- @touch = options[:touch].nil? ? '/' : options[:touch]
24
+ @port = options[:port] || 3000
25
+ @env = options[:env] || 'development'
26
+ ping_opt = unless options[:touch].nil?
27
+ UI.info "Warning: The :touch option has been replaced by the :ping option, usage is still the same."
28
+ options[:touch]
29
+ else
30
+ options[:ping]
31
+ end
32
+ @ping = ping_opt.eql?(true) ? '/' : ping_opt
27
33
  end
28
-
34
+
29
35
  # Call once when guard starts
30
36
  def start
31
- UI.info "Guard::Passenger is guarding your changes!"
32
- if standalone?
33
- Runner.start_passenger(port, env)
34
- else
35
- true
36
- end
37
+ UI.info 'Guard::Passenger is running!'
38
+ standalone? ? Runner.start_passenger(port, env) : true
37
39
  end
38
-
40
+
39
41
  # Call with Ctrl-C signal (when Guard quit)
40
42
  def stop
41
- if standalone?
42
- Runner.stop_passenger(port)
43
- else
44
- true
45
- end
43
+ UI.info 'Stopping Passenger...'
44
+ standalone? ? Runner.stop_passenger(port) : true
46
45
  end
47
-
46
+
48
47
  # Call with Ctrl-Z signal
49
48
  def reload
50
- restart_and_touch
49
+ restart_and_ping
51
50
  end
52
-
53
- # Call with Ctrl-/ signal
54
- def run_all
55
- true
56
- end
57
-
51
+
58
52
  # Call on file(s) modifications
59
- def run_on_change(paths)
60
- restart_and_touch
53
+ def run_on_change(paths = {})
54
+ restart_and_ping
61
55
  end
62
-
56
+
63
57
  private
64
- def restart_and_touch
65
- if Runner.restart_passenger & touch_url
66
- UI.info 'Successfully restarted passenger'
67
- true
68
- else
69
- UI.error 'Restarting passenger failed'
70
- false
71
- end
72
- end
73
-
74
- def touch_url
75
- if touch
76
- Toucher.touch('localhost', port, touch)
77
- else
78
- true
79
- end
80
- end
58
+
59
+ def restart_and_ping
60
+ UI.info 'Restarting Passenger...'
61
+ restarted = Runner.restart_passenger
62
+ Pinger.ping('localhost', port, ping) if ping
63
+ restarted
64
+ end
65
+
81
66
  end
82
- end
67
+ end
@@ -0,0 +1,32 @@
1
+ require 'net/http'
2
+
3
+ module Guard
4
+ class Passenger
5
+ module Pinger
6
+ class << self
7
+
8
+ # try to ping given url (e.g. http://localhost:3000/) and display a message to inform of the result
9
+ # failure == response status is 5xx
10
+ # otherwise, it's a success
11
+ def ping(host, port, path = '/')
12
+ path = "/#{path}" unless path.match(/^\//)
13
+ ping_in_thread = Thread.start {
14
+ begin
15
+ response = Net::HTTP.start(host, port) do |http|
16
+ http.head(path)
17
+ end
18
+ if response.is_a? Net::HTTPServerError
19
+ Notifier.notify("Passenger is not running!", :title => "Passenger", :image => :failed)
20
+ else
21
+ Notifier.notify("Passenger is running.", :title => "Passenger", :image => :success)
22
+ end
23
+ rescue
24
+ # do nothing
25
+ end
26
+ }
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -2,34 +2,42 @@ module Guard
2
2
  class Passenger
3
3
  module Runner
4
4
  class << self
5
-
5
+
6
6
  def restart_passenger
7
- system 'touch tmp/restart.txt'
7
+ succeed = system("touch tmp/restart.txt")
8
+ if succeed
9
+ UI.info "Passenger successfully restarted."
10
+ else
11
+ UI.error "Passenger failed to restart!"
12
+ end
13
+ succeed
8
14
  end
9
-
15
+
10
16
  def start_passenger(port, environment)
11
17
  if passenger_standalone_installed?
12
- result = system "passenger start -p #{port} -d -e #{environment}"
13
- if result
14
- UI.info "Passenger standalone startet at port #{port}"
18
+ succeed = system("passenger start -p #{port} -d -e #{environment}")
19
+ if succeed
20
+ UI.info "Passenger standalone (port #{port}) started."
15
21
  else
16
- UI.error "Passenger standalone failed to start at port #{port}"
22
+ UI.error "Passenger standalone (port #{port}) failed to start!"
17
23
  end
18
- result
24
+ succeed
19
25
  else
20
- UI.error "Passenger standalone is not installed. You need at least passenger version >= 3.0.0.\nPlease run 'gem install passenger' or add it to your Gemfile."
26
+ UI.error "Passenger standalone is not installed. You need at least Passenger version >= 3.0.0.\nPlease run 'gem install passenger' or add it to your Gemfile."
21
27
  false
22
28
  end
23
29
  end
24
-
30
+
25
31
  def stop_passenger(port)
26
- result = system "passenger stop -p #{port}"
27
- if result
28
- UI.info "Passenger standalone stopped"
32
+ succeed = system("passenger stop -p #{port}")
33
+ if succeed
34
+ UI.info "Passenger standalone (port #{port}) stopped."
35
+ else
36
+ UI.error "Passenger standalone (port #{port}) failed to stop!"
29
37
  end
30
- true
38
+ succeed
31
39
  end
32
-
40
+
33
41
  def passenger_standalone_installed?
34
42
  begin
35
43
  gem "passenger", ">=3.0.0"
@@ -38,7 +46,8 @@ module Guard
38
46
  end
39
47
  true
40
48
  end
49
+
41
50
  end
42
51
  end
43
52
  end
44
- end
53
+ end
@@ -1,5 +1,5 @@
1
1
  module Guard
2
2
  module PassengerVersion
3
- VERSION = '0.1.0'
3
+ VERSION = '0.2.0'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-passenger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Fabio Kuhn
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-06 00:00:00 +01:00
18
+ date: 2010-11-29 00:00:00 +01:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,7 +24,7 @@ dependencies:
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ">="
27
+ - - ~>
28
28
  - !ruby/object:Gem::Version
29
29
  hash: 21
30
30
  segments:
@@ -35,22 +35,70 @@ dependencies:
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
38
- name: rspec
38
+ name: bundler
39
39
  prerelease: false
40
40
  requirement: &id002 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- hash: 13
45
+ hash: 25
46
+ segments:
47
+ - 1
48
+ - 0
49
+ - 7
50
+ version: 1.0.7
51
+ type: :development
52
+ version_requirements: *id002
53
+ - !ruby/object:Gem::Dependency
54
+ name: rspec
55
+ prerelease: false
56
+ requirement: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 7
46
62
  segments:
47
63
  - 2
64
+ - 2
65
+ - 0
66
+ version: 2.2.0
67
+ type: :development
68
+ version_requirements: *id003
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ prerelease: false
72
+ requirement: &id004 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ hash: 11
78
+ segments:
48
79
  - 0
49
80
  - 1
50
- version: 2.0.1
81
+ - 8
82
+ version: 0.1.8
51
83
  type: :development
52
- version_requirements: *id002
53
- description: Guard::Passenger automatically restarts passenger when needed
84
+ version_requirements: *id004
85
+ - !ruby/object:Gem::Dependency
86
+ name: guard-bundler
87
+ prerelease: false
88
+ requirement: &id005 !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ hash: 25
94
+ segments:
95
+ - 0
96
+ - 1
97
+ - 1
98
+ version: 0.1.1
99
+ type: :development
100
+ version_requirements: *id005
101
+ description: Guard::Passenger automatically restarts Passenger when needed.
54
102
  email:
55
103
  - mordaroso@gmail.com
56
104
  executables: []
@@ -60,9 +108,9 @@ extensions: []
60
108
  extra_rdoc_files: []
61
109
 
62
110
  files:
111
+ - lib/guard/passenger/pinger.rb
63
112
  - lib/guard/passenger/runner.rb
64
113
  - lib/guard/passenger/templates/Guardfile
65
- - lib/guard/passenger/toucher.rb
66
114
  - lib/guard/passenger/version.rb
67
115
  - lib/guard/passenger.rb
68
116
  - LICENSE
@@ -1,23 +0,0 @@
1
- require 'net/http'
2
-
3
- module Guard
4
- class Passenger
5
- module Toucher
6
- class << self
7
-
8
- # try recieve header from given url (e.g. http://localhost:3000/) and return false if response status is 500
9
- def touch(host, port, path)
10
- begin
11
- response = nil;
12
- Net::HTTP.start(host, port) do |http|
13
- response = http.head(path)
14
- end
15
- response['status'].to_i != 500
16
- rescue
17
- false
18
- end
19
- end
20
- end
21
- end
22
- end
23
- end