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 CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unicorn-directory-watcher (0.1.2)
4
+ unicorn-directory-watcher (0.1.3)
5
5
  directory_watcher (>= 1.4.0)
6
6
  eventmachine (>= 0.12)
7
7
  rev (>= 0.3.2)
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, :log_dir, :pid_dir
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
- @log_dir = (params[:log_dir] || "#{root_dir}/log").tap do |dir|
18
- FileUtils.mkdir_p(dir)
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.open(pidfile) { |f| f.read }.chomp.to_i
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
- Process.kill :QUIT, master_pid.call # kill unicorn
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
@@ -1,3 +1,3 @@
1
1
  module UnicornDirectoryWatcher
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: unicorn-directory-watcher
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.3
5
+ version: 0.1.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Takita