diff --git a/config/deploy.example.rb b/config/deploy.example.rb index 05e786c..c7758a0 100644 --- a/config/deploy.example.rb +++ b/config/deploy.example.rb @@ -2,9 +2,9 @@ # ============= # # Copy this file to config/deploy.rb and customize it as needed. -# Then run `cap deploy:setup` to set up your server and finally +# Then run `cap errbit:setup` to set up your server and finally # `cap deploy` whenever you would like to deploy Errbit. Refer -# to the Readme for more information. +# to ./docs/deployment/capistrano.md for more info # config valid only for current version of Capistrano lock '3.3.5' @@ -20,9 +20,8 @@ set :ssh_options, forward_agent: true set :linked_files, fetch(:linked_files, []) + %w( .env - config/config.yml - config/mongoid.yml config/newrelic.yml + config/unicorn.rb ) set :linked_dirs, fetch(:linked_dirs, []) + %w( @@ -38,36 +37,51 @@ set :linked_dirs, fetch(:linked_dirs, []) + %w( # set :rbenv_roles, :all namespace :errbit do - task :setup_configs do + desc "Setup config files (first time setup)" + task :setup do on roles(:app) do execute "mkdir -p #{shared_path}/config" + execute "mkdir -p #{shared_path}/pids" + execute "touch #{shared_path}/.env" + { - 'config/config.example.yml' => 'config/config.yml', - 'config/mongoid.example.yml' => 'config/mongoid.yml', - 'config/newrelic.example.yml' => 'config/newrelic.yml' + 'config/newrelic.example.yml' => 'config/newrelic.yml', + 'config/unicorn.default.rb' => 'config/unicorn.rb', }.each do |src, target| - execute "if [ ! -f #{shared_path}/#{target} ]; then cp #{current_path}/#{src} #{shared_path}/#{target}; fi" + unless test("[ -f #{shared_path}/#{target} ]") + upload! src, "#{shared_path}/#{target}" + end end end end end namespace :db do - desc "Create the indexes defined on your mongoid models" - task :create_mongoid_indexes do + desc "Create and setup the mongo db" + task :setup do on roles(:db) do within current_path do with rails_env: fetch(:rails_env) do - execute :rake, 'db:mongoid:create_indexes' + execute :rake, 'errbit:bootstrap' end end end end end -set :unicorn_pid, "`cat #{"#{fetch(:deploy_to)}/shared/pids"}/unicorn.pid`" +set :unicorn_pidfile, "#{fetch(:deploy_to)}/shared/pids/unicorn.pid" +set :unicorn_pid, "`cat #{fetch(:unicorn_pidfile)}`" namespace :unicorn do + desc 'Start unicorn' + task :start do + on roles(:app) do + within current_path do + execute "UNICORN_PID=\"#{fetch(:unicorn_pidfile)}\"", "bundle exec unicorn -D -c ./config/unicorn.rb" + end + end + end + desc 'Reload unicorn' task :reload do on roles(:app) do diff --git a/config/unicorn.default.rb b/config/unicorn.default.rb index 58b2d13..3cd7d2c 100644 --- a/config/unicorn.default.rb +++ b/config/unicorn.default.rb @@ -3,6 +3,8 @@ worker_processes 3 # amount of unicorn workers to spin up timeout 30 # restarts workers that hang for 30 seconds preload_app true +listen 8080 +pid ENV['UNICORN_PID'] if ENV['UNICORN_PID'] # Taken from github: https://github.com/blog/517-unicorn # Though everyone uses pretty miuch the same code @@ -17,7 +19,7 @@ before_fork do |server, worker| # we send it a QUIT. # # Using this method we get 0 downtime deploys. - + old_pid = "#{server.config[:pid]}.oldbin" if File.exists?(old_pid) && server.pid != old_pid begin @@ -27,3 +29,4 @@ before_fork do |server, worker| end end end + diff --git a/docs/deployment/capistrano.md b/docs/deployment/capistrano.md index 322501f..ff46ba7 100644 --- a/docs/deployment/capistrano.md +++ b/docs/deployment/capistrano.md @@ -1,8 +1,8 @@ # Deploy with Capistrano These instructions should be good enough to get you started deploying -capistrano with Errbit. More than likely, you'll have to adjust some things to -suit your needs, so you should understand how to use capistrano before you -continue. +capistrano with Errbit. More than likely, you'll have to adjust some +things to suit your needs, so you should understand how to use +capistrano before you continue. ## Clone and prepare the source code repository @@ -18,20 +18,48 @@ $EDITOR config/deploy.rb cp config/deploy/production.example.rb config/deploy/production.rb $EDITOR config/deploy/production.rb -# Create required directories. -# It will print out what files are missing. -# Create them manually or use errbit:setup_configs task after first deploy +# Check to make sure configs exist bundle exec cap production deploy:check + +# Create the configs yourself, or run errbit:setup_configs to upload the +# defaults +bundle exec cap production errbit:setup_configs + +# Deploy +bundle exec cap production deploy + +# Setup the remote DB if you haven't already +bundle exec cap production db:setup ``` +## Static Assets +For a deployment of any real size, you'll probably want to set up a web +server for efficiently serving static assets. If you choose to go this +route, just map all requests for /assets/.\* to +/deploy/path/shared/public/assets + +## Starting Errbit +Errbit comes with some capistrano tasks to manage running Errbit under +unicorn. +To start Errbit, you can run: +```bash +bundle exec cap production unicorn:start +``` + +Supervising and monitoring Errbit is beyond the scope of this +documentation. + + ### rbenv support -Pass `rbenv` environment when running `cap` to use rbenv. +Pass `rbenv` environment when running `cap` to use rbenv. See +[capistrano/rbenv](https://github.com/capistrano/rbenv) for more +information. ```bash rbenv=1 bundle exec cap production deploy ``` ## Schedule recurring tasks -You may want to periodically clear resolved errors to free up space. Schedule -the ```rake errbit:db:clear_resolved``` rake task to run every day or so. +You may want to periodically clear resolved errors to free up space. +Schedule ```rake errbit:db:clear_resolved``` to run every day or so. diff --git a/docs/deployment/heroku.md b/docs/deployment/heroku.md index 466bc0c..e4af8d9 100644 --- a/docs/deployment/heroku.md +++ b/docs/deployment/heroku.md @@ -23,19 +23,17 @@ git commit -m "Update db/seeds.rb with initial login" heroku apps:create heroku addons:add mongolab:sandbox heroku addons:add sendgrid:starter -heroku config:add HEROKU=true -heroku config:add SECRET_TOKEN="$(bundle exec rake secret)" +heroku config:add GEMFILE_RUBY_VERSION=2.2.0 +heroku config:add SECRET_KEY_BASE="$(bundle exec rake secret)" heroku config:add ERRBIT_HOST=some-hostname.example.com heroku config:add ERRBIT_EMAIL_FROM=example@example.com git push heroku master ``` ## Prepare the DB -No bootstrap task is used on Heroku! ```bash -heroku run rake db:seed -heroku run rake db:mongoid:create_indexes +heroku run rake errbit:bootstrap ``` ## Schedule recurring tasks -- libgit2 0.21.2