diff --git a/config/application.rb b/config/application.rb index f216f28..ec53664 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,49 +1,50 @@ require File.expand_path('../boot', __FILE__) require 'rails/all' # Production doesn't use bundler # you've limited to :test, :development, or :production. if ENV['RAILS_ENV'] != 'production' Bundler.require(*Rails.groups) else # Dependencies to load before starting rails in production require 'jquery-rails' + require 'beaneater' end module Baas def self.settings opts = nil @settings ||= {} return @settings if opts.nil? @settings.merge! opts @settings end class Application < Rails::Application # Settings in config/environments/* take precedence over those specified here. # Application configuration should go into files in config/initializers # -- all .rb files in that directory are automatically loaded. # Store/Read localtime from the database config.time_zone = 'Athens' config.active_record.default_timezone = :local # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] # config.i18n.default_locale = :de config.autoload_paths << Rails.root.join('lib') # config.x = {} end # def self.settings # Application.config.x # end def self.bean @bean ||= Bean::Client.new( YAML.load_file(Rails.root.join('config', 'beanstalk.yml'))[Rails.env].symbolize_keys[:host] ) end end diff --git a/config/deploy.rb b/config/deploy.rb index 1ec0a16..bd0fb59 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,33 +1,23 @@ # config valid only for Capistrano 3.1 lock '3.2.1' -set :application, 'webdns' -set :repo_url, 'git@bitbucket.org:xlembouras/webns.git' +set :application, 'archiving' +set :repo_url, 'git@bitbucket.org:xlembouras/baas.git' -set :deploy_to, '/srv/webdns' +set :deploy_to, '/srv/archiving' set :linked_files, %w(config/database.yml config/secrets.yml) set :linked_dirs, %w(log tmp/pids tmp/cache tmp/sockets) set :keep_releases, 5 namespace :deploy do desc 'Restart application' task :restart do on roles(:app), in: :sequence, wait: 5 do - # Your restart mechanism here, for example: - # execute :touch, release_path.join('tmp/restart.txt') + execute 'sudo unicornctl respawn' end end after :publishing, :restart - - after :restart, :clear_cache do - on roles(:web), in: :groups, limit: 3, wait: 10 do - # Here we can do anything such as: - # within release_path do - # execute :rake, 'cache:clear' - # end - end - end end diff --git a/config/deploy/staging.rb b/config/deploy/staging.rb index 757be32..a05fe8c 100644 --- a/config/deploy/staging.rb +++ b/config/deploy/staging.rb @@ -1,5 +1,5 @@ set :rails_env, :production -server 'webdns-edet4.grnet.gr', user: 'webdns', roles: %w(web app db) +server 'baas-edet4.grnet.gr', user: 'archiving', roles: %w(web app db) set :ssh_options, forward_agent: false diff --git a/unicorn.conf.rb b/unicorn.conf.rb new file mode 100644 index 0000000..45d2541 --- /dev/null +++ b/unicorn.conf.rb @@ -0,0 +1,25 @@ +listen ENV['UNICORN_LISTEN'] +working_directory ENV['APP_ROOT'] +worker_processes ENV['UNICORN_WORKERS'].to_i +pid ENV['UNICORN_PIDFILE'] + +preload_app true + +before_fork do |server, worker| + ActiveRecord::Base.connection.disconnect! + + old_pid = "#{server.config[:pid]}.oldbin" + if old_pid != server.pid + begin + sig = (worker.nr + 1) >= server.worker_processes ? :QUIT : :TTOU + Process.kill(sig, File.read(old_pid).to_i) + rescue Errno::ENOENT, Errno::ESRCH + end + end + + sleep 1 +end + +after_fork do |server, worker| + ActiveRecord::Base.establish_connection +end