diff options
| author | Tyler Mercier <tylermercier@gmail.com> | 2013-07-24 20:12:39 -0600 |
|---|---|---|
| committer | Tyler Mercier <tylermercier@gmail.com> | 2013-07-24 20:12:39 -0600 |
| commit | 1f58ab205c1e255d2671895a209fb3322113f940 (patch) | |
| tree | ac261fe78968e1ac0fa83b05bdc2aec9be6dad6a /config | |
| parent | 9f32eb099c59b4d0d702e557257cf524c0b34b4c (diff) | |
deployments are now working
Diffstat (limited to 'config')
| -rw-r--r-- | config/deploy.rb | 29 | ||||
| -rw-r--r-- | config/nginx_parley.txt | 2 | ||||
| -rw-r--r-- | config/recipes/base.rb | 2 | ||||
| -rw-r--r-- | config/recipes/nginx.rb | 5 | ||||
| -rw-r--r-- | config/recipes/nodejs.rb | 2 | ||||
| -rw-r--r-- | config/recipes/postgresql.rb | 2 | ||||
| -rw-r--r-- | config/recipes/rbenv.rb (renamed from config/recipes/rvm.rb) | 15 | ||||
| -rw-r--r-- | config/recipes/templates/nginx_unicorn.erb | 2 | ||||
| -rw-r--r-- | config/recipes/templates/unicorn.rb.erb | 28 | ||||
| -rw-r--r-- | config/recipes/templates/unicorn_init.erb | 4 | ||||
| -rw-r--r-- | config/recipes/unicorn.rb | 1 |
11 files changed, 56 insertions, 36 deletions
diff --git a/config/deploy.rb b/config/deploy.rb index 5a066f8..0d9d888 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -5,19 +5,19 @@ load "config/recipes/nginx" load "config/recipes/unicorn" load "config/recipes/postgresql" load "config/recipes/nodejs" -load "config/recipes/rvm" +load "config/recipes/rbenv" load "config/recipes/check" # Your HTTP server, Apache/etc -role :web, "www.parleytool.com" +role :web, "192.241.204.27" # This may be the same as your `Web` server -role :app, "www.parleytool.com" +role :app, "192.241.204.27" # This is where Rails migrations will run -role :db, "www.parleytool.com", primary: true -#role :db, "your slave db-server here" +role :db, "192.241.204.27", primary: true +#role :db, "your slave db-server here" set :application, "parley" -set :user, "demo" +set :user, "deployer" set :deploy_to, "/home/#{user}/apps/#{application}" set :deploy_via, :remote_cache # keeps git repo on server cache set :use_sudo, false @@ -26,30 +26,13 @@ set :scm, "git" set :branch, "master" set :repository, "git@github.com:madebyuppercut/parley.git" -# set :rvm_ruby_string, :local - -# rvm info - to get this -set :default_environment, { - 'PATH' => "/home/demo/.rvm/gems/ruby-2.0.0-p247/bin:/home/demo/.rvm/gems/ruby-2.0.0-p247@global/bin:/home/demo/.rvm/rubies/ruby-2.0.0-p247/bin:/home/demo/.rvm/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games", - 'RUBY_VERSION' => 'ruby-2.0.0-p247', - 'GEM_HOME' => "/home/demo/.rvm/gems/ruby-2.0.0-p247", - 'GEM_PATH' => "/home/demo/.rvm/gems/ruby-2.0.0-p247:/home/demo/.rvm/gems/ruby-2.0.0-p247@global" -} - default_run_options[:pty] = true # password prompt ssh_options[:forward_agent] = true # no deploy key for github after "deploy", "deploy:cleanup" # keep only the last 5 releases -task :tacocat do - run 'echo $PATH' -end - # Instructions ############## -# ssh root@198.199.101.128 -# adduser deployer --ingroup admin -# exit # cap deploy:install # cap deploy:setup # cap deploy:cold diff --git a/config/nginx_parley.txt b/config/nginx_parley.txt index 8ad4a1b..a3ff9ef 100644 --- a/config/nginx_parley.txt +++ b/config/nginx_parley.txt @@ -75,7 +75,7 @@ server { # per-response basis. # proxy_buffering off; - proxy_pass http://localhost:8080; + proxy_pass http://app_server; } # Rails error pages diff --git a/config/recipes/base.rb b/config/recipes/base.rb index d7c3714..cbecaa6 100644 --- a/config/recipes/base.rb +++ b/config/recipes/base.rb @@ -11,6 +11,6 @@ namespace :deploy do desc "Install everything onto the server" task :install do run "#{sudo} apt-get -y update" - run "#{sudo} apt-get -y install python-software-properties" + run "#{sudo} apt-get -y install curl git-core python-software-properties" end end diff --git a/config/recipes/nginx.rb b/config/recipes/nginx.rb index a290800..b1f5332 100644 --- a/config/recipes/nginx.rb +++ b/config/recipes/nginx.rb @@ -1,7 +1,7 @@ namespace :nginx do desc "Install latest stable release of nginx" task :install, roles: :web do - run "#{sudo} add-apt-repository ppa:nginx/stable" + run "#{sudo} add-apt-repository -y ppa:nginx/stable" run "#{sudo} apt-get -y update" run "#{sudo} apt-get -y install nginx" end @@ -10,7 +10,8 @@ namespace :nginx do desc "Setup nginx configuration for this application" task :setup, roles: :web do template "nginx_unicorn.erb", "/tmp/nginx_conf" - run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-enabled/#{application}" + run "#{sudo} mv /tmp/nginx_conf /etc/nginx/sites-available/#{application}" + run "#{sudo} ln -s /etc/nginx/sites-available/#{application} /etc/nginx/sites-enabled/#{application}" run "#{sudo} rm -f /etc/nginx/sites-enabled/default" restart end diff --git a/config/recipes/nodejs.rb b/config/recipes/nodejs.rb index e32981b..7696104 100644 --- a/config/recipes/nodejs.rb +++ b/config/recipes/nodejs.rb @@ -1,7 +1,7 @@ namespace :nodejs do desc "Install the latest relase of Node.js" task :install, roles: :app do - run "#{sudo} add-apt-repository ppa:chris-lea/node.js" + run "#{sudo} add-apt-repository -y ppa:chris-lea/node.js" run "#{sudo} apt-get -y update" run "#{sudo} apt-get -y install nodejs" end diff --git a/config/recipes/postgresql.rb b/config/recipes/postgresql.rb index 19d9863..5cc405f 100644 --- a/config/recipes/postgresql.rb +++ b/config/recipes/postgresql.rb @@ -6,7 +6,7 @@ set_default(:postgresql_database) { "#{application}_production" } namespace :postgresql do desc "Install the latest stable release of PostgreSQL." task :install, roles: :db, only: {primary: true} do - run "#{sudo} add-apt-repository ppa:pitti/postgresql" + run "#{sudo} add-apt-repository -y ppa:pitti/postgresql" run "#{sudo} apt-get -y update" run "#{sudo} apt-get -y install postgresql libpq-dev" end diff --git a/config/recipes/rvm.rb b/config/recipes/rbenv.rb index a2201e4..f37f04c 100644 --- a/config/recipes/rvm.rb +++ b/config/recipes/rbenv.rb @@ -1,5 +1,5 @@ -set_default :ruby_version, "1.9.3-p125" -set_default :rbenv_bootstrap, "bootstrap-ubuntu-10-04" +set_default :ruby_version, "2.0.0-p247" +set_default :rbenv_bootstrap, "bootstrap-ubuntu-12-04" namespace :rbenv do desc "Install rbenv, Ruby, and the Bundler gem" @@ -17,7 +17,16 @@ BASHRC run "mv ~/.bashrc.tmp ~/.bashrc" run %q{export PATH="$HOME/.rbenv/bin:$PATH"} run %q{eval "$(rbenv init -)"} - run "rbenv #{rbenv_bootstrap}" + # Install development tools: + run "#{sudo} apt-get -y install build-essential" + # Packages required for compilation of some stdlib modules + run "#{sudo} apt-get -y install tklib" + # Extras for RubyGems and Rails: + run "#{sudo} apt-get -y install zlib1g-dev libssl-dev" + # Readline Dev on Ubuntu 12.04 LTS: + run "#{sudo} apt-get -y install libreadline-gplv2-dev" + # Install some nokogiri dependencies: + run "#{sudo} apt-get -y install libxml2 libxml2-dev libxslt1-dev" run "rbenv install #{ruby_version}" run "rbenv global #{ruby_version}" run "gem install bundler --no-ri --no-rdoc" diff --git a/config/recipes/templates/nginx_unicorn.erb b/config/recipes/templates/nginx_unicorn.erb index 48e44b1..45b5e9e 100644 --- a/config/recipes/templates/nginx_unicorn.erb +++ b/config/recipes/templates/nginx_unicorn.erb @@ -1,5 +1,5 @@ upstream unicorn { - server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0; + server unix:<%= shared_path %>/sockets/unicorn.sock fail_timeout=0; } server { diff --git a/config/recipes/templates/unicorn.rb.erb b/config/recipes/templates/unicorn.rb.erb index 1f51905..136b86b 100644 --- a/config/recipes/templates/unicorn.rb.erb +++ b/config/recipes/templates/unicorn.rb.erb @@ -3,6 +3,32 @@ pid "<%= unicorn_pid %>" stderr_path "<%= unicorn_log %>" stdout_path "<%= unicorn_log %>" -listen "/tmp/unicorn.<%= application %>.sock" +listen "<%= shared_path %>/sockets/unicorn.sock" worker_processes <%= unicorn_workers %> timeout 30 + +preload_app true + +before_fork do |server, worker| + # Disconnect since the database connection will not carry over + if defined? ActiveRecord::Base + ActiveRecord::Base.connection.disconnect! + end + + # Quit the old unicorn process + old_pid = "#{server.config[:pid]}.oldbin" + if File.exists?(old_pid) && server.pid != old_pid + begin + Process.kill("QUIT", File.read(old_pid).to_i) + rescue Errno::ENOENT, Errno::ESRCH + # someone else did our job for us + end + end +end + +after_fork do |server, worker| + # Start up the database connection again in the worker + if defined?(ActiveRecord::Base) + ActiveRecord::Base.establish_connection + end +end diff --git a/config/recipes/templates/unicorn_init.erb b/config/recipes/templates/unicorn_init.erb index cc78278..2d7b067 100644 --- a/config/recipes/templates/unicorn_init.erb +++ b/config/recipes/templates/unicorn_init.erb @@ -14,7 +14,7 @@ set -e TIMEOUT=${TIMEOUT-60} APP_ROOT=<%= current_path %> PID=<%= unicorn_pid %> -CMD="cd <%= current_path %>; bundle exec unicorn -D -c <%= unicorn_config %> -E production" +CMD="cd <%= current_path %>; bundle exec unicorn -E production -D -c <%= unicorn_config %>" AS_USER=<%= unicorn_user %> set -u @@ -50,7 +50,7 @@ force-stop) echo >&2 "Not running" ;; restart|reload) - sig HUP && echo reloaded OK && exit 0 + sig USR2 && echo reloaded OK && exit 0 echo >&2 "Couldn't reload, starting '$CMD' instead" run "$CMD" ;; diff --git a/config/recipes/unicorn.rb b/config/recipes/unicorn.rb index a5cbe1b..18b05dd 100644 --- a/config/recipes/unicorn.rb +++ b/config/recipes/unicorn.rb @@ -8,6 +8,7 @@ namespace :unicorn do desc "Setup Unicorn initializer and app configuration" task :setup, roles: :app do run "mkdir -p #{shared_path}/config" + run "mkdir -p #{shared_path}/sockets" template "unicorn.rb.erb", unicorn_config template "unicorn_init.erb", "/tmp/unicorn_init" run "chmod +x /tmp/unicorn_init" |
