Skip to content

Instantly share code, notes, and snippets.

@mpapis
Forked from workmaster2n/bundle show paperclip
Last active December 18, 2015 23:49
Show Gist options
  • Save mpapis/5864065 to your computer and use it in GitHub Desktop.
Save mpapis/5864065 to your computer and use it in GitHub Desktop.
deployer@arcsite:~/apps/arcsite/current$ bundle show paperclip
/home/deployer/.rvm/gems/ruby-1.9.3-p392@arcsite_mysql/gems/paperclip-3.4.2
require "bundler/capistrano"
require "rvm/capistrano"
set :application, "arcsite"
set :repository, "git@github.com:PeritusSolutions/arcsite_mysql.git"
set :branch, "master"
set :user, "deployer"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :deploy_via, :remote_cache
set :use_sudo, false
#rvm
set :rvm_ruby_string, :local
set :rvm_autolibs_flag, :enable
set :rvm_install_with_sudo, true
set :bundle_flags, '--system'
before 'deploy:setup', 'rvm:install_rvm' # install RVM
before 'deploy:setup', 'rvm:install_ruby' # install Ruby and create gemset
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
set :scm, :git # You can set :scm explicitly or Capistrano will make an intelligent guess based on known version control directory names
# Or: `accurev`, `bzr`, `cvs`, `darcs`, `git`, `mercurial`, `perforce`, `subversion` or `none`
#server "192.168.0.30", :web, :app, :db, primary: true
server "198.199.105.200", :web, :app, :db, primary: true
#role :web, "your web-server here" # Your HTTP server, Apache/etc
#role :app, "your app-server here" # This may be the same as your `Web` server
#role :db, "your primary db-server here", :primary => true # This is where Rails migrations will run
#role :db, "your slave db-server here"
# if you want to clean up old releases on each deploy uncomment this:
after "deploy:restart", "deploy:cleanup"
# if you're still using the script/reaper helper you will need
# these http://github.com/rails/irs_process_scripts
# If you are using Passenger mod_rails uncomment this:
# namespace :deploy do
# task :start do ; end
# task :stop do ; end
# task :restart, :roles => :app, :except => { :no_release => true } do
# run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
# end
# end
namespace :deploy do
task :rvm_app_alias, roles: :app do
run "rvm alias create #{application} #{rvm_ruby_string}"
run "rvm wrapper #{application} --no-links --all"
end
after "deploy:finalize_update", "deploy:rvm_app_alias"
%w[start stop restart].each do |command|
desc "#{command} unicorn server"
task command, roles: :app, except: {no_release: true} do
run "/etc/init.d/unicorn_#{application} #{command}"
end
end
task :setup_config, roles: :app do
sudo "ln -nfs #{current_path}/config/nginx.conf /etc/nginx/sites-enabled/#{application}"
sudo "ln -nfs #{current_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
run "mkdir -p #{shared_path}/config"
put File.read("config/database.example.yml"), "#{shared_path}/config/database.yml"
puts "Now edit the config files in #{shared_path}."
end
after "deploy:setup", "deploy:setup_config"
task :symlink_config, roles: :app do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
after "deploy:finalize_update", "deploy:symlink_config"
desc "Make sure local git is in sync with remote."
task :check_revision, roles: :web do
unless `git rev-parse HEAD` == `git rev-parse origin/master`
puts "WARNING: HEAD is not the same as origin/master"
puts "Run `git push` to sync changes."
exit
end
end
before "deploy", "deploy:check_revision"
#precompile assets only when needed
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
end
Tylers-MacBook-Pro:arcsite_mysql tyler$ cap deploy:migrations
* 2013-06-25 16:02:46 executing `deploy:migrations'
* 2013-06-25 16:02:46 executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git@github.com:PeritusSolutions/arcsite_mysql.git master"
command finished in 1669ms
* executing "if [ -d /home/deployer/apps/arcsite/shared/cached-copy ]; then cd /home/deployer/apps/arcsite/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard e9a02ca057f822c8709ecb790177c78db6af8021 && git clean -q -d -x -f; else git clone -q -b master git@github.com:PeritusSolutions/arcsite_mysql.git /home/deployer/apps/arcsite/shared/cached-copy && cd /home/deployer/apps/arcsite/shared/cached-copy && git checkout -q -b deploy e9a02ca057f822c8709ecb790177c78db6af8021; fi"
servers: ["198.199.105.200"]
[198.199.105.200] executing command
command finished in 4356ms
copying the cached version to /home/deployer/apps/arcsite/releases/20130625210253
* executing "cp -RPp /home/deployer/apps/arcsite/shared/cached-copy /home/deployer/apps/arcsite/releases/20130625210253 && (echo e9a02ca057f822c8709ecb790177c78db6af8021 > /home/deployer/apps/arcsite/releases/20130625210253/REVISION)"
servers: ["198.199.105.200"]
[198.199.105.200] executing command
command finished in 751ms
* 2013-06-25 16:02:53 executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* 2013-06-25 16:02:53 executing `deploy:assets:symlink'
* executing "rm -rf /home/deployer/apps/arcsite/releases/20130625210253/public/assets && mkdir -p /home/deployer/apps/arcsite/releases/20130625210253/public && mkdir -p /home/deployer/apps/arcsite/shared/assets && ln -s /home/deployer/apps/arcsite/shared/assets /home/deployer/apps/arcsite/releases/20130625210253/public/assets"
servers: ["198.199.105.200"]
[198.199.105.200] executing command
command finished in 593ms
* 2013-06-25 16:02:54 executing `bundle:install'
* executing "cd /home/deployer/apps/arcsite/releases/20130625210253 && bundle install --gemfile /home/deployer/apps/arcsite/releases/20130625210253/Gemfile --path /home/deployer/apps/arcsite/shared/bundle --system --without development test"
servers: ["198.199.105.200"]
[198.199.105.200] executing command
** [out :: 198.199.105.200] You have specified both a path to install your gems to,
** [out :: 198.199.105.200]
** [out :: 198.199.105.200] as well as --system. Please choose.
** [out :: 198.199.105.200]
command finished in 990ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-1.9.3-p392@arcsite_mysql' -c 'cd /home/deployer/apps/arcsite/releases/20130625210253 && bundle install --gemfile /home/deployer/apps/arcsite/releases/20130625210253/Gemfile --path /home/deployer/apps/arcsite/shared/bundle --system --without development test'" on 198.199.105.200
Tylers-MacBook-Pro:arcsite_mysql tyler$
E, [2013-06-25T21:15:45.960566 #341] ERROR -- : uninitialized constant Paperclip (NameError)
/home/deployer/apps/arcsite/releases/20130625211233/config/initializers/paperclip_custom_interpolator.rb:1:in `<top (required)>'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:588:in `block (2 levels) in <class:Engine>'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:587:in `each'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/engine.rb:587:in `block in <class:Engine>'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `instance_exec'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:30:in `run'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `each'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/initializable.rb:54:in `run_initializers'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/application.rb:136:in `initialize!'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/railties-3.2.13/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/deployer/apps/arcsite/releases/20130625211233/config/environment.rb:5:in `<top (required)>'
config.ru:4:in `require'
config.ru:4:in `block in <main>'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn.rb:44:in `eval'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn.rb:44:in `block in builder'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:722:in `call'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:722:in `build_app!'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:595:in `init_worker_process'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:615:in `worker_loop'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:511:in `maintain_worker_count'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:277:in `join'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/bin/unicorn:126:in `<top (required)>'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `load'
/home/deployer/apps/arcsite/shared/bundle/ruby/1.9.1/bin/unicorn:23:in `<main>'
# Just part of it
gem 'pg'
gem 'rgeo'
gem 'rgeo-shapefile'
gem 'activerecord-postgis-adapter'
gem 'paperclip'
upstream unicorn {
server unix:/tmp/unicorn.arcsite.sock fail_timeout=0;
}
server {
listen 80 default deferred;
# server_name example.com;
root /home/deployer/apps/arcsite/current/public;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://unicorn;
}
error_page 500 502 503 504 /500.html;
client_max_body_size 4G;
keepalive_timeout 10;
}
Paperclip.interpolates :zone do |attachment, style|
attachment.instance.zone_id
end
root = "/home/deployer/apps/arcsite/current"
working_directory root
pid "#{root}/tmp/pids/unicorn.pid"
stderr_path "#{root}/log/unicorn.log"
stdout_path "#{root}/log/unicorn.log"
listen "/tmp/unicorn.arcsite.sock"
worker_processes 2
timeout 30
#!/bin/sh
set -e
# Feel free to change any of the following variables for your app:
TIMEOUT=${TIMEOUT-60}
APP_NAME=arcsite
PATH="$HOME/.rvm/wrappers/$APP_NAME:$PATH"
APP_ROOT=/home/deployer/apps/$APP_NAME/current
PID=$APP_ROOT/tmp/pids/unicorn.pid
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production"
AS_USER=deployer
set -u
OLD_PIN="$PID.oldbin"
sig () {
test -s "$PID" && kill -$1 `cat $PID`
}
oldsig () {
test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
}
run () {
if [ "$(id -un)" = "$AS_USER" ]; then
eval $1
else
su -c "env PATH='$PATH' $1" - $AS_USER
fi
}
case "$1" in
start)
sig 0 && echo >&2 "Already running" && exit 0
run "$CMD"
;;
stop)
sig QUIT && exit 0
echo >&2 "Not running"
;;
force-stop)
sig TERM && exit 0
echo >&2 "Not running"
;;
restart|reload)
sig HUP && echo reloaded OK && exit 0
echo >&2 "Couldn't reload, starting '$CMD' instead"
run "$CMD"
;;
upgrade)
if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
then
n=$TIMEOUT
while test -s $OLD_PIN && test $n -ge 0
do
printf '.' && sleep 1 && n=$(( $n - 1 ))
done
echo
if test $n -lt 0 && test -s $OLD_PIN
then
echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
exit 1
fi
exit 0
fi
echo >&2 "Couldn't upgrade, starting '$CMD' instead"
run "$CMD"
;;
reopen-logs)
sig USR1
;;
*)
echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
exit 1
;;
esac
@workmaster2n
Copy link

Getting a new error related to the deploy task. It doesn't like the command line argument 'wrappers' to rvm. I ran rvm get stable on the machine and tried redeploying. Got the same error:

 * executing "rvm wrappers arcsite --no-links --all"
    servers: ["198.199.105.200"]
    [198.199.105.200] executing command
 ** [out :: 198.199.105.200] Unrecognized command line argument: 'wrappers' ( see: 'rvm usage' )
 ** [out :: 198.199.105.200] 
    command finished in 1019ms
*** [deploy:update_code] rolling back
  * executing "rm -rf /home/deployer/apps/arcsite/releases/20130626022103; true"
    servers: ["198.199.105.200"]
    [198.199.105.200] executing command
    command finished in 717ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell 'ruby-1.9.3-p392@arcsite_mysql' -c 'rvm wrappers arcsite --no-links --all'" on 198.199.105.200

@mpapis
Copy link
Author

mpapis commented Jun 26, 2013

ah it's because it is wrapper not wrappers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment