Move discourse dev data out of tmp

Fix watch for restart so it works with puma
This commit is contained in:
Sam 2017-05-18 11:36:12 -04:00
parent 4fb335f1f0
commit e7c2ad41ca
4 changed files with 28 additions and 14 deletions

2
.gitignore vendored
View File

@ -10,6 +10,8 @@ dump.rdb
bin/* bin/*
data/
.sass-cache/* .sass-cache/*
public/csv/* public/csv/*
public/plugins/* public/plugins/*

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
SCRIPTPATH=$(cd "$(dirname "$0")"; pwd -P) SCRIPTPATH=$(cd "$(dirname "$0")"; pwd -P)
SOURCE_DIR=$(cd "$SCRIPTPATH" && cd ../.. && pwd -P) SOURCE_DIR=$(cd "$SCRIPTPATH" && cd ../.. && pwd -P)
DATA_DIR="$SOURCE_DIR/tmp/postgres" DATA_DIR="$SOURCE_DIR/data/postgres"
show_help() { show_help() {
cat <<EOF cat <<EOF

View File

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
SCRIPTPATH=$(cd "$(dirname "$0")"; pwd -P) SCRIPTPATH=$(cd "$(dirname "$0")"; pwd -P)
SOURCE_DIR=$(cd "$SCRIPTPATH" && cd ../.. && pwd -P) SOURCE_DIR=$(cd "$SCRIPTPATH" && cd ../.. && pwd -P)
DATA_DIR=$SOURCE_DIR/tmp/postgres DATA_DIR=$SOURCE_DIR/data/postgres
# Should this also run /etc/runit/1.d/ensure_database, or will that # Should this also run /etc/runit/1.d/ensure_database, or will that
# happen automatically? # happen automatically?

View File

@ -5,26 +5,38 @@
# #
# This works fine for Discourse.org cause we host our app accross multiple machines, if you hosting # This works fine for Discourse.org cause we host our app accross multiple machines, if you hosting
# on a single machine you have a trickier problem at hand as you need to cycle the processes in order # on a single machine you have a trickier problem at hand as you need to cycle the processes in order
#
# VIM users rejoice, if you add this to your .vimrc CTRL-a will restart puma:
# nmap <C-a> <Esc>:!touch tmp/restart<CR><CR>
Thread.new do Thread.new do
file = "#{Rails.root}/tmp/restart" file = "#{Rails.root}/tmp/restart"
old_time = File.ctime(file).to_i if File.exists? file old_time = File.ctime(file).to_i if File.exists? file
wait_seconds = 4 wait_seconds = 4
if $PROGRAM_NAME =~ /thin/ if Rails.env.development? && $PROGRAM_NAME =~ /puma/
while true require 'listen'
time = File.ctime(file).to_i if File.exists? file
if old_time != time time = nil
Rails.logger.info "attempting to reload #{$$} #{$PROGRAM_NAME} in #{wait_seconds} seconds"
$shutdown = true begin
sleep wait_seconds listener = Listen.to("#{Rails.root}/tmp", only: /restart/) do
Rails.logger.info "restarting #{$$}"
Process.kill("HUP", $$) time = File.ctime(file).to_i if File.exists? file
break
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 end
listener.start
sleep 1 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 end
end end