2013-02-11 21:44:44 -05:00
|
|
|
rails_env = ENV['RAILS_ENV'] || "production"
|
|
|
|
rails_root = ENV['RAILS_ROOT'] || "/var/rails/my_discourse"
|
|
|
|
|
|
|
|
user = ENV["DISCOURSE_USER"] || ENV['USER'] || 'user_running_app'
|
|
|
|
group = ENV["DISCOURSE_GROUP"] || ENV['GROUP'] || 'www-data'
|
|
|
|
num_webs = ENV["NUM_WEBS"].to_i > 0 ? ENV["NUM_WEBS"].to_i : 4
|
|
|
|
|
|
|
|
# to debug use
|
|
|
|
#Bluepill.application("your_app", :foreground => true) do |app|
|
2013-05-29 00:07:26 -04:00
|
|
|
|
|
|
|
# Running bluepill as a user? Use:
|
|
|
|
Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |app|
|
|
|
|
|
|
|
|
# Running bluepill as root? Use:
|
|
|
|
#Bluepill.application("discourse") do |app|
|
2013-02-11 21:44:44 -05:00
|
|
|
|
|
|
|
app.gid = group
|
|
|
|
app.uid = user
|
|
|
|
|
|
|
|
# getting this to work was a nightmare
|
|
|
|
# bundle exec spawns a process totally messing with the demonize option
|
|
|
|
# so we suck the environment out and set it up first
|
|
|
|
app.environment = `env -i BUNDLE_GEMFILE=#{rails_root}/Gemfile /usr/local/rvm/bin/bootup_bundle exec env`.lines.inject({}) do |env_hash,l|
|
|
|
|
kv = l.chomp.split('=',2)
|
|
|
|
env_hash[kv[0]] = kv[1]
|
|
|
|
env_hash
|
|
|
|
end if File.exist?("/usr/local/rvm/bin/rvm")
|
|
|
|
|
|
|
|
app.environment ||= {}
|
|
|
|
app.environment['RAILS_ENV'] = rails_env
|
|
|
|
|
|
|
|
app.gid = group
|
|
|
|
app.uid = user
|
|
|
|
|
|
|
|
app.working_dir = rails_root
|
2013-05-24 23:25:03 -04:00
|
|
|
sockdir = "#{rails_root}/tmp/sockets"
|
|
|
|
File.directory? sockdir or Dir.mkdir sockdir
|
2013-02-11 21:44:44 -05:00
|
|
|
num_webs.times do |i|
|
|
|
|
app.process("thin-#{i}") do |process|
|
2013-05-24 23:25:03 -04:00
|
|
|
process.start_command = "bundle exec thin start -e production -t 0 --socket #{sockdir}/thin.#{i}.sock -P #{rails_root}/tmp/pids/thin#{i}.pid -d"
|
2013-05-03 10:59:34 -04:00
|
|
|
|
|
|
|
# Alternatively, you can start with a port number instead of a socket. If you do that, then you MUST update
|
|
|
|
# the upstream section in the nginx config to match.
|
|
|
|
# The nginx.sample.conf file assumes you're using sockets.
|
|
|
|
# process.start_command = "bundle exec thin start -e production -t 0 -p #{9040 + i} -P #{rails_root}/tmp/pids/thin#{i}.pid -d"
|
|
|
|
|
2013-02-11 21:44:44 -05:00
|
|
|
process.pid_file = "#{rails_root}/tmp/pids/thin#{i}.pid"
|
|
|
|
process.start_grace_time = 30.seconds
|
|
|
|
process.stop_grace_time = 10.seconds
|
|
|
|
process.restart_grace_time = 10.seconds
|
|
|
|
process.group = "thins"
|
|
|
|
process.uid = user
|
|
|
|
process.gid = group
|
|
|
|
process.daemonize = false
|
|
|
|
process.stdout = process.stderr = "#{rails_root}/log/thin#{i}.log"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
#debug instance
|
2013-05-29 00:07:26 -04:00
|
|
|
# app.process("thin-debug") do |process|
|
|
|
|
# process.start_command = "bundle exec thin start -e development -t 0 -p 10040 -P #{rails_root}/tmp/pids/thin-debug.pid -d"
|
|
|
|
# process.pid_file = "#{rails_root}/tmp/pids/thin-debug.pid"
|
|
|
|
# process.start_grace_time = 30.seconds
|
|
|
|
# process.stop_grace_time = 10.seconds
|
|
|
|
# process.restart_grace_time = 10.seconds
|
|
|
|
# process.group = "thins"
|
|
|
|
# process.uid = user
|
|
|
|
# process.gid = group
|
|
|
|
# process.daemonize = false
|
|
|
|
# process.stdout = process.stderr = "#{rails_root}/log/thin-debug.log"
|
|
|
|
# end
|
2013-02-11 21:44:44 -05:00
|
|
|
|
|
|
|
app.process("sidekiq-worker") do |process|
|
|
|
|
pidfile = "#{rails_root}/tmp/pids/sidekiq-worker.pid"
|
|
|
|
|
|
|
|
process.start_command = "/usr/bin/env PIDFILE=#{pidfile} RAILS_ENV=#{rails_env} bundle exec sidekiq"
|
|
|
|
process.pid_file = pidfile
|
|
|
|
process.start_grace_time = 30.seconds
|
|
|
|
process.stop_grace_time = 10.seconds
|
|
|
|
process.restart_grace_time = 10.seconds
|
|
|
|
process.uid = user
|
|
|
|
process.gid = group
|
|
|
|
process.daemonize = true
|
|
|
|
end
|
|
|
|
|
|
|
|
if `hostname`.strip == "host to run on"
|
|
|
|
app.process("clockwork") do |process|
|
|
|
|
pidfile = "#{rails_root}/tmp/pids/clockwork.pid"
|
|
|
|
|
|
|
|
process.start_command = "/usr/bin/env RAILS_ENV=#{rails_env} bundle exec clockwork config/clock.rb"
|
|
|
|
process.pid_file = pidfile
|
|
|
|
process.start_grace_time = 30.seconds
|
|
|
|
process.stop_grace_time = 10.seconds
|
|
|
|
process.restart_grace_time = 10.seconds
|
|
|
|
process.uid = user
|
|
|
|
process.gid = group
|
|
|
|
process.daemonize = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|