From e7c2ad41ca7a3294b5434bbaed18002291ff87ec Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 18 May 2017 11:36:12 -0400 Subject: [PATCH] Move discourse dev data out of tmp Fix watch for restart so it works with puma --- .gitignore | 2 ++ bin/docker/boot_dev | 2 +- bin/docker/reset_db | 2 +- config/initializers/100-watch_for_restart.rb | 36 +++++++++++++------- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 25f45fa7f7d..1f4280195ad 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,8 @@ dump.rdb bin/* +data/ + .sass-cache/* public/csv/* public/plugins/* diff --git a/bin/docker/boot_dev b/bin/docker/boot_dev index ede7eeafa23..30b721cef2d 100755 --- a/bin/docker/boot_dev +++ b/bin/docker/boot_dev @@ -1,7 +1,7 @@ #!/bin/bash SCRIPTPATH=$(cd "$(dirname "$0")"; pwd -P) SOURCE_DIR=$(cd "$SCRIPTPATH" && cd ../.. && pwd -P) -DATA_DIR="$SOURCE_DIR/tmp/postgres" +DATA_DIR="$SOURCE_DIR/data/postgres" show_help() { cat < :!touch tmp/restart Thread.new do file = "#{Rails.root}/tmp/restart" old_time = File.ctime(file).to_i if File.exists? file wait_seconds = 4 - if $PROGRAM_NAME =~ /thin/ - while true - time = File.ctime(file).to_i if File.exists? file + if Rails.env.development? && $PROGRAM_NAME =~ /puma/ + require 'listen' - if old_time != time - Rails.logger.info "attempting to reload #{$$} #{$PROGRAM_NAME} in #{wait_seconds} seconds" - $shutdown = true - sleep wait_seconds - Rails.logger.info "restarting #{$$}" - Process.kill("HUP", $$) - break + time = nil + + begin + listener = Listen.to("#{Rails.root}/tmp", only: /restart/) do + + time = File.ctime(file).to_i if File.exists? file + + if old_time != time + Rails.logger.info "attempting to reload #{$$} #{$PROGRAM_NAME} in #{wait_seconds} seconds" + $shutdown = true + sleep wait_seconds + Rails.logger.info "restarting #{$$}" + Process.kill("USR2", $$) + end end - - sleep 1 + listener.start + sleep + rescue => e + puts "Failed to watch for restart, this probably means the old postgres directory is in tmp, remove it #{e}" end end end