mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-05-02 08:54:02 -04:00
add unicorn launcher to support live reloads
add oobgc rudimentary support
This commit is contained in:
parent
e9f9d22482
commit
0e8914cee6
4 changed files with 69 additions and 1 deletions
config
|
@ -6,7 +6,7 @@ enabled = if Rails.configuration.respond_to?(:enable_anon_caching)
|
||||||
Rails.env.production?
|
Rails.env.production?
|
||||||
end
|
end
|
||||||
|
|
||||||
if enabled
|
if !ENV['DISCOURSE_DISABLE_ANON_CACHE'] && enabled
|
||||||
Rails.configuration.middleware.insert 0, Middleware::AnonymousCache
|
Rails.configuration.middleware.insert 0, Middleware::AnonymousCache
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
4
config/initializers/99-unicorn.rb
Normal file
4
config/initializers/99-unicorn.rb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
if (oobgc=ENV['UNICORN_OOBGC_REQS'].to_i) > 0
|
||||||
|
require 'unicorn/oob_gc'
|
||||||
|
Rails.configuration.middleware.insert 0, Unicorn::OobGC, oobgc
|
||||||
|
end
|
|
@ -1,5 +1,8 @@
|
||||||
# See http://unicorn.bogomips.org/Unicorn/Configurator.html
|
# See http://unicorn.bogomips.org/Unicorn/Configurator.html
|
||||||
|
|
||||||
|
# RUN out of band GC every 2 requests
|
||||||
|
# ENV['UNICORN_OOBGC_REQS'] = "2" unless ENV['UNICORN_OOBGC_REQS']
|
||||||
|
|
||||||
discourse_path = File.expand_path(File.expand_path(File.dirname(__FILE__)) + "/../")
|
discourse_path = File.expand_path(File.expand_path(File.dirname(__FILE__)) + "/../")
|
||||||
|
|
||||||
# tune down if not enough ram
|
# tune down if not enough ram
|
||||||
|
@ -39,8 +42,30 @@ before_fork do |server, worker|
|
||||||
unless initialized
|
unless initialized
|
||||||
# load up the yaml for the localization bits, in master process
|
# load up the yaml for the localization bits, in master process
|
||||||
I18n.t(:posts)
|
I18n.t(:posts)
|
||||||
|
|
||||||
|
# load up all models and schema
|
||||||
|
(ActiveRecord::Base.connection.tables - %w[schema_migrations]).each do |table|
|
||||||
|
table.classify.constantize.first rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
# get rid of rubbish so we don't share it
|
# get rid of rubbish so we don't share it
|
||||||
GC.start
|
GC.start
|
||||||
|
|
||||||
|
initialized = true
|
||||||
|
|
||||||
|
supervisor = ENV['UNICORN_SUPERVISOR_PID'].to_i
|
||||||
|
if supervisor > 0
|
||||||
|
Thread.new do
|
||||||
|
while true
|
||||||
|
unless File.exists?("/proc/#{supervisor}")
|
||||||
|
puts "Kill self supervisor is gone"
|
||||||
|
Process.kill "TERM", Process.pid
|
||||||
|
end
|
||||||
|
sleep 2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
ActiveRecord::Base.connection.disconnect!
|
ActiveRecord::Base.connection.disconnect!
|
||||||
|
|
39
config/unicorn_launcher
Executable file
39
config/unicorn_launcher
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# This is a helper script you can use to supervise unicorn, it allows you to perform a live restart
|
||||||
|
# by sending it a USR2 signal
|
||||||
|
|
||||||
|
LOCAL_WEB="http://127.0.0.1:3000/"
|
||||||
|
|
||||||
|
function on_exit()
|
||||||
|
{
|
||||||
|
kill $UNICORN_PID
|
||||||
|
echo "exiting"
|
||||||
|
}
|
||||||
|
|
||||||
|
function on_reload()
|
||||||
|
{
|
||||||
|
echo "Reloading unicorn"
|
||||||
|
kill -s USR2 $UNICORN_PID
|
||||||
|
sleep 10
|
||||||
|
curl $LOCAL_WEB &> /dev/null
|
||||||
|
NEW_UNICORN_PID=`ps -f --ppid $UNICORN_PID | grep unicorn | grep -v worker | awk '{ print $2 }'`
|
||||||
|
kill $UNICORN_PID
|
||||||
|
echo "Old pid is: $UNICORN_PID New pid is: $NEW_UNICORN_PID"
|
||||||
|
UNICORN_PID=$NEW_UNICORN_PID
|
||||||
|
}
|
||||||
|
|
||||||
|
export UNICORN_SUPERVISOR_PID=$$
|
||||||
|
|
||||||
|
trap on_exit EXIT
|
||||||
|
trap on_reload USR2
|
||||||
|
|
||||||
|
unicorn -c $1 &
|
||||||
|
UNICORN_PID=$!
|
||||||
|
|
||||||
|
echo "supervisor pid: $UNICORN_SUPERVISOR_PID unicorn pid: $UNICORN_PID"
|
||||||
|
|
||||||
|
while [ -e /proc/$UNICORN_PID ]
|
||||||
|
do
|
||||||
|
sleep 0.1
|
||||||
|
done
|
Loading…
Add table
Add a link
Reference in a new issue