Project 32 adding a restart unicorn method module Divergence class Helpers def initialize(config) @config = config end def execute(block, opts={}) self.instance_exec opts, &block end private def bundle_install(opts={}) Application.log.debug "bundle install" begin cmd = 'bundle install' cmd << ' --deployment' if opts[:deployment] cmd << " --path #{opts[:path]}" if opts[:path] cmd << ' --without development test' result = `#{cmd}` Application.log.debug result rescue Application.log.error "bundle install failed!" Application.log.error e.message end end def restart_passenger Application.log.debug "Restarting passenger..." begin unless File.exists? 'tmp' FileUtils.mkdir_p 'tmp' end FileUtils.touch 'tmp/restart.txt' rescue end end def restart_unicorn Application.log.debug "Restarting unicorn..." begin unicorn_pid_file = File.join(config.app_path, "tmp/pids/unicorn.pid") cmd = "cat #{unicorn_pid_file} | xargs kill -USR2" result = `#{cmd}` Application.log.debug result rescue end end end end Proect 33 Convert page 404 into url page module Divergence class Application < Rack::Proxy def call(env) @req = RequestParser.new(env, @g) # First, lets find out what subdomain/git branch # we're dealing with (if any). unless @req.has_subdomain? # No subdomain, simply proxy the request. return perform_request(env) end # Ask our GitManager to prepare the directory # for the given branch. result = @g.prepare_directory @req.branch if result === false return error! end # And then perform the codebase swap @g.swap! fix_environment!(env) # Git is finished, pass the request through. status, header, body = perform_request(env) # This is super weird. Not sure why there is a status # header coming through, but Rack::Lint complains about # it, so we just remove it. if header.has_key?('Status') header.delete 'Status' end [status, header, body] end private def fix_environment!(env) env["HTTP_HOST"] = "#{config.forward_host}:#{config.forward_port}" end def error! Application.log.error "Branch #{@req.branch} does not exist" Application.log.error @req.raw public_path = File.expand_path('../../../public', __FILE__) file = File.open("#{public_path}/404.html", "r") contents = file.read file.close [404, {"Content-Type" => "text/html"}, [contents]] end end end second loop require 'divergence' require ::File.expand_path('../config/config', __FILE__) run Divergence::Application.new()
Stars
2
Forks
2
Watchers
2
Open Issues
0
Overall repository health assessment
No language data available
No package.json found
This might not be a Node.js project
1
commits