rerun 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +58 -16
- data/bin/rerun +4 -2
- data/lib/rerun.rb +27 -17
- data/lib/system.rb +4 -2
- data/lib/watcher.rb +1 -1
- data/rerun.gemspec +3 -3
- metadata +3 -3
data/README.md
CHANGED
@@ -9,15 +9,37 @@ Currently only *.rb files are watched, anywhere under the current
|
|
9
9
|
directory (.). This is pretty lame so it will change soon.
|
10
10
|
|
11
11
|
If you're on Mac OS X, it uses the built-in facilities for monitoring
|
12
|
-
the filesystem, so CPU use is very light.
|
12
|
+
the filesystem, so CPU use is very light.
|
13
13
|
|
14
|
-
If you have "growlcmd" available on the PATH, it sends notifications
|
15
|
-
growl in addition to the console.
|
14
|
+
If you have "growlcmd" available on the PATH, it sends notifications
|
15
|
+
to growl in addition to the console.
|
16
|
+
|
17
|
+
# Installation:
|
18
|
+
|
19
|
+
sudo gem install rerun
|
20
|
+
|
21
|
+
or...
|
22
|
+
|
23
|
+
gem sources -a http://gems.github.com/
|
24
|
+
sudo gem install alexch-rerun
|
25
|
+
|
26
|
+
(The github way isn't working yet for some reason. Maybe I have to wait for cron to run or something.)
|
16
27
|
|
17
28
|
# Usage:
|
18
29
|
|
19
30
|
rerun [options] cmd
|
20
31
|
|
32
|
+
For example, if you're running a Sinatra app whose main file is
|
33
|
+
app.rb:
|
34
|
+
|
35
|
+
rerun app.rb
|
36
|
+
|
37
|
+
Or if you're running a Rack app that's configured in config.ru
|
38
|
+
but you want to override its port:
|
39
|
+
|
40
|
+
rerun "thin start --port=4000 -R config.ru"
|
41
|
+
|
42
|
+
|
21
43
|
# Options:
|
22
44
|
|
23
45
|
Only --version and --help so far.
|
@@ -36,26 +58,46 @@ Shotgun: <http://github.com/rtomayko/shotgun>
|
|
36
58
|
|
37
59
|
# Why would I use this instead of Shotgun?
|
38
60
|
|
39
|
-
Shotgun does a "fork" after the web framework has loaded but before
|
40
|
-
loaded. It then loads your app, processes a
|
61
|
+
Shotgun does a "fork" after the web framework has loaded but before
|
62
|
+
your application is loaded. It then loads your app, processes a
|
63
|
+
single request in the child process, then exits the child process.
|
41
64
|
|
42
|
-
Rerun launches the whole app, then when it's time to restart, uses
|
43
|
-
down and starts the whole thing up again from
|
65
|
+
Rerun launches the whole app, then when it's time to restart, uses
|
66
|
+
"kill" to shut it down and starts the whole thing up again from
|
67
|
+
scratch.
|
44
68
|
|
45
|
-
So rerun takes somewhat longer than Shotgun to restart the app, but
|
46
|
-
frequently. And once it's running it behaves more
|
47
|
-
production app.
|
69
|
+
So rerun takes somewhat longer than Shotgun to restart the app, but
|
70
|
+
does it much less frequently. And once it's running it behaves more
|
71
|
+
normally and consistently with your production app.
|
48
72
|
|
49
|
-
Also, Shotgun reloads the app on every request, even if it doesn't
|
50
|
-
fine if you're loading a single file, but my web
|
51
|
-
media) and that adds up quickly.
|
52
|
-
|
73
|
+
Also, Shotgun reloads the app on every request, even if it doesn't
|
74
|
+
need to. This is fine if you're loading a single file, but my web
|
75
|
+
pages all load other files (CSS, JS, media) and that adds up quickly.
|
76
|
+
The developers of shotgun are probably using caching or a front web
|
77
|
+
server so this doesn't affect them too much.
|
53
78
|
|
54
79
|
YMMV!
|
55
80
|
|
56
|
-
#
|
81
|
+
# Why did you write this?
|
82
|
+
|
83
|
+
I've been using [Sinatra](http://sinatrarb.com) and loving it. In
|
84
|
+
order to simplify their system, the Rat Pack just took out
|
85
|
+
auto-reloading. I approve of this: a web application framework should
|
86
|
+
be focused on serving requests, not on munging Ruby ObjectSpace. But
|
87
|
+
I still wanted automatic reloading during development. Shotgun wasn't
|
88
|
+
working for me (see above) so I spliced Rerun together out of .
|
89
|
+
|
90
|
+
# Credits
|
91
|
+
|
92
|
+
Rerun: Alex Chaffee, <mailto:alex@stinky.com>, <http://github.com/alexch/>
|
93
|
+
|
94
|
+
Based upon and/or inspired by:
|
95
|
+
|
96
|
+
Shotgun: <http://github.com/rtomayko/shotgun>
|
97
|
+
|
98
|
+
Rspactor: <http://github.com/mislav/rspactor>
|
57
99
|
|
58
|
-
|
100
|
+
FileSystemWatcher: <http://paulhorman.com/filesystemwatcher/>
|
59
101
|
|
60
102
|
# License
|
61
103
|
|
data/bin/rerun
CHANGED
@@ -5,7 +5,7 @@ require 'rubygems'
|
|
5
5
|
libdir = "#{File.expand_path(File.dirname(File.dirname(__FILE__)))}/lib"
|
6
6
|
$LOAD_PATH.unshift libdir unless $LOAD_PATH.include?(libdir)
|
7
7
|
|
8
|
-
load
|
8
|
+
load "#{libdir}/../rerun.gemspec" # defines "$spec" variable, which we read the version from
|
9
9
|
|
10
10
|
require 'optparse'
|
11
11
|
|
@@ -47,4 +47,6 @@ end
|
|
47
47
|
|
48
48
|
require 'rerun'
|
49
49
|
cmd = ARGV.join(" ")
|
50
|
-
Rerun::Runner.new(cmd, options)
|
50
|
+
runner = Rerun::Runner.new(cmd, options)
|
51
|
+
runner.start
|
52
|
+
runner.join
|
data/lib/rerun.rb
CHANGED
@@ -14,8 +14,10 @@ module Rerun
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def restart
|
17
|
+
@restarting = true
|
17
18
|
stop
|
18
19
|
start
|
20
|
+
@restarting = false
|
19
21
|
end
|
20
22
|
|
21
23
|
def start
|
@@ -24,22 +26,24 @@ module Rerun
|
|
24
26
|
"To infinity... and beyond!",
|
25
27
|
"Charge!",
|
26
28
|
]
|
27
|
-
notify "
|
29
|
+
notify "Launched", taglines[rand(taglines.size)]
|
28
30
|
@already_running = true
|
29
31
|
else
|
30
32
|
taglines = [
|
31
33
|
"Here we go again!",
|
32
34
|
"Once more unto the breach, dear friends, once more!",
|
33
35
|
]
|
34
|
-
notify "
|
36
|
+
notify "Restarted", taglines[rand(taglines.size)]
|
35
37
|
end
|
36
38
|
|
37
39
|
@pid = Kernel.fork do
|
38
|
-
Signal.trap("
|
40
|
+
# Signal.trap("INT") { exit }
|
39
41
|
exec(@run_command)
|
40
42
|
end
|
41
43
|
|
42
|
-
|
44
|
+
Signal.trap("INT") { stop; exit }
|
45
|
+
|
46
|
+
# Process.detach(@pid)
|
43
47
|
|
44
48
|
begin
|
45
49
|
sleep 2
|
@@ -54,18 +58,25 @@ module Rerun
|
|
54
58
|
@already_running = false
|
55
59
|
end
|
56
60
|
|
57
|
-
|
58
|
-
|
61
|
+
unless @watcher
|
62
|
+
watcher_class = osx? ? OSXWatcher : FSWatcher
|
63
|
+
# watcher_class = FSWatcher
|
59
64
|
|
60
|
-
|
61
|
-
|
65
|
+
watcher = watcher_class.new do
|
66
|
+
restart unless @restarting
|
67
|
+
end
|
68
|
+
watcher.add_directory(".", "**/*.rb")
|
69
|
+
watcher.sleep_time = 1
|
70
|
+
watcher.start
|
71
|
+
|
72
|
+
@watcher = watcher
|
62
73
|
end
|
63
|
-
watcher.add_directory(".", "**/*.rb")
|
64
|
-
watcher.sleep_time = 1
|
65
|
-
watcher.start
|
66
|
-
watcher.join
|
67
74
|
|
68
75
|
end
|
76
|
+
|
77
|
+
def join
|
78
|
+
@watcher.join
|
79
|
+
end
|
69
80
|
|
70
81
|
def running?
|
71
82
|
signal(0)
|
@@ -79,11 +90,11 @@ module Rerun
|
|
79
90
|
end
|
80
91
|
|
81
92
|
def stop
|
82
|
-
if @pid && @pid != 0
|
83
|
-
notify "
|
93
|
+
if @pid && (@pid != 0)
|
94
|
+
notify "Stopped", "All good things must come to an end." unless @restarting
|
84
95
|
signal("KILL") && Process.wait(@pid)
|
85
96
|
end
|
86
|
-
rescue
|
97
|
+
rescue => e
|
87
98
|
false
|
88
99
|
end
|
89
100
|
|
@@ -101,8 +112,7 @@ module Rerun
|
|
101
112
|
def notify(title, body)
|
102
113
|
growl title, body if has_growl?
|
103
114
|
puts
|
104
|
-
puts "#{Time.now.strftime("%T")} - #{app_name} #{title}
|
105
|
-
puts
|
115
|
+
puts "#{Time.now.strftime("%T")} - #{app_name} #{title}"
|
106
116
|
end
|
107
117
|
|
108
118
|
end
|
data/lib/system.rb
CHANGED
@@ -28,8 +28,10 @@ module Rerun
|
|
28
28
|
File.expand_path(".").gsub(/^.*\//, '').capitalize
|
29
29
|
end
|
30
30
|
|
31
|
-
def growl(title, body)
|
32
|
-
|
31
|
+
def growl(title, body, background = true)
|
32
|
+
s = "#{growlcmd} -n \"#{app_name}\" -m \"#{body}\" \"#{app_name} #{title}\""
|
33
|
+
s += " &" if background
|
34
|
+
`#{s}`
|
33
35
|
end
|
34
36
|
|
35
37
|
end
|
data/lib/watcher.rb
CHANGED
@@ -149,6 +149,7 @@ module Rerun
|
|
149
149
|
else
|
150
150
|
# see if we have found this file already
|
151
151
|
found_file = @found[full_file_name]
|
152
|
+
@found[full_file_name] = FoundFile.new(full_file_name, mod_time, size)
|
152
153
|
|
153
154
|
if found_file
|
154
155
|
if mod_time > found_file.mod_time || size != found_file.size then
|
@@ -157,7 +158,6 @@ module Rerun
|
|
157
158
|
else
|
158
159
|
@client_callback.call(CREATED, full_file_name)
|
159
160
|
end
|
160
|
-
@found[full_file_name] = FoundFile.new(full_file_name, mod_time, size)
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
data/rerun.gemspec
CHANGED
@@ -3,8 +3,8 @@ $spec = Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'rerun'
|
6
|
-
s.version = '0.2'
|
7
|
-
s.date = '2009-06-
|
6
|
+
s.version = '0.2.1'
|
7
|
+
s.date = '2009-06-16'
|
8
8
|
|
9
9
|
s.description = "Restarts your app when a file changes"
|
10
10
|
s.summary = "Launches an app, and restarts it whenever the filesystem changes."
|
@@ -33,6 +33,6 @@ $spec = Gem::Specification.new do |s|
|
|
33
33
|
|
34
34
|
s.homepage = "http://github.com/alexch/rerun/"
|
35
35
|
s.require_paths = %w[lib]
|
36
|
-
|
36
|
+
s.rubyforge_project = 'pivotalrb'
|
37
37
|
s.rubygems_version = '1.1.1'
|
38
38
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rerun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Chaffee
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -55,7 +55,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
55
55
|
version:
|
56
56
|
requirements: []
|
57
57
|
|
58
|
-
rubyforge_project:
|
58
|
+
rubyforge_project: pivotalrb
|
59
59
|
rubygems_version: 1.3.3
|
60
60
|
signing_key:
|
61
61
|
specification_version: 2
|