From 0b3adcb63a76063c886a15261c443ca5ffe5019e Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Mon, 4 Nov 2013 04:09:45 +0900 Subject: [PATCH 1/7] =?UTF-8?q?refs=20#17=20=E3=83=89=E3=83=A1=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E5=90=8D=E5=A4=89=E6=9B=B4:=20clipclap.herokuapp.com?= =?UTF-8?q?=20=3D>=20clipclap.org?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- config/environments/production.rb | 6 +++--- config/initializers/devise.rb | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b4e0dd3..660fa8a 100644 --- a/README.md +++ b/README.md @@ -8,4 +8,4 @@ Clipclap Clipclap is a tool for collecting and sharing pictures you love. -[Check out a demo](http://clipclap.heroku.com/). +[Check out a demo](http://clipclap.org/). diff --git a/config/environments/production.rb b/config/environments/production.rb index 6a4c0f5..800bd40 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -74,17 +74,17 @@ authentication: :plain, user_name: ENV['SENDGRID_USERNAME'], password: ENV['SENDGRID_PASSWORD'], - domain: 'heroku.com' + domain: 'clipclap.org' } # for Device - config.action_mailer.default_url_options = { :host => 'clipclap.herokuapp.com' } + config.action_mailer.default_url_options = { :host => 'clipclap.org' } config.middleware.use( ExceptionNotification::Rack, email: { email_prefix: "[Clipclap] ", - sender_address: "Clipclap ", + sender_address: %{"Clipclap" }, exception_recipients: %w( hyoshida@appirits.com ) } ) diff --git a/config/initializers/devise.rb b/config/initializers/devise.rb index dc2d1d1..9f876f5 100644 --- a/config/initializers/devise.rb +++ b/config/initializers/devise.rb @@ -4,7 +4,7 @@ # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class with default "from" parameter. - config.mailer_sender = "noreply@clipclap.herokuapp.com" + config.mailer_sender = "no-reply@clipclap.org" # Configure the class responsible to send e-mails. # config.mailer = "Devise::Mailer" From 5007d6af0d04cdc3f7965729957a759d0eb1257b Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Mon, 4 Nov 2013 20:13:36 +0900 Subject: [PATCH 2/7] =?UTF-8?q?refs=20#17=20=E4=B8=8D=E8=A6=81=E3=81=AAUni?= =?UTF-8?q?corn=E3=81=AE=E8=A8=AD=E5=AE=9A=E3=82=92=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/unicorn.rb | 70 ----------------------------------------------- 1 file changed, 70 deletions(-) delete mode 100644 config/unicorn.rb diff --git a/config/unicorn.rb b/config/unicorn.rb deleted file mode 100644 index feffd0b..0000000 --- a/config/unicorn.rb +++ /dev/null @@ -1,70 +0,0 @@ -# config/unicorn.rb -# Set environment to development unless something else is specified -ENV['RAILS_ENV'] ||= 'production' - -# See http://unicorn.bogomips.org/Unicorn/Configurator.html for complete -# documentation. -worker_processes 1 - -# Preload our app for more speed -preload_app true - -# nuke workers after 30 seconds instead of 60 seconds (the default) -timeout 60 - -application = 'clipclap' -shared_path = "/home/yoshida/public_html/#{application}/shared" - listen '/tmp/clipclap_unicorn.socket', :backlog => 1024 - -# Production specific settings -if ENV['RAILS_ENV'] == 'production' - worker_processes 4 - - # listen on both a Unix domain socket and a TCP port, - # we use a shorter backlog for quicker failover when busy - #listen 80, :backlog => 1024 - #listen 4422, :tcp_nopush => true - listen '/tmp/clipclap_unicorn.socket', :backlog => 1024 - - # Help ensure your application will always spawn in the symlinked - # "current" directory that Capistrano sets up. - working_directory "/home/yoshida/public_html/#{application}/current" - - # feel free to point this anywhere accessible on the filesystem - user 'yoshida', 'wheel' - - stderr_path "#{shared_path}/log/unicorn.stderr.log" - stdout_path "#{shared_path}/log/unicorn.stdout.log" -end - -before_fork do |server, worker| - # the following is highly recomended for Rails + "preload_app true" - # as there's no need for the master process to hold a connection - if defined?(ActiveRecord::Base) - ActiveRecord::Base.connection.disconnect! - end - - # Before forking, kill the master process that belongs to the .oldbin PID. - # This enables 0 downtime deploys. - old_pid = "#{shared_path}/pids/unicorn.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| - # the following is *required* for Rails + "preload_app true", - if defined?(ActiveRecord::Base) - ActiveRecord::Base.establish_connection - end - - # if preload_app is true, then you may also want to check and - # restart any other shared sockets/descriptors such as Memcached, - # and Redis. TokyoCabinet file handles are safe to reuse - # between any number of forked children (assuming your kernel - # correctly implements pread()/pwrite() system calls) -end From 96e56fb6992d8be11dec7cdf934639856dd76bcd Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Mon, 4 Nov 2013 20:36:31 +0900 Subject: [PATCH 3/7] =?UTF-8?q?refs=20#17=20Heroku=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 3 --- Gemfile.lock | 15 --------------- 2 files changed, 18 deletions(-) diff --git a/Gemfile b/Gemfile index 5cf7107..8079023 100644 --- a/Gemfile +++ b/Gemfile @@ -18,9 +18,6 @@ group :development do # Deploy with Capistrano gem 'capistrano' gem 'capistrano-rbenv' - - # for Heroku - gem 'heroku' end # Gems used only for assets and not required diff --git a/Gemfile.lock b/Gemfile.lock index 9904766..2d9442a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -49,7 +49,6 @@ GEM i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) acts_as_follower (0.1.1) - addressable (2.3.5) arel (3.0.2) bcrypt-ruby (3.1.1) bootstrap-sass (2.3.1.0) @@ -114,7 +113,6 @@ GEM exception_notification (4.0.1) actionmailer (>= 3.0.4) activesupport (>= 3.0.4) - excon (0.25.3) execjs (1.4.0) multi_json (~> 1.0) factory_girl (4.2.0) @@ -146,14 +144,6 @@ GEM haml (4.0.0) tilt hashie (2.0.5) - heroku (3.0.1) - heroku-api (~> 0.3.7) - launchy (>= 0.3.2) - netrc (~> 0.7.7) - rest-client (~> 1.6.1) - rubyzip - heroku-api (0.3.15) - excon (~> 0.25.1) highline (1.6.15) hike (1.2.3) hpricot (0.8.6) @@ -178,8 +168,6 @@ GEM actionpack (>= 3.0.0) activesupport (>= 3.0.0) kgio (2.8.0) - launchy (2.3.0) - addressable (~> 2.3) libv8 (3.11.8.13) mail (2.5.4) mime-types (~> 1.16) @@ -209,7 +197,6 @@ GEM net-ssh (2.6.5) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) - netrc (0.7.7) newrelic_rpm (3.6.8.168) nokogiri (1.5.6) ntlm-http (0.1.1) @@ -286,7 +273,6 @@ GEM rspec-core (~> 2.13.0) rspec-expectations (~> 2.13.0) rspec-mocks (~> 2.13.0) - rubyzip (1.0.0) safe_yaml (0.8.4) sass (3.2.8) sass-rails (3.2.6) @@ -375,7 +361,6 @@ DEPENDENCIES font-awesome-sass-rails foreman google-analytics-rails - heroku hpricot i18n_generators image_size From 0e124d42746e16d027ffd95b975e98fa07e02bc0 Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Thu, 7 Nov 2013 22:14:43 +0900 Subject: [PATCH 4/7] =?UTF-8?q?.env=E3=81=AE=E3=82=B5=E3=83=B3=E3=83=97?= =?UTF-8?q?=E3=83=AB=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.sample | 4 ++++ .gitignore | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 .env.sample diff --git a/.env.sample b/.env.sample new file mode 100644 index 0000000..3defb26 --- /dev/null +++ b/.env.sample @@ -0,0 +1,4 @@ +RAILS_ENV=production +SENDGRID_USERNAME=username +SENDGRID_PASSWORD=password +GA_TRACKINGID=UA-xxxxxxxx-x diff --git a/.gitignore b/.gitignore index ba610be..6e3c519 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,9 @@ /log/*.log /tmp +# Ignore dotenv +/.env + /public/assets *.swp *~ From f6a8318c2d5abed0a8734f8a9407dcf1913b8cc3 Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Thu, 7 Nov 2013 19:22:40 +0900 Subject: [PATCH 5/7] =?UTF-8?q?refs=20#17=20Bluepill=E3=82=92=E5=B0=8E?= =?UTF-8?q?=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 3 ++- Gemfile.lock | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 8079023..29b2b2f 100644 --- a/Gemfile +++ b/Gemfile @@ -106,8 +106,9 @@ gem 'resque' gem 'private_pub' gem 'thin' -# 複数アプリケーションの管理 +# アプリケーション管理 gem 'foreman' +gem 'bluepill' # リソース監視 gem 'newrelic_rpm' diff --git a/Gemfile.lock b/Gemfile.lock index 2d9442a..456ed62 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,6 +51,11 @@ GEM acts_as_follower (0.1.1) arel (3.0.2) bcrypt-ruby (3.1.1) + bluepill (0.0.66) + activesupport (>= 3.0.0, < 4.0.0) + daemons (~> 1.1.4) + i18n (>= 0.5.0) + state_machine (~> 1.1) bootstrap-sass (2.3.1.0) sass (~> 3.2) builder (3.0.4) @@ -301,6 +306,7 @@ GEM multi_json (~> 1.0) rack (~> 1.0) tilt (~> 1.1, != 1.3.0) + state_machine (1.2.0) temple (0.6.5) term-ansicolor (1.2.2) tins (~> 0.8) @@ -347,6 +353,7 @@ PLATFORMS DEPENDENCIES acts_as_follower (~> 0.1.1) + bluepill bootstrap-sass (~> 2.3.1.0) capistrano capistrano-rbenv From e9ced644633eba5bea68ad9d4ede457f26b155f1 Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Thu, 7 Nov 2013 21:49:45 +0900 Subject: [PATCH 6/7] =?UTF-8?q?refs=20#17=20Bluepill=E3=81=A7=E7=92=B0?= =?UTF-8?q?=E5=A2=83=E5=A4=89=E6=95=B0=E3=81=8C=E4=BD=BF=E3=81=88=E3=81=9A?= =?UTF-8?q?=E3=81=AB=E3=82=A8=E3=83=A9=E3=83=BC=E3=81=8C=E5=87=BA=E3=82=8B?= =?UTF-8?q?=E5=95=8F=E9=A1=8C=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Procfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Procfile b/Procfile index 74256eb..efdda16 100644 --- a/Procfile +++ b/Procfile @@ -1,3 +1,3 @@ -web: bundle exec rails server -p $PORT +web: sh -c 'bundle exec rails server -p $PORT' resque: bundle exec rake resque:work QUEUE='*' private_pub: bundle exec rackup private_pub.ru -s thin -E production From baf6002fbc9692c83de2fc8b790ee7b91c342c3f Mon Sep 17 00:00:00 2001 From: YOSHIDA Hiroki Date: Thu, 7 Nov 2013 22:12:23 +0900 Subject: [PATCH 7/7] =?UTF-8?q?refs=20#17=20=E3=83=87=E3=83=97=E3=83=AD?= =?UTF-8?q?=E3=82=A4=E8=A8=AD=E5=AE=9A=E3=82=92=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/deploy.rb | 66 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/config/deploy.rb b/config/deploy.rb index 508ca5b..a01b63c 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -1,7 +1,7 @@ require 'bundler/capistrano' set :application, 'clipclap' -set :repository, 'git@49.212.160.224:clipclap.git' +set :repository, 'https://github.com/hyoshida/clipclap.git' set :deploy_to, "/home/yoshida/public_html/#{application}" set :rails_env, 'production' set :user, 'yoshida' @@ -10,12 +10,12 @@ set :scm, :git # Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none` -role :web, '49.212.160.224' # Your HTTP server, Apache/etc -role :app, '49.212.160.224' # This may be the same as your `Web` server -role :db, '49.212.160.224', :primary => true # This is where Rails migrations will run +role :web, 'clipclap.org' # Your HTTP server, Apache/etc +role :app, 'clipclap.org' # This may be the same as your `Web` server +role :db, 'clipclap.org', :primary => true # This is where Rails migrations will run require 'capistrano-rbenv' -set :rbenv_ruby_version, '2.0.0-p0' +set :rbenv_ruby_version, '2.0.0-p247' # if you want to clean up old releases on each deploy uncomment this: # after "deploy:restart", "deploy:cleanup" @@ -32,16 +32,58 @@ # end # end -namespace :deploy do - task :start, :roles => :app do - run "cd #{current_path}; bundle exec unicorn_rails -c config/unicorn.rb -E #{rails_env} -D --path /#{application}" +default_run_options[:pty] = true + +set :foreman_export_format, 'bluepill' +set :foreman_location_path, "#{shared_path}/bluepill" + +namespace :foreman do + desc "Export the Procfile to scripts" + task :export, roles: :app do + run "if [ ! -d #{foreman_location_path} ]; then mkdir -p #{foreman_location_path}; fi" + run "cd #{release_path} && bundle exec foreman export #{foreman_export_format} #{foreman_location_path} #{foreman_format(foreman_options)}" end - task :restart, :roles => :app do - run "kill -s USR2 `cat #{current_path}/tmp/pids/unicorn.pid`" + def foreman_options + { + app: application, + log: "#{shared_path}/log", + user: user + } end - task :stop, :roles => :app do - run "kill -s QUIT `cat #{current_path}/tmp/pids/unicorn.pid`" + def foreman_format(opts) + opts.map {|opt,value| "--#{opt}='#{value}'" }.join(' ') end end + +after 'deploy:update', 'foreman:export' + +namespace :bluepill do + desc "Stop processes that bluepill is monitoring and quit bluepill" + task :quit, roles: :app do + run "cd #{release_path} && #{sudo} bundle exec bluepill stop" + run "cd #{release_path} && #{sudo} bundle exec bluepill quit" + end + + desc "Load bluepill configuration and start it" + task :start, roles: :app do + run "cd #{current_path} && #{sudo} bundle exec bluepill load #{foreman_location_path}/#{application}.pill" + end + + desc "Prints bluepills monitored processes statuses" + task :status, roles: :app do + run "cd #{release_path} && #{sudo} bundle exec bluepill status" + end +end + +after "deploy:update", "bluepill:quit", "bluepill:start" + +namespace :deploy do + desc "Create a symbolic link .env file to release path" + task :link_dotenv, roles: :app do + run "ln -fns #{shared_path}/config/.env #{release_path}/.env" + end +end + +before 'deploy:assets:precompile', 'deploy:link_dotenv'