guard-passenger 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -3
- data/lib/guard/passenger.rb +79 -25
- data/lib/guard/passenger/pinger.rb +10 -6
- data/lib/guard/passenger/runner.rb +21 -21
- data/lib/guard/passenger/templates/Guardfile +2 -2
- data/lib/guard/passenger/version.rb +1 -1
- metadata +6 -6
data/README.rdoc
CHANGED
@@ -49,11 +49,11 @@ If the ping responds with a non-5XX response, Passenger is considered as running
|
|
49
49
|
Guard::Passenger accepts some options for configuration.
|
50
50
|
|
51
51
|
# :standalone boolean run Passenger standalone (default: true)
|
52
|
-
# :
|
53
|
-
# :
|
52
|
+
# :cli string options to pass to passenger command (default: '--daemonize')
|
53
|
+
# :notification boolean Notifications enabled (default: true)
|
54
54
|
# :ping boolean or string ping localhost after Passenger restart (default: false)
|
55
55
|
|
56
|
-
guard 'passenger', :standalone => false, :
|
56
|
+
guard 'passenger', :standalone => false, :cli => '--daemonize --port 3001 --address my_app.local --environment production', :ping => '/foo' do
|
57
57
|
end
|
58
58
|
|
59
59
|
== Development
|
data/lib/guard/passenger.rb
CHANGED
@@ -4,25 +4,29 @@ require 'rubygems'
|
|
4
4
|
|
5
5
|
module Guard
|
6
6
|
class Passenger < Guard
|
7
|
-
|
7
|
+
|
8
8
|
autoload :Runner, 'guard/passenger/runner'
|
9
9
|
autoload :Pinger, 'guard/passenger/pinger'
|
10
|
-
|
11
|
-
attr_reader :
|
12
|
-
|
10
|
+
|
11
|
+
attr_reader :cli_start, :cli_stop, :ping, :notification
|
12
|
+
|
13
13
|
def standalone?
|
14
14
|
@standalone
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
# =================
|
18
18
|
# = Guard methods =
|
19
19
|
# =================
|
20
|
-
|
20
|
+
|
21
21
|
def initialize(watchers = [], options = {})
|
22
22
|
super
|
23
|
-
|
24
|
-
|
25
|
-
@
|
23
|
+
|
24
|
+
warn_deprectation options
|
25
|
+
@standalone = options[:standalone].nil? ? true : options[:standalone]
|
26
|
+
@cli_start = init_cli(options)
|
27
|
+
@cli_stop = cli_stop
|
28
|
+
@notification = options[:notification].nil? ? true : options[:notification]
|
29
|
+
|
26
30
|
ping_opt = unless options[:touch].nil?
|
27
31
|
UI.info "Warning: The :touch option has been replaced by the :ping option, usage is still the same."
|
28
32
|
options[:touch]
|
@@ -31,37 +35,87 @@ module Guard
|
|
31
35
|
end
|
32
36
|
@ping = ping_opt.eql?(true) ? '/' : ping_opt
|
33
37
|
end
|
34
|
-
|
38
|
+
|
35
39
|
# Call once when guard starts
|
36
40
|
def start
|
37
41
|
UI.info 'Guard::Passenger is running!'
|
38
|
-
standalone? ? Runner.start_passenger(
|
42
|
+
standalone? ? Runner.start_passenger(cli_start) : true
|
39
43
|
end
|
40
|
-
|
44
|
+
|
41
45
|
# Call with Ctrl-C signal (when Guard quit)
|
42
46
|
def stop
|
43
47
|
UI.info 'Stopping Passenger...'
|
44
|
-
|
48
|
+
Runner.stop_passenger(cli_stop) if standalone?
|
49
|
+
true
|
45
50
|
end
|
46
|
-
|
51
|
+
|
47
52
|
# Call with Ctrl-Z signal
|
48
53
|
def reload
|
49
54
|
restart_and_ping
|
50
55
|
end
|
51
|
-
|
56
|
+
|
52
57
|
# Call on file(s) modifications
|
53
58
|
def run_on_change(paths = {})
|
54
59
|
restart_and_ping
|
55
60
|
end
|
56
|
-
|
61
|
+
|
57
62
|
private
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
|
64
|
+
def init_cli options={}
|
65
|
+
cmd_parts = []
|
66
|
+
cmd_parts << (options[:cli].nil? ? '--daemonize' : options[:cli])
|
67
|
+
cmd_parts << "--port #{options[:port]}" if options[:port] #DEPRICATED
|
68
|
+
cmd_parts << "--environment #{options[:env]}" if options[:env] #DEPRICATED
|
69
|
+
cmd_parts.join(' ')
|
70
|
+
end
|
71
|
+
|
72
|
+
def cli_stop
|
73
|
+
cmd_parts = []
|
74
|
+
cmd_parts << "--port #{port}" if port != 3000
|
75
|
+
cmd_parts << "--pid_file #{pid_file}" if pid_file
|
76
|
+
cmd_parts.join(' ')
|
77
|
+
end
|
78
|
+
|
79
|
+
def port
|
80
|
+
if cli_start =~ /(?:-p|--port)/
|
81
|
+
cli_start.match(/(?:-p|--port) ([^ ]+)/)[1]
|
82
|
+
else
|
83
|
+
'3000'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def address
|
88
|
+
if cli_start =~ /(?:-a|--address)/
|
89
|
+
cli_start.match(/(?:-a|--address) ([^ ]+)/)[1]
|
90
|
+
else
|
91
|
+
'0.0.0.0'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def pid_file
|
96
|
+
if cli_start =~ /(--pid-file)/
|
97
|
+
cli_start.match(/--pid-file ([^ ]+)/)[1]
|
98
|
+
else
|
99
|
+
nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def restart_and_ping
|
104
|
+
UI.info 'Restarting Passenger...'
|
105
|
+
restarted = Runner.restart_passenger
|
106
|
+
Pinger.ping(address, port, notification, ping) if ping
|
107
|
+
restarted
|
108
|
+
end
|
109
|
+
|
110
|
+
def warn_deprectation(options={})
|
111
|
+
options[:environment] = options[:env] if options[:env]
|
112
|
+
[:port, :environment].each do |option|
|
113
|
+
key, value = [option, option.to_s.gsub('_', '-')]
|
114
|
+
if options.key?(key)
|
115
|
+
UI.info "DEPRECATION WARNING: The :#{key} option is deprecated. Pass standard command line argument \"--#{value}\" to Passenger with the :cli option."
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
66
120
|
end
|
67
|
-
end
|
121
|
+
end
|
@@ -8,18 +8,22 @@ module Guard
|
|
8
8
|
# try to ping given url (e.g. http://localhost:3000/) and display a message to inform of the result
|
9
9
|
# failure == response status is 5xx
|
10
10
|
# otherwise, it's a success
|
11
|
-
def ping(host, port, path = '/')
|
11
|
+
def ping(host, port, notification, path = '/')
|
12
12
|
path = "/#{path}" unless path.match(/^\//)
|
13
13
|
ping_in_thread = Thread.start {
|
14
14
|
begin
|
15
15
|
response = Net::HTTP.start(host, port) do |http|
|
16
16
|
http.head(path)
|
17
17
|
end
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
|
19
|
+
if notification
|
20
|
+
if response.is_a? Net::HTTPServerError
|
21
|
+
Notifier.notify("Passenger is not running!", :title => "Passenger", :image => :failed)
|
22
|
+
else
|
23
|
+
Notifier.notify("Passenger is running.", :title => "Passenger", :image => :success)
|
24
|
+
end
|
22
25
|
end
|
26
|
+
|
23
27
|
rescue
|
24
28
|
# do nothing
|
25
29
|
end
|
@@ -29,4 +33,4 @@ module Guard
|
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
32
|
-
end
|
36
|
+
end
|
@@ -2,24 +2,24 @@ module Guard
|
|
2
2
|
class Passenger
|
3
3
|
module Runner
|
4
4
|
class << self
|
5
|
-
|
5
|
+
|
6
6
|
def restart_passenger
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
14
14
|
end
|
15
|
-
|
16
|
-
def start_passenger(
|
15
|
+
|
16
|
+
def start_passenger(cli)
|
17
17
|
if passenger_standalone_installed?
|
18
|
-
succeed = system("passenger start
|
18
|
+
succeed = system("passenger start #{cli}")
|
19
19
|
if succeed
|
20
|
-
UI.info "Passenger standalone
|
20
|
+
UI.info "Passenger standalone started."
|
21
21
|
else
|
22
|
-
UI.error "Passenger standalone
|
22
|
+
UI.error "Passenger standalone failed to start!"
|
23
23
|
end
|
24
24
|
succeed
|
25
25
|
else
|
@@ -27,17 +27,17 @@ module Guard
|
|
27
27
|
false
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
31
|
-
def stop_passenger(
|
32
|
-
succeed = system("passenger stop
|
30
|
+
|
31
|
+
def stop_passenger(cli)
|
32
|
+
succeed = system("passenger stop #{cli}")
|
33
33
|
if succeed
|
34
|
-
UI.info "Passenger standalone
|
34
|
+
UI.info "Passenger standalone stopped."
|
35
35
|
else
|
36
|
-
UI.error "Passenger standalone
|
36
|
+
UI.error "Passenger standalone failed to stop!"
|
37
37
|
end
|
38
38
|
succeed
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
def passenger_standalone_installed?
|
42
42
|
begin
|
43
43
|
gem "passenger", ">=3.0.0"
|
@@ -46,8 +46,8 @@ module Guard
|
|
46
46
|
end
|
47
47
|
true
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
53
|
-
end
|
53
|
+
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 3
|
9
|
+
- 0
|
10
|
+
version: 0.3.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: 2011-
|
18
|
+
date: 2011-03-02 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -146,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
requirements: []
|
147
147
|
|
148
148
|
rubyforge_project: guard-passenger
|
149
|
-
rubygems_version: 1.
|
149
|
+
rubygems_version: 1.5.0
|
150
150
|
signing_key:
|
151
151
|
specification_version: 3
|
152
152
|
summary: Guard gem for Passenger
|