├── .gitignore ├── README.md ├── app └── assets │ ├── javascripts │ └── application.js │ └── stylesheets │ └── application.css.scss ├── app_template.rb └── config ├── application.yml ├── initializers ├── errbit.rb ├── redis.rb └── settings.rb ├── mysql └── database.yml ├── newrelic.yml ├── postgresql └── database.yml └── unicorn ├── development.rb ├── heroku.rb ├── production.rb └── staging.rb /.gitignore: -------------------------------------------------------------------------------- 1 | ### https://raw.github.com/github/gitignore/master/Global/OSX.gitignore 2 | 3 | .DS_Store 4 | .AppleDouble 5 | .LSOverride 6 | 7 | # Icon must ends with two \r. 8 | Icon 9 | 10 | # Thumbnails 11 | ._* 12 | 13 | # Files that might appear on external disk 14 | .Spotlight-V100 15 | .Trashes 16 | 17 | 18 | ### https://raw.github.com/github/gitignore/master/Ruby.gitignore 19 | 20 | *.gem 21 | *.rbc 22 | /.config 23 | /coverage/ 24 | /InstalledFiles 25 | /pkg/ 26 | /spec/reports/ 27 | /test/tmp/ 28 | /test/version_tmp/ 29 | /tmp/ 30 | 31 | ## Documentation cache and generated files: 32 | /.yardoc/ 33 | /_yardoc/ 34 | /doc/ 35 | /rdoc/ 36 | 37 | ## Environment normalisation: 38 | /.bundle/ 39 | /lib/bundler/man/ 40 | 41 | # for a library or gem, you might want to ignore these files since the code is 42 | # intended to run in multiple environments; otherwise, check them in: 43 | # Gemfile.lock 44 | # .ruby-version 45 | # .ruby-gemset 46 | 47 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 48 | .rvmrc 49 | 50 | 51 | ### https://raw.github.com/github/gitignore/master/Rails.gitignore 52 | 53 | *.rbc 54 | *.sassc 55 | .sass-cache 56 | capybara-*.html 57 | .rspec 58 | /log 59 | /tmp 60 | /db/*.sqlite3 61 | /public/system 62 | /coverage/ 63 | /spec/tmp 64 | **.orig 65 | rerun.txt 66 | pickle-email-*.html 67 | config/initializers/secret_token.rb 68 | config/secrets.yml 69 | 70 | ## Environment normalisation: 71 | /.bundle 72 | /vendor/bundle 73 | 74 | # these should all be checked in to normalise the environment: 75 | # Gemfile.lock, .ruby-version, .ruby-gemset 76 | 77 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 78 | .rvmrc 79 | 80 | 81 | ### https://raw.github.com/github/gitignore/master/Global/JetBrains.gitignore 82 | 83 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode 84 | 85 | ## Directory-based project format 86 | .idea/ 87 | # if you remove the above rule, at least ignore user-specific stuff: 88 | # .idea/workspace.xml 89 | # .idea/tasks.xml 90 | # and these sensitive or high-churn files: 91 | # .idea/dataSources.ids 92 | # .idea/dataSources.xml 93 | # .idea/sqlDataSources.xml 94 | # .idea/dynamic.xml 95 | 96 | ## File-based project format 97 | *.ipr 98 | *.iws 99 | *.iml 100 | 101 | ## Additional for IntelliJ 102 | out/ 103 | 104 | # generated by mpeltonen/sbt-idea plugin 105 | .idea_modules/ 106 | 107 | 108 | ### https://raw.github.com/github/gitignore/master/Global/SASS.gitignore 109 | 110 | ### Sass Ignores - "Sassy CSS" http://sass-lang.com/ 111 | *.sass-cache 112 | 113 | 114 | ### https://raw.github.com/github/gitignore/master/Global/SublimeText.gitignore 115 | 116 | # workspace files are user-specific 117 | *.sublime-workspace 118 | 119 | # project files should be checked into the repository, unless a significant 120 | # proportion of contributors will probably not be using SublimeText 121 | # *.sublime-project 122 | 123 | 124 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Rails4 application template 2 | 3 | Rails4 Application Template. - [Rails Application Templates — Ruby on Rails Guides](http://guides.rubyonrails.org/rails_application_templates.html) 4 | 5 | It's easy to start Rails4 x PosgreSQL/MySQL application. 6 | 7 | In addition, you can choose following options; 8 | 9 | 1) Errbit
10 | 2) MongoDB
11 | 3) Redis
12 | 4) Heroku Push
13 | 14 | ## Reparation 15 | 16 | I recommend to install gibo before generating Rails project. - [simonwhitaker/gibo](https://github.com/simonwhitaker/gibo) 17 | 18 | (It's not compulsory, maybe...) 19 | 20 | brew install gibo 21 | 22 | ## Execution command 23 | 24 | Execute following command 25 | 26 | gem update rails 27 | 28 | # if you want to use PostgreSQL, please execute following command; 29 | rails new test_app --database=postgresql --skip-test-unit --skip-bundle -m https://raw.github.com/morizyun/rails4_template/master/app_template.rb 30 | 31 | # if you want to use MySQL, please execute following command; 32 | rails new test_app --database=mysql --skip-test-unit --skip-bundle -m https://raw.github.com/morizyun/rails4_template/master/app_template.rb 33 | 34 | Caution: Please don't use '-' in application name. 35 | 36 | ## Detail explanation 37 | 38 | Description of this template in Japanese is as follows; 39 | 40 | - [Rails4でheroku Pushまでの最短手順 [haml/bootstrap 3.0/postgresql or MySQL] - 酒と泪とRubyとRailsと](http://morizyun.github.io/blog/heroku-rails4-postgresql-introduction/) 41 | 42 | ## Supported versions 43 | 44 | - Ruby 2.2.3 45 | - Rails 4.2.4 46 | 47 | ## Contributing 48 | 49 | 1. Fork it 50 | 2. Create your feature branch (`git checkout -b my-new-feature`) 51 | 3. Commit your changes (`git commit -am 'Add some feature'`) 52 | 4. Push to the branch (`git push origin my-new-feature`) 53 | 5. Create new Pull Request 54 | -------------------------------------------------------------------------------- /app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require jquery.turbolinks 16 | //= require turbolinks 17 | -------------------------------------------------------------------------------- /app/assets/stylesheets/application.css.scss: -------------------------------------------------------------------------------- 1 | // First import cerulean variables 2 | @import "bootswatch/yeti/variables"; 3 | 4 | // Then bootstrap itself 5 | @import "bootstrap"; 6 | 7 | // Bootstrap body padding for fixed navbar 8 | body { padding-top: 60px; } 9 | 10 | // And finally bootswatch style itself 11 | @import "bootswatch/yeti/bootswatch"; 12 | 13 | @import "font-awesome"; -------------------------------------------------------------------------------- /app_template.rb: -------------------------------------------------------------------------------- 1 | require 'bundler' 2 | 3 | # アプリ名の取得 4 | @app_name = app_name 5 | 6 | # メールアドレスの取得 7 | mail_address = ask("What's your current email address?") 8 | 9 | # clean file 10 | run 'rm README.rdoc' 11 | 12 | # .gitignore 13 | run 'gibo OSX Ruby Rails JetBrains SASS SublimeText > .gitignore' rescue nil 14 | gsub_file '.gitignore', /^config\/initializers\/secret_token.rb$/, '' 15 | gsub_file '.gitignore', /config\/secret.yml/, '' 16 | 17 | # add to Gemfile 18 | append_file 'Gemfile', <<-CODE 19 | 20 | # Bootstrap & Bootswatch & font-awesome 21 | gem 'bootstrap-sass' 22 | gem 'bootswatch-rails' 23 | gem 'font-awesome-rails' 24 | 25 | # turbolinks support 26 | gem 'jquery-turbolinks' 27 | 28 | # sprocket-rails (3.0.0 is not good...) 29 | gem 'sprockets-rails', '2.3.3' 30 | 31 | # See https://github.com/sstephenson/execjs#readme for more supported runtimes 32 | gem 'therubyracer', platforms: :ruby 33 | 34 | # CSS Support 35 | gem 'less-rails' 36 | 37 | # App Server 38 | gem 'unicorn' 39 | 40 | # Slim 41 | gem 'slim-rails' 42 | 43 | # Assets log cleaner 44 | gem 'quiet_assets' 45 | 46 | # Form Builders 47 | gem 'simple_form' 48 | 49 | # # Process Management 50 | gem 'foreman' 51 | 52 | # PG/MySQL Log Formatter 53 | gem 'rails-flog' 54 | 55 | # Pagenation 56 | gem 'kaminari' 57 | 58 | # NewRelic 59 | gem 'newrelic_rpm' 60 | 61 | # Hash extensions 62 | gem 'hashie' 63 | 64 | # Cron Manage 65 | gem 'whenever', require: false 66 | 67 | # Presenter Layer Helper 68 | gem 'active_decorator' 69 | 70 | # Table(Migration) Comment 71 | gem 'migration_comments' 72 | 73 | # Exception Notifier 74 | gem 'exception_notification' 75 | 76 | group :development do 77 | gem 'html2slim' 78 | 79 | # N+1問題の検出 80 | gem 'bullet' 81 | 82 | # Rack Profiler 83 | # gem 'rack-mini-profiler' 84 | end 85 | 86 | group :development, :test do 87 | # Pry & extensions 88 | gem 'pry-rails' 89 | gem 'pry-coolline' 90 | gem 'pry-byebug' 91 | gem 'rb-readline' 92 | 93 | # PryでのSQLの結果を綺麗に表示 94 | gem 'hirb' 95 | gem 'hirb-unicode' 96 | 97 | # pryの色付けをしてくれる 98 | gem 'awesome_print' 99 | 100 | # Rspec 101 | gem 'rspec-rails' 102 | 103 | # test fixture 104 | gem 'factory_girl_rails' 105 | 106 | # Deploy 107 | gem 'capistrano', '~> 3.2.1' 108 | gem 'capistrano-rails' 109 | gem 'capistrano-rbenv' 110 | gem 'capistrano-bundler' 111 | gem 'capistrano3-unicorn' 112 | end 113 | 114 | group :test do 115 | # HTTP requests用のモックアップを作ってくれる 116 | gem 'webmock' 117 | gem 'vcr' 118 | 119 | # Time Mock 120 | gem 'timecop' 121 | 122 | # テスト用データを生成 123 | gem 'faker' 124 | 125 | # テスト環境のテーブルをきれいにする 126 | gem 'database_rewinder' 127 | end 128 | 129 | group :production, :staging do 130 | # ログ保存先変更、静的アセット Heroku 向けに調整 131 | gem 'rails_12factor' 132 | end 133 | CODE 134 | 135 | Bundler.with_clean_env do 136 | run 'bundle install --path vendor/bundle --jobs=4' 137 | end 138 | 139 | # set config/application.rb 140 | application do 141 | %q{ 142 | # Set timezone 143 | config.time_zone = 'Tokyo' 144 | config.active_record.default_timezone = :local 145 | 146 | # 日本語化 147 | I18n.enforce_available_locales = true 148 | config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s] 149 | config.i18n.default_locale = :ja 150 | 151 | # generatorの設定 152 | config.generators do |g| 153 | g.orm :active_record 154 | g.template_engine :slim 155 | g.test_framework :rspec, :fixture => true 156 | g.fixture_replacement :factory_girl, :dir => "spec/factories" 157 | g.view_specs false 158 | g.controller_specs true 159 | g.routing_specs false 160 | g.helper_specs false 161 | g.request_specs false 162 | g.assets false 163 | g.helper false 164 | end 165 | 166 | # libファイルの自動読み込み 167 | config.autoload_paths += %W(#{config.root}/lib) 168 | config.autoload_paths += Dir["#{config.root}/lib/**/"] 169 | } 170 | end 171 | 172 | # For Bullet (N+1 Problem) 173 | insert_into_file 'config/environments/development.rb',%( 174 | # Bulletの設定 175 | config.after_initialize do 176 | Bullet.enable = true # Bulletプラグインを有効 177 | Bullet.alert = true # JavaScriptでの通知 178 | Bullet.bullet_logger = true # log/bullet.logへの出力 179 | Bullet.console = true # ブラウザのコンソールログに記録 180 | Bullet.rails_logger = true # Railsログに出力 181 | end 182 | ), after: 'config.assets.debug = true' 183 | 184 | # Exception Notifier 185 | insert_into_file 'config/environments/production.rb',%( 186 | # Exception Notifier 187 | Rails.application.config.middleware.use ExceptionNotification::Rack, 188 | :email => { 189 | :email_prefix => "[#{@app_name}] ", 190 | :sender_address => %{"notifier" <#{mail_address}>}, 191 | :exception_recipients => %w{#{mail_address}} 192 | } 193 | ), after: 'config.active_record.dump_schema_after_migration = false' 194 | 195 | # set Japanese locale 196 | run 'wget https://raw.github.com/svenfuchs/rails-i18n/master/rails/locale/ja.yml -P config/locales/' 197 | 198 | # application.js(turbolink setting) 199 | run 'rm -rf app/assets/javascripts/application.js' 200 | run 'wget https://raw.github.com/morizyun/rails4_template/master/app/assets/javascripts/application.js -P app/assets/javascripts/' 201 | 202 | # erb => slim 203 | Bundler.with_clean_env do 204 | run 'bundle exec erb2slim -d app/views' 205 | end 206 | 207 | # Bootstrap/Bootswach/Font-Awesome 208 | run 'rm -rf app/assets/stylesheets/application.css' 209 | run 'wget https://raw.github.com/morizyun/rails4_template/master/app/assets/stylesheets/application.css.scss -P app/assets/stylesheets/' 210 | 211 | # Simple Form 212 | generate 'simple_form:install --bootstrap' 213 | 214 | # Whenever 215 | run 'wheneverize .' 216 | 217 | # Capistrano 218 | Bundler.with_clean_env do 219 | run 'bundle exec cap install' 220 | end 221 | 222 | # Kaminari config 223 | generate 'kaminari:config' 224 | 225 | # Database 226 | run 'rm -rf config/database.yml' 227 | if yes?('Use MySQL?([yes] else PostgreSQL)') 228 | run 'wget https://raw.github.com/morizyun/rails4_template/master/config/mysql/database.yml -P config/' 229 | else 230 | run 'wget https://raw.github.com/morizyun/rails4_template/master/config/postgresql/database.yml -P config/' 231 | run "createuser #{@app_name} -s" 232 | end 233 | 234 | gsub_file 'config/database.yml', /APPNAME/, @app_name 235 | Bundler.with_clean_env do 236 | run 'bundle exec rake RAILS_ENV=development db:create' 237 | end 238 | 239 | # Unicorn(App Server) 240 | run 'mkdir config/unicorn' 241 | run 'wget https://raw.github.com/morizyun/rails4_template/master/config/unicorn/development.rb -P config/unicorn/' 242 | run 'wget https://raw.github.com/morizyun/rails4_template/master/config/unicorn/heroku.rb -P config/unicorn/' 243 | run 'wget https://raw.github.com/morizyun/rails4_template/master/config/unicorn/production.rb -P config/unicorn/' 244 | run 'wget https://raw.github.com/morizyun/rails4_template/master/config/unicorn/staging.rb -P config/unicorn/' 245 | run "echo 'web: bundle exec unicorn -p $PORT -c ./config/unicorn/heroku.rb' > Procfile" 246 | 247 | # Rspec/Guard 248 | # ---------------------------------------------------------------- 249 | # Rspec 250 | generate 'rspec:install' 251 | 252 | run "echo '--color -f d' > .rspec" 253 | 254 | insert_into_file 'spec/spec_helper.rb',%( 255 | config.before :suite do 256 | DatabaseRewinder.clean_all 257 | end 258 | 259 | config.after :each do 260 | DatabaseRewinder.clean 261 | end 262 | 263 | config.before :all do 264 | FactoryGirl.reload 265 | FactoryGirl.factories.clear 266 | FactoryGirl.sequences.clear 267 | FactoryGirl.find_definitions 268 | end 269 | 270 | config.include FactoryGirl::Syntax::Methods 271 | 272 | VCR.configure do |c| 273 | c.cassette_library_dir = 'spec/vcr' 274 | c.hook_into :webmock 275 | c.allow_http_connections_when_no_cassette = true 276 | end 277 | ), after: 'RSpec.configure do |config|' 278 | 279 | insert_into_file 'spec/spec_helper.rb', "\nrequire 'factory_girl_rails'", after: "require 'rspec/rails'" 280 | gsub_file 'spec/spec_helper.rb', "require 'rspec/autorun'", '' 281 | 282 | # MongoDB 283 | # ---------------------------------------------------------------- 284 | use_mongodb = if yes?('Use MongoDB? [yes or ELSE]') 285 | append_file 'Gemfile', <<-CODE 286 | \n# Mongoid 287 | gem 'mongoid', '4.0.0.alpha1' 288 | gem 'bson_ext' 289 | gem 'origin' 290 | gem 'moped' 291 | CODE 292 | 293 | Bundler.with_clean_env do 294 | run 'bundle install' 295 | end 296 | 297 | generate 'mongoid:config' 298 | 299 | append_file 'config/mongoid.yml', <<-CODE 300 | production: 301 | sessions: 302 | default: 303 | uri: <%= ENV['MONGOLAB_URI'] %> 304 | CODE 305 | 306 | append_file 'spec/spec_helper.rb', <<-CODE 307 | require 'rails/mongoid' 308 | CODE 309 | 310 | insert_into_file 'spec/spec_helper.rb',%( 311 | # Clean/Reset Mongoid DB prior to running each test. 312 | config.before(:each) do 313 | Mongoid::Sessions.default.collections.select {|c| c.name !~ /system/ }.each(&:drop) 314 | end 315 | ), after: 'RSpec.configure do |config|' 316 | end 317 | 318 | # Redis 319 | # ---------------------------------------------------------------- 320 | use_redis = if yes?('Use Redis? [yes or ELSE]') 321 | append_file 'Gemfile', <<-CODE 322 | \n# Redis 323 | gem 'redis-objects' 324 | gem 'redis-namespace' 325 | CODE 326 | 327 | Bundler.with_clean_env do 328 | run 'bundle install' 329 | end 330 | 331 | run 'wget https://raw.github.com/morizyun/rails4_template/master/config/initializers/redis.rb -P config/initializers/' 332 | end 333 | 334 | # git init 335 | # ---------------------------------------------------------------- 336 | git :init 337 | git :add => '.' 338 | git :commit => "-a -m 'first commit'" 339 | 340 | # heroku deploy 341 | # ---------------------------------------------------------------- 342 | if yes?('Use Heroku? [yes or ELSE]') 343 | def heroku(cmd, arguments="") 344 | run "heroku #{cmd} #{arguments}" 345 | end 346 | 347 | # herokuに不要なファイルを設定 348 | file '.slugignore', <<-EOS.gsub(/^ /, '') 349 | *.psd 350 | *.pdf 351 | test 352 | spec 353 | features 354 | doc 355 | docs 356 | EOS 357 | 358 | git :add => '.' 359 | git :commit => "-a -m 'Configuration for heroku'" 360 | 361 | heroku_app_name = @app_name.gsub('_', '-') 362 | heroku :create, "#{heroku_app_name}" 363 | 364 | # config 365 | run 'heroku config:add SECRET_KEY_BASE=`rake secret`' 366 | run 'heroku config:add TZ=Asia/Tokyo' 367 | 368 | # addons 369 | heroku :'addons:create', 'logentries' 370 | heroku :'addons:create', 'scheduler' 371 | heroku :'addons:create', 'mongolab' if use_mongodb 372 | heroku :'addons:create', 'rediscloud' if use_redis 373 | 374 | git :push => 'heroku master' 375 | heroku :run, "rake db:migrate --app #{heroku_app_name}" 376 | 377 | # newrelic 378 | if yes?('Use newrelic?[yes or ELSE]') 379 | heroku :'addons:create', 'newrelic' 380 | heroku :'addons:open', 'newrelic' 381 | run 'wget https://raw.github.com/morizyun/rails4_template/master/config/newrelic.yml -P config/' 382 | gsub_file 'config/newrelic.yml', /%APP_NAME/, @app_name 383 | key_value = ask('Newrelic licence key value?') 384 | gsub_file 'config/newrelic.yml', /%KEY_VALUE/, key_value 385 | end 386 | end 387 | -------------------------------------------------------------------------------- /config/application.yml: -------------------------------------------------------------------------------- 1 | defaults: &defaults 2 | 3 | 4 | development: 5 | <<: *defaults 6 | 7 | 8 | test: 9 | <<: *defaults 10 | 11 | 12 | staging: 13 | <<: *defaults 14 | 15 | 16 | production: 17 | <<: *defaults 18 | -------------------------------------------------------------------------------- /config/initializers/errbit.rb: -------------------------------------------------------------------------------- 1 | # Please fix following settings 2 | Airbrake.configure do |config| 3 | config.api_key = '%KEY_VALUE' 4 | config.host = 'xxx.herokuapp.com' 5 | config.port = 443 6 | config.secure = config.port == 443 7 | config.development_environments = %w(development test) 8 | end -------------------------------------------------------------------------------- /config/initializers/redis.rb: -------------------------------------------------------------------------------- 1 | namespace = [Rails.application.class.parent_name, Rails.env].join ':' 2 | if Rails.env.production? 3 | # herokuの初期 asset compileでENVがうまく読み込まれていないっぽいので対策 4 | if ENV['REDISCLOUD_URL'] 5 | redis_uri = URI(ENV['REDISCLOUD_URL']) 6 | Redis.current = Redis.new(host: redis_uri.host, port: redis_uri.port, password: redis_uri.password) 7 | Redis.current = Redis::Namespace.new(namespace, Redis.new(host: redis_uri.host, port: redis_uri.port, password: redis_uri.password)) 8 | end 9 | else 10 | Redis.current = Redis::Namespace.new(namespace, Redis.new(host: '127.0.0.1', port: 6379)) 11 | end -------------------------------------------------------------------------------- /config/initializers/settings.rb: -------------------------------------------------------------------------------- 1 | class Settings < Settingslogic 2 | source "#{Rails.root}/config/application.yml" 3 | namespace Rails.env 4 | end -------------------------------------------------------------------------------- /config/mysql/database.yml: -------------------------------------------------------------------------------- 1 | development: 2 | adapter: mysql2 3 | encoding: utf8 4 | database: APPNAME_development 5 | pool: 5 6 | username: root 7 | password: 8 | 9 | test: 10 | adapter: mysql2 11 | encoding: utf8 12 | database: APPNAME_test 13 | pool: 5 14 | username: root 15 | password: 16 | 17 | production: 18 | adapter: mysql2 19 | encoding: utf8 20 | database: APPNAME_production 21 | pool: 5 22 | username: root 23 | password: 24 | -------------------------------------------------------------------------------- /config/newrelic.yml: -------------------------------------------------------------------------------- 1 | # 2 | # This file configures the New Relic Agent. New Relic monitors 3 | # Ruby, Java, .NET, PHP, and Python applications with deep visibility and low overhead. 4 | # For more information, visit www.newrelic.com. 5 | # 6 | # Generated December 30, 2013 7 | # 8 | # This configuration file is custom generated for app20803116@heroku.com 9 | 10 | 11 | # Here are the settings that are common to all environments 12 | common: &default_settings 13 | # ============================== LICENSE KEY =============================== 14 | 15 | # You must specify the license key associated with your New Relic 16 | # account. This key binds your Agent's data to your account in the 17 | # New Relic service. 18 | license_key: '%KEY_VALUE' 19 | 20 | # Agent Enabled (Ruby/Rails Only) 21 | # Use this setting to force the agent to run or not run. 22 | # Default is 'auto' which means the agent will install and run only 23 | # if a valid dispatcher such as Mongrel is running. This prevents 24 | # it from running with Rake or the console. Set to false to 25 | # completely turn the agent off regardless of the other settings. 26 | # Valid values are true, false and auto. 27 | # 28 | # agent_enabled: auto 29 | 30 | # Application Name Set this to be the name of your application as 31 | # you'd like it show up in New Relic. The service will then auto-map 32 | # instances of your application into an "application" on your 33 | # dashboard page. If you want to map this instance into multiple 34 | # apps, like "AJAX Requests" and "All UI" then specify a semicolon 35 | # separated list of up to three distinct names, or a yaml list. 36 | # Defaults to the capitalized RAILS_ENV or RACK_ENV (i.e., 37 | # Production, Staging, etc) 38 | # 39 | # Example: 40 | # 41 | # app_name: 42 | # - Ajax Service 43 | # - All Services 44 | # 45 | app_name: %APP_NAME 46 | 47 | # When "true", the agent collects performance data about your 48 | # application and reports this data to the New Relic service at 49 | # newrelic.com. This global switch is normally overridden for each 50 | # environment below. (formerly called 'enabled') 51 | monitor_mode: true 52 | 53 | # Developer mode should be off in every environment but 54 | # development as it has very high overhead in memory. 55 | developer_mode: false 56 | 57 | # The newrelic agent generates its own log file to keep its logging 58 | # information separate from that of your application. Specify its 59 | # log level here. 60 | log_level: info 61 | 62 | # Optionally set the path to the log file This is expanded from the 63 | # root directory (may be relative or absolute, e.g. 'log/' or 64 | # '/var/log/') The agent will attempt to create this directory if it 65 | # does not exist. 66 | # log_file_path: 'log' 67 | 68 | # Optionally set the name of the log file, defaults to 'newrelic_agent.log' 69 | # log_file_name: 'newrelic_agent.log' 70 | 71 | # The newrelic agent communicates with the service via https by default. This 72 | # prevents eavesdropping on the performance metrics transmitted by the agent. 73 | # The encryption required by SSL introduces a nominal amount of CPU overhead, 74 | # which is performed asynchronously in a background thread. If you'd prefer 75 | # to send your metrics over http uncomment the following line. 76 | # ssl: false 77 | 78 | #============================== Browser Monitoring =============================== 79 | # New Relic Real User Monitoring gives you insight into the performance real users are 80 | # experiencing with your website. This is accomplished by measuring the time it takes for 81 | # your users' browsers to download and render your web pages by injecting a small amount 82 | # of JavaScript code into the header and footer of each page. 83 | browser_monitoring: 84 | # By default the agent automatically injects the monitoring JavaScript 85 | # into web pages. Set this attribute to false to turn off this behavior. 86 | auto_instrument: true 87 | 88 | # Proxy settings for connecting to the New Relic server. 89 | # 90 | # If a proxy is used, the host setting is required. Other settings 91 | # are optional. Default port is 8080. 92 | # 93 | # proxy_host: hostname 94 | # proxy_port: 8080 95 | # proxy_user: 96 | # proxy_pass: 97 | 98 | # The agent can optionally log all data it sends to New Relic servers to a 99 | # separate log file for human inspection and auditing purposes. To enable this 100 | # feature, change 'enabled' below to true. 101 | # See: https://newrelic.com/docs/ruby/audit-log 102 | audit_log: 103 | enabled: false 104 | 105 | # Tells transaction tracer and error collector (when enabled) 106 | # whether or not to capture HTTP params. When true, frameworks can 107 | # exclude HTTP parameters from being captured. 108 | # Rails: the RoR filter_parameter_logging excludes parameters 109 | # Java: create a config setting called "ignored_params" and set it to 110 | # a comma separated list of HTTP parameter names. 111 | # ex: ignored_params: credit_card, ssn, password 112 | capture_params: false 113 | 114 | # Transaction tracer captures deep information about slow 115 | # transactions and sends this to the New Relic service once a 116 | # minute. Included in the transaction is the exact call sequence of 117 | # the transactions including any SQL statements issued. 118 | transaction_tracer: 119 | 120 | # Transaction tracer is enabled by default. Set this to false to 121 | # turn it off. This feature is only available at the Professional 122 | # and above product levels. 123 | enabled: true 124 | 125 | # Threshold in seconds for when to collect a transaction 126 | # trace. When the response time of a controller action exceeds 127 | # this threshold, a transaction trace will be recorded and sent to 128 | # New Relic. Valid values are any float value, or (default) "apdex_f", 129 | # which will use the threshold for an dissatisfying Apdex 130 | # controller action - four times the Apdex T value. 131 | transaction_threshold: apdex_f 132 | 133 | # When transaction tracer is on, SQL statements can optionally be 134 | # recorded. The recorder has three modes, "off" which sends no 135 | # SQL, "raw" which sends the SQL statement in its original form, 136 | # and "obfuscated", which strips out numeric and string literals. 137 | record_sql: obfuscated 138 | 139 | # Threshold in seconds for when to collect stack trace for a SQL 140 | # call. In other words, when SQL statements exceed this threshold, 141 | # then capture and send to New Relic the current stack trace. This is 142 | # helpful for pinpointing where long SQL calls originate from. 143 | stack_trace_threshold: 0.500 144 | 145 | # Determines whether the agent will capture query plans for slow 146 | # SQL queries. Only supported in mysql and postgres. Should be 147 | # set to false when using other adapters. 148 | # explain_enabled: true 149 | 150 | # Threshold for query execution time below which query plans will 151 | # not be captured. Relevant only when `explain_enabled` is true. 152 | # explain_threshold: 0.5 153 | 154 | # Error collector captures information about uncaught exceptions and 155 | # sends them to New Relic for viewing 156 | error_collector: 157 | 158 | # Error collector is enabled by default. Set this to false to turn 159 | # it off. This feature is only available at the Professional and above 160 | # product levels. 161 | enabled: true 162 | 163 | # Rails Only - tells error collector whether or not to capture a 164 | # source snippet around the place of the error when errors are View 165 | # related. 166 | capture_source: true 167 | 168 | # To stop specific errors from reporting to New Relic, set this property 169 | # to comma-separated values. Default is to ignore routing errors, 170 | # which are how 404's get triggered. 171 | ignore_errors: "ActionController::RoutingError,Sinatra::NotFound" 172 | 173 | # If you're interested in capturing memcache keys as though they 174 | # were SQL uncomment this flag. Note that this does increase 175 | # overhead slightly on every memcached call, and can have security 176 | # implications if your memcached keys are sensitive 177 | # capture_memcache_keys: true 178 | 179 | # Application Environments 180 | # ------------------------------------------ 181 | # Environment-specific settings are in this section. 182 | # For Rails applications, RAILS_ENV is used to determine the environment. 183 | # For Java applications, pass -Dnewrelic.environment to set 184 | # the environment. 185 | 186 | # NOTE if your application has other named environments, you should 187 | # provide newrelic configuration settings for these environments here. 188 | 189 | development: 190 | <<: *default_settings 191 | # Turn off communication to New Relic service in development mode (also 192 | # 'enabled'). 193 | # NOTE: for initial evaluation purposes, you may want to temporarily 194 | # turn the agent on in development mode. 195 | monitor_mode: false 196 | 197 | # Rails Only - when running in Developer Mode, the New Relic Agent will 198 | # present performance information on the last 100 transactions you have 199 | # executed since starting the mongrel. 200 | # NOTE: There is substantial overhead when running in developer mode. 201 | # Do not use for production or load testing. 202 | developer_mode: true 203 | 204 | # Enable textmate links 205 | # textmate: true 206 | 207 | test: 208 | <<: *default_settings 209 | # It almost never makes sense to turn on the agent when running 210 | # unit, functional or integration tests or the like. 211 | monitor_mode: false 212 | 213 | # Turn on the agent in production for 24x7 monitoring. NewRelic 214 | # testing shows an average performance impact of < 5 ms per 215 | # transaction, you can leave this on all the time without 216 | # incurring any user-visible performance degradation. 217 | production: 218 | <<: *default_settings 219 | monitor_mode: true 220 | 221 | # Many applications have a staging environment which behaves 222 | # identically to production. Support for that environment is provided 223 | # here. By default, the staging environment has the agent turned on. 224 | staging: 225 | <<: *default_settings 226 | monitor_mode: true 227 | # app_name: My Application (Staging) 228 | -------------------------------------------------------------------------------- /config/postgresql/database.yml: -------------------------------------------------------------------------------- 1 | # PostgreSQL. Versions 8.2 and up are supported. 2 | # 3 | # Install the pg driver: 4 | # gem install pg 5 | # On OS X with Homebrew: 6 | # gem install pg -- --with-pg-config=/usr/local/bin/pg_config 7 | # On OS X with MacPorts: 8 | # gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 9 | # On Windows: 10 | # gem install pg 11 | # Choose the win32 build. 12 | # Install PostgreSQL and put its /bin directory on your path. 13 | # 14 | # Configure Using Gemfile 15 | # gem 'pg' 16 | # 17 | development: 18 | adapter: postgresql 19 | encoding: unicode 20 | database: APPNAME_development 21 | pool: 5 22 | username: APPNAME 23 | password: 24 | host: localhost 25 | 26 | # Connect on a TCP socket. Omitted by default since the client uses a 27 | # domain socket that doesn't need configuration. Windows does not have 28 | # domain sockets, so uncomment these lines. 29 | #host: localhost 30 | 31 | # The TCP port the server listens on. Defaults to 5432. 32 | # If your server runs on a different port number, change accordingly. 33 | #port: 5432 34 | 35 | # Schema search path. The server defaults to $user,public 36 | #schema_search_path: myapp,sharedapp,public 37 | 38 | # Minimum log levels, in increasing order: 39 | # debug5, debug4, debug3, debug2, debug1, 40 | # log, notice, warning, error, fatal, and panic 41 | # Defaults to warning. 42 | #min_messages: notice 43 | 44 | # Warning: The database defined as "test" will be erased and 45 | # re-generated from your development database when you run "rake". 46 | # Do not set this db to the same as development or production. 47 | test: 48 | adapter: postgresql 49 | encoding: unicode 50 | database: APPNAME_test 51 | pool: 5 52 | username: APPNAME 53 | password: 54 | host: localhost 55 | 56 | production: 57 | adapter: postgresql 58 | encoding: unicode 59 | database: APPNAME_production 60 | pool: 5 61 | username: APPNAME 62 | password: 63 | -------------------------------------------------------------------------------- /config/unicorn/development.rb: -------------------------------------------------------------------------------- 1 | worker_processes 2 2 | 3 | pid File.expand_path('tmp/pids/unicorn.pid', ENV['RAILS_ROOT']).to_s 4 | listen 3000 5 | 6 | stderr_path File.expand_path('log/error.log', ENV['RAILS_ROOT']) 7 | stdout_path File.expand_path('log/development.log', ENV['RAILS_ROOT']) 8 | 9 | preload_app true 10 | 11 | before_fork do |server, worker| 12 | ENV['BUNDLE_GEMFILE'] = "#{ENV['RAILS_ROOT']}/Gemfile" 13 | defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! 14 | end 15 | 16 | after_fork do |server, worker| 17 | defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection 18 | end -------------------------------------------------------------------------------- /config/unicorn/heroku.rb: -------------------------------------------------------------------------------- 1 | worker_processes 1 2 | timeout 15 3 | preload_app true 4 | 5 | before_fork do |server, worker| 6 | Signal.trap 'TERM' do 7 | puts 'Unicorn master intercepting TERM and sending myself QUIT instead' 8 | Process.kill 'QUIT', Process.pid 9 | end 10 | 11 | defined?(ActiveRecord::Base) and 12 | ActiveRecord::Base.connection.disconnect! 13 | end 14 | 15 | after_fork do |server, worker| 16 | Signal.trap 'TERM' do 17 | puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT' 18 | end 19 | 20 | defined?(ActiveRecord::Base) and 21 | ActiveRecord::Base.establish_connection 22 | end -------------------------------------------------------------------------------- /config/unicorn/production.rb: -------------------------------------------------------------------------------- 1 | worker_processes 10 2 | 3 | pid File.expand_path('tmp/pids/unicorn.pid', ENV['RAILS_ROOT']).to_s 4 | listen 5001 5 | 6 | stderr_path File.expand_path('log/error.log', ENV['RAILS_ROOT']) 7 | stdout_path File.expand_path('log/production.log', ENV['RAILS_ROOT']) 8 | 9 | preload_app true 10 | 11 | before_fork do |server, worker| 12 | ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile', ENV['RAILS_ROOT']) 13 | 14 | defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! 15 | end 16 | 17 | after_fork do |server, worker| 18 | defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection 19 | end 20 | -------------------------------------------------------------------------------- /config/unicorn/staging.rb: -------------------------------------------------------------------------------- 1 | worker_processes 3 2 | 3 | pid File.expand_path('tmp/pids/unicorn.pid', ENV['RAILS_ROOT']).to_s 4 | listen 5001 5 | 6 | stderr_path File.expand_path('log/error.log', ENV['RAILS_ROOT']) 7 | stdout_path File.expand_path('log/staging.log', ENV['RAILS_ROOT']) 8 | 9 | preload_app true 10 | 11 | before_fork do |server, worker| 12 | ENV['BUNDLE_GEMFILE'] = File.expand_path('Gemfile', ENV['RAILS_ROOT']) 13 | 14 | defined?(ActiveRecord::Base) and ActiveRecord::Base.connection.disconnect! 15 | end 16 | 17 | after_fork do |server, worker| 18 | defined?(ActiveRecord::Base) and ActiveRecord::Base.establish_connection 19 | end 20 | --------------------------------------------------------------------------------