Guest User

Untitled

a guest
Mar 30th, 2014
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 4.56 KB | None | 0 0
  1. # encoding: utf-8
  2. rails_env   = "production"
  3. rails_root  = ENV['RAILS_ROOT'] || "/var/www/adrian/forum.bassmusic.io/discourse"
  4. socket_dir = "/var/www/adrian/forum.bassmusic.io/sockets"
  5.  
  6. user = ENV["DISCOURSE_USER"] || ENV['USER'] || 'adrian'
  7. group = ENV["DISCOURSE_GROUP"] || ENV['GROUP'] || 'www-data'
  8. num_webs = ENV["NUM_WEBS"].to_i > 0 ? ENV["NUM_WEBS"].to_i : 4
  9.  
  10. # to debug use
  11. Bluepill.application("bassmusic", :foreground => true) do |app|
  12.  
  13. # Running bluepill as a user? Use:
  14. Bluepill.application("discourse", :base_dir => ENV["HOME"] + '/.bluepill') do |app|
  15.  
  16. # Running bluepill as root? Use:
  17. #Bluepill.application("discourse") do |app|
  18.  
  19.   # getting this to work was a nightmare
  20.   # bundle exec spawns a process totally messing with the demonize option
  21.   # so we suck the environment out and set it up first
  22.   bootup_bundle = [ "#{ENV['HOME']}/.rvm/bin/rvm/bootup_bundle",
  23.                     "/usr/local/rvm/bin/rvm/bootup_bundle",
  24.                     `which bootup_bundle`.strip,
  25.                   ].each do |location|
  26.     if File.exist? location
  27.       break location
  28.     end
  29.   end
  30.   # XXX if none match, bootup_bundle is set to the array
  31.  
  32.   if bootup_bundle
  33.     app.environment = `env -i BUNDLE_GEMFILE=#{rails_root}/Gemfile #{bootup_bundle} exec env`.lines.inject({}) do |env_hash,l|
  34.       kv = l.chomp.split('=',2)
  35.       env_hash[kv[0]] = kv[1]
  36.       env_hash
  37.     end
  38.   end
  39.  
  40.   app.environment ||= {}
  41.  
  42.   # Load .env file if there is one
  43.   if File.exist? "#{rails_root}/.env"
  44.     File.read("#{rails_root}/.env").split("\n").each do |l|
  45.       kv = l.chomp.split('=',2)
  46.       app.environment[kv[0]] = kv[1]
  47.     end
  48.   end
  49.  
  50.   # Force RAILS_ENV to the value specified in the environment of the bluepill invocation
  51.   app.environment['RAILS_ENV'] = rails_env
  52.  
  53.   app.gid = group
  54.   app.uid = user
  55.  
  56.   app.working_dir = rails_root
  57.   sockdir = "#{rails_root}/tmp/sockets"
  58.   File.directory? sockdir or FileUtils.mkdir_p sockdir
  59.  
  60.   # Discourse is set to use Thin as its WebServer, here is its running scripts.
  61.   num_webs.times do |i|
  62.     app.process("thin-#{i}") do |process|
  63.       process.start_command  = "bundle exec thin start -e production -t 0 --socket #{sockdir}/thin.#{i}.sock --pid #{rails_root}/tmp/pids/thin-#{i}.pid --log #{rails_root}/log/thin-#{i}.log --daemonize"
  64.  
  65.       process.stop_command  = "bundle exec thin stop --pid #{rails_root}/tmp/pids/thin-#{i}.pid"
  66.  
  67.       # Alternatively, you can start with a port number instead of a socket. If you do that, then you MUST update
  68.       # the upstream section in the nginx config to match.
  69.       # The nginx.sample.conf file assumes you're using sockets.
  70.       # process.start_command  = "bundle exec thin start -e production -t 0 -p #{9040 + i} -P #{rails_root}/tmp/pids/thin-#{i}.pid -d"
  71.  
  72.       process.pid_file = "#{rails_root}/tmp/pids/thin-#{i}.pid"
  73.  
  74.       process.start_grace_time = 30.seconds
  75.       process.stop_grace_time = 30.seconds
  76.       process.restart_grace_time = 10.seconds
  77.      
  78.       process.group = "thins"
  79.       process.uid = user
  80.       process.gid = group
  81.      
  82.       process.daemonize = false
  83.       process.stdout = process.stderr = "#{rails_root}/log/thin-#{i}.log"
  84.      
  85.       # Thanks to: http://www.garrensmith.com/2012/09/24/Staying-up-with-Unicorn-Upstart-Bluepill.html
  86.       # If the amount of memory is exceeded 3 times out of 5, restart
  87.       process.checks :mem_usage, :every => 1.minutes, :below => 750.megabytes, :times => [3, 5]
  88.     end
  89.   end
  90.  
  91. #debug instance
  92. #    app.process("thin-debug") do |process|
  93. #      process.start_command  = "bundle exec thin start -e development -t 0 -p 10040 -P #{rails_root}/tmp/pids/thin-debug.pid -l #{rails_root}/log/thin-debug.log" -d"
  94. #      process.pid_file = "#{rails_root}/tmp/pids/thin-debug.pid"
  95. #      process.start_grace_time = 30.seconds
  96. #      process.stop_grace_time = 10.seconds
  97. #      process.restart_grace_time = 10.seconds
  98. #      process.group = "thins"
  99. #      process.uid = user
  100. #      process.gid = group
  101. #      process.daemonize = false
  102. #      process.stdout = process.stderr = "#{rails_root}/log/thin-debug.log"
  103. #    end
  104.  
  105.   app.process("sidekiq-worker") do |process|
  106.     pidfile = "#{rails_root}/tmp/pids/sidekiq-worker.pid"
  107.  
  108.     process.start_command  = "/usr/bin/env PIDFILE=#{pidfile} RAILS_ENV=#{rails_env} bundle exec sidekiq -L #{rails_root}/log/sidekiq.log"
  109.     process.pid_file = pidfile
  110.     process.start_grace_time = 30.seconds
  111.     process.stop_grace_time = 10.seconds
  112.     process.restart_grace_time = 10.seconds
  113.     process.uid = user
  114.     process.gid = group
  115.     process.daemonize = true
  116.   end
  117.  
  118. end
Advertisement
Add Comment
Please, Sign In to add comment