You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@whimsical.apache.org by Sam Ruby <ru...@apache.org> on 2016/02/27 04:08:00 UTC

[whimsy.git] [1/1] Commit 5304fd6: oops, forgot to commit this file

Commit 5304fd617f0a7625b83fae8e7eef6261af884fcc:
    oops, forgot to commit this file


Branch: refs/heads/master
Author: Sam Ruby <ru...@intertwingly.net>
Committer: Sam Ruby <ru...@intertwingly.net>
Pusher: rubys <ru...@apache.org>

------------------------------------------------------------
tools/toucher.rb                                             | +++++++++++ 
------------------------------------------------------------
43 changes: 43 additions, 0 deletions.
------------------------------------------------------------


diff --git a/tools/toucher.rb b/tools/toucher.rb
new file mode 100755
index 0000000..97bd7c9
--- /dev/null
+++ b/tools/toucher.rb
@@ -0,0 +1,43 @@
+#!/usr/bin/ruby
+#
+# Watch for updates to sources to passenger applications, and restart those
+# applications whenever changes occur.
+#
+
+require 'listen'
+require 'fileutils'
+
+watch = Hash.new {|hash, key| hash[key] = []}
+
+Dir["#{File.real_path('/srv/whimsy')}/**/restart.txt"].each do |restart|
+  app = File.expand_path('../..', restart)
+  next unless File.exist? "#{app}/config.ru"
+
+  watch[app] << restart
+
+  if File.exist? "#{app}/Gemfile.lock"
+    paths = File.read("#{app}/Gemfile.lock")[/^PATH.*?\n\n/m].to_s
+    libs = paths.scan(/^\s*remote: (.*)/).flatten.map {|path| path+'/lib'}
+    libs.each {|lib| watch[lib] << restart}
+  end
+end
+
+listener = Listen.to(*watch.keys) do |modified, added, removed|
+  touches = []
+  (modified + added + removed).each do |file|
+    watch.each do |path, restarts|
+      touches += restarts if file.start_with? path + '/'
+    end
+  end
+
+  touches.uniq.each do |restart|
+    FileUtils.touch restart
+  end
+end
+
+listener.ignore /~$/
+listener.ignore /^\..*\.sw\w$/
+listener.ignore /passenger.\d+\.(log|pid(\.lock)?)$/
+
+listener.start
+sleep