From 960aab7acad1699b63e2e6c46c9b831e1fdaac39 Mon Sep 17 00:00:00 2001 From: Luke Barratt Date: Sun, 23 Mar 2014 04:13:19 +0000 Subject: [PATCH] Silence deprecation warning in production Fix rbenv not being able to export to upstart via foreman --- INSTALL.md | 22 +++++++++++++++++----- Procfile | 2 +- config/deploy.rb | 28 ++++++++++++++++++---------- config/environment.rb | 4 +++- config/unicorn.rb | 3 +++ db/seeds.rb | 2 +- 6 files changed, 43 insertions(+), 18 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 0c64fd1..6b1f78f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -13,13 +13,17 @@ Create a deploy user. Disable password authentication and add it to the www-data sudo passwd -l deploy sudo usermod -a -G www-data deploy -Add the following to `/etc/sudoers` to allow the `deploy` user to manage nginx and foreman via sudo without a password +Create a new upstart config and set permissions + + touch /etc/init/ensl.conf + chown deploy /etc/init/ensl.conf + +Add the following to `/etc/sudoers` to allow the `deploy` user to manage nginx, rbenv and upstart via sudo without a password # /etc/sudoers - Cmnd_Alias START_FOREMAN = /sbin/start foreman - - deploy ALL=NOPASSWD:START_FOREMAN - deploy ALL=NOPASSWD:/etc/init.d/nginx + deploy ALL=NOPASSWD:/etc/init.d/nginx + deploy ALL=NOPASSWD:/home/deploy/.rbenv/bin/* + deploy ALL=NOPASSWD:/usr/sbin/service ensl start, /usr/sbin/service ensl stop, /usr/sbin/service ensl restart ## Install MySQL & Memcached @@ -42,11 +46,14 @@ Switch user to deploy, and install rbenv su deploy cd ~ git clone git://github.com/sstephenson/rbenv.git .rbenv + echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.profile echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc + echo 'eval "$(rbenv init -)"' >> ~/.profile echo 'eval "$(rbenv init -)"' >> ~/.bashrc exec $SHELL git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build + echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.profile echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc exec $SHELL @@ -56,6 +63,11 @@ Switch user to deploy, and install rbenv echo "gem: --no-ri --no-rdoc" > ~/.gemrc gem install bundler +Install the rbenv-sudo plugin + + mkdir ~/.rbenv/plugins + git clone git://github.com/dcarley/rbenv-sudo.git ~/.rbenv/plugins/rbenv-sudo + ## Install the ENSL site Create the `.env` file with the appropriate credentials. diff --git a/Procfile b/Procfile index 02d328f..08b255c 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: bundle exec unicorn -p $UNICORN_PORT -l $UNICORN_SOCKET -c ./config/unicorn.rb \ No newline at end of file +web: bundle exec unicorn -c ./config/unicorn.rb \ No newline at end of file diff --git a/config/deploy.rb b/config/deploy.rb index 8984b0f..a6e2808 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,22 +1,28 @@ lock '3.1.0' set :application, 'ensl' +set :deploy_user, 'deploy' +set :pty, true + set :scm, :git set :repo_url, 'git@github.com:ENSL/ensl.org.git' set :keep_releases, 10 -set :linked_files, %w{.env} -set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle public/system} -set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets} - set :rbenv_type, :user set :rbenv_ruby, '2.1.1' +set :rbenv_sudo, "sudo /home/#{fetch(:deploy_user)}/.rbenv/bin/rbenv sudo" + +set :linked_files, %w{.env} +set :linked_dirs, %w{bin log tmp/pids tmp/cache tmp/sockets vendor/bundle + public/system public/local public/uploads} + +set :normalize_asset_timestamps, %{public/images public/javascripts public/stylesheets} namespace :deploy do desc 'Restart application' task :restart do - foreman.export - foreman.restart + invoke 'foreman:export' + invoke 'foreman:restart' end after :publishing, :restart @@ -26,28 +32,30 @@ namespace :foreman do desc "Export the Procfile to Ubuntu's upstart scripts" task :export do on roles(:app) do |host| - run "cd #{current_path} && #{sudo} foreman export upstart /etc/init -a #{app_name} -u #{user} -l #{fetch(:deploy_to)}/shared/log" + within release_path do + execute "#{fetch(:rbenv_sudo)} bundle exec foreman export upstart /etc/init -a #{fetch(:application)} -u #{fetch(:deploy_user)} -l #{fetch(:deploy_to)}/shared/log" + end end end desc "Start the application services" task :start do on roles(:app) do |host| - run "#{sudo} service #{app_name} start" + execute "sudo service #{fetch(:application)} start" end end desc "Stop the application services" task :stop do on roles(:app) do |host| - run "#{sudo} service #{app_name} stop" + execute "sudo service #{fetch(:application)} stop" end end desc "Restart the application services" task :restart do on roles(:app) do |host| - run "#{sudo} service #{app_name} start || #{sudo} service #{app_name} restart" + execute "sudo service #{fetch(:application)} start || #{sudo} service #{fetch(:application)} restart" end end end \ No newline at end of file diff --git a/config/environment.rb b/config/environment.rb index 380ee77..49305a8 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -5,4 +5,6 @@ require 'exceptions' require 'extra' Dotenv.load -Ensl::Application.initialize! \ No newline at end of file +ActiveSupport::Deprecation.silenced = true if ['staging', 'production'].include?(ENV['RAILS_ENV']) + +Ensl::Application.initialize! diff --git a/config/unicorn.rb b/config/unicorn.rb index 5b896f4..0e07129 100644 --- a/config/unicorn.rb +++ b/config/unicorn.rb @@ -2,6 +2,9 @@ worker_processes Integer(ENV['UNICORN_WORKERS'] || 3) timeout 30 preload_app true +listen ENV['UNICORN_PORT'] +listen ENV['UNICORN_SOCKET'] + before_fork do |server, worker| Signal.trap 'TERM' do puts 'Unicorn master intercepting TERM and sending myself QUIT instead' diff --git a/db/seeds.rb b/db/seeds.rb index fced31d..702bfde 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -60,7 +60,7 @@ Option.create!(option: "Option 1", poll: Poll.first) Option.create!(option: "Option 2", poll: Poll.first) # Base Forums -Forum.create!(title: "General Discussion", description: "Anything that doesn't belong in the other forums", catrgory_id: Category.where(domain: Category::DOMAIN_FORUMS).first) +Forum.create!(title: "General Discussion", description: "Anything that doesn't belong in the other forums", category: Category.where(domain: Category::DOMAIN_FORUMS).first) # Example Topic Topic.create!(title: "Hello World!", forum_id: Forum.first.id, user: User.first, first_post: "Hello World!")