Silence deprecation warning in production

Fix rbenv not being able to export to upstart via foreman
This commit is contained in:
Luke Barratt 2014-03-23 04:13:19 +00:00
parent d28004b6dd
commit 960aab7aca
6 changed files with 43 additions and 18 deletions

View file

@ -13,13 +13,17 @@ Create a deploy user. Disable password authentication and add it to the www-data
sudo passwd -l deploy sudo passwd -l deploy
sudo usermod -a -G www-data 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 # /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 ## Install MySQL & Memcached
@ -42,11 +46,14 @@ Switch user to deploy, and install rbenv
su deploy su deploy
cd ~ cd ~
git clone git://github.com/sstephenson/rbenv.git .rbenv 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 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.profile
echo 'eval "$(rbenv init -)"' >> ~/.bashrc echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL exec $SHELL
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build 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 echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL exec $SHELL
@ -56,6 +63,11 @@ Switch user to deploy, and install rbenv
echo "gem: --no-ri --no-rdoc" > ~/.gemrc echo "gem: --no-ri --no-rdoc" > ~/.gemrc
gem install bundler 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 ## Install the ENSL site
Create the `.env` file with the appropriate credentials. Create the `.env` file with the appropriate credentials.

View file

@ -1 +1 @@
web: bundle exec unicorn -p $UNICORN_PORT -l $UNICORN_SOCKET -c ./config/unicorn.rb web: bundle exec unicorn -c ./config/unicorn.rb

View file

@ -1,22 +1,28 @@
lock '3.1.0' lock '3.1.0'
set :application, 'ensl' set :application, 'ensl'
set :deploy_user, 'deploy'
set :pty, true
set :scm, :git set :scm, :git
set :repo_url, 'git@github.com:ENSL/ensl.org.git' set :repo_url, 'git@github.com:ENSL/ensl.org.git'
set :keep_releases, 10 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_type, :user
set :rbenv_ruby, '2.1.1' 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 namespace :deploy do
desc 'Restart application' desc 'Restart application'
task :restart do task :restart do
foreman.export invoke 'foreman:export'
foreman.restart invoke 'foreman:restart'
end end
after :publishing, :restart after :publishing, :restart
@ -26,28 +32,30 @@ namespace :foreman do
desc "Export the Procfile to Ubuntu's upstart scripts" desc "Export the Procfile to Ubuntu's upstart scripts"
task :export do task :export do
on roles(:app) do |host| 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
end end
desc "Start the application services" desc "Start the application services"
task :start do task :start do
on roles(:app) do |host| on roles(:app) do |host|
run "#{sudo} service #{app_name} start" execute "sudo service #{fetch(:application)} start"
end end
end end
desc "Stop the application services" desc "Stop the application services"
task :stop do task :stop do
on roles(:app) do |host| on roles(:app) do |host|
run "#{sudo} service #{app_name} stop" execute "sudo service #{fetch(:application)} stop"
end end
end end
desc "Restart the application services" desc "Restart the application services"
task :restart do task :restart do
on roles(:app) do |host| 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 end
end end

View file

@ -5,4 +5,6 @@ require 'exceptions'
require 'extra' require 'extra'
Dotenv.load Dotenv.load
ActiveSupport::Deprecation.silenced = true if ['staging', 'production'].include?(ENV['RAILS_ENV'])
Ensl::Application.initialize! Ensl::Application.initialize!

View file

@ -2,6 +2,9 @@ worker_processes Integer(ENV['UNICORN_WORKERS'] || 3)
timeout 30 timeout 30
preload_app true preload_app true
listen ENV['UNICORN_PORT']
listen ENV['UNICORN_SOCKET']
before_fork do |server, worker| before_fork do |server, worker|
Signal.trap 'TERM' do Signal.trap 'TERM' do
puts 'Unicorn master intercepting TERM and sending myself QUIT instead' puts 'Unicorn master intercepting TERM and sending myself QUIT instead'

View file

@ -60,7 +60,7 @@ Option.create!(option: "Option 1", poll: Poll.first)
Option.create!(option: "Option 2", poll: Poll.first) Option.create!(option: "Option 2", poll: Poll.first)
# Base Forums # 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 # Example Topic
Topic.create!(title: "Hello World!", forum_id: Forum.first.id, user: User.first, first_post: "Hello World!") Topic.create!(title: "Hello World!", forum_id: Forum.first.id, user: User.first, first_post: "Hello World!")