unicorn-directory-watcher 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/unicorn_directory_watcher.rb +7 -16
- data/lib/unicorn_directory_watcher/version.rb +1 -1
- metadata +1 -1
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -18,6 +18,7 @@ Unicorn wrapper that restarts the server when a file changes (inspired by http:/
|
|
18
18
|
UnicornDirectoryWatcher.call(
|
19
19
|
app_name,
|
20
20
|
root_dir,
|
21
|
+
:pid_file => "#{root_dir}/tmp/pids/unicorn.pid",
|
21
22
|
:watcher_globs => {
|
22
23
|
root_dir => "{app,lib,services,vendor}/**/*.rb"
|
23
24
|
}
|
@@ -7,18 +7,15 @@ module UnicornDirectoryWatcher
|
|
7
7
|
end
|
8
8
|
|
9
9
|
class Runner
|
10
|
-
attr_reader :app_name, :root_dir, :watcher_globs, :
|
10
|
+
attr_reader :app_name, :root_dir, :watcher_globs, :pid_file
|
11
11
|
|
12
12
|
def initialize(app_name, root_dir, params={})
|
13
13
|
@app_name, @root_dir = app_name, root_dir
|
14
14
|
@watcher_globs = params[:watcher_globs] || {
|
15
15
|
root_dir => "{app,lib,vendor}/**/*.rb"
|
16
16
|
}
|
17
|
-
@
|
18
|
-
FileUtils.mkdir_p(
|
19
|
-
end
|
20
|
-
@pid_dir = (params[:pid_dir] || "#{root_dir}/tmp/pids").tap do |dir|
|
21
|
-
FileUtils.mkdir_p(dir)
|
17
|
+
@pid_file = (params[:pid_file] || "#{root_dir}/tmp/pids/unicorn.pid").tap do |pid_file|
|
18
|
+
FileUtils.mkdir_p File.dirname(File.expand_path(pid_file))
|
22
19
|
end
|
23
20
|
end
|
24
21
|
|
@@ -32,11 +29,8 @@ module UnicornDirectoryWatcher
|
|
32
29
|
# start the unicorn
|
33
30
|
yield(self)
|
34
31
|
|
35
|
-
# get the pid
|
36
|
-
system "touch #{pidfile}"
|
37
|
-
|
38
32
|
master_pid = lambda do
|
39
|
-
File.
|
33
|
+
File.exists?(pid_file) ? File.read(pid_file).strip.to_i : nil
|
40
34
|
end
|
41
35
|
|
42
36
|
directory_watchers = watcher_globs.map do |dir, glob|
|
@@ -64,7 +58,9 @@ module UnicornDirectoryWatcher
|
|
64
58
|
|
65
59
|
# wrap this in a lambda, just to avoid repeating it
|
66
60
|
stop = lambda { |sig|
|
67
|
-
|
61
|
+
master_pid.call.tap do |pid|
|
62
|
+
Process.kill :QUIT, pid if pid
|
63
|
+
end
|
68
64
|
directory_watchers.each do |dw|
|
69
65
|
dw.stop
|
70
66
|
end
|
@@ -78,10 +74,5 @@ module UnicornDirectoryWatcher
|
|
78
74
|
end
|
79
75
|
sleep
|
80
76
|
end
|
81
|
-
|
82
|
-
protected
|
83
|
-
def pidfile
|
84
|
-
"#{pid_dir}/unicorn.pid"
|
85
|
-
end
|
86
77
|
end
|
87
78
|
end
|