Skip to content

Instantly share code, notes, and snippets.

@cpfarher
Created November 21, 2013 22:48
Show Gist options
  • Select an option

  • Save cpfarher/7591238 to your computer and use it in GitHub Desktop.

Select an option

Save cpfarher/7591238 to your computer and use it in GitHub Desktop.
Deploy con capistrano
set :application, 'myapp'
set :scm, :git
set :repository, '[email protected]:repo/myapp.git'
set :branch, "master"
set :use_sudo, false
set :deploy_via, :copy
namespace :deploy do
desc 'Restart application'
task :restart do
on roles(:app), in: :sequence, wait: 5 do
# Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
end
end
after :restart, :clear_cache do
on roles(:web), in: :groups, limit: 3, wait: 10 do
# Here we can do anything such as:
# within release_path do
# execute :rake, 'cache:clear'
# end
end
end
after :finishing, 'deploy:cleanup'
end
christian@toshichri:~/public_html/rails/myapp$ cap production deploy:check
INFO [3148ade1] Running /usr/bin/env mkdir -p /tmp/myapp/ on 192.168.1.103
DEBUG [3148ade1] Command: /usr/bin/env mkdir -p /tmp/myapp/
cap aborted!
Net::SSH::AuthenticationFailed
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/net-ssh-2.7.0/lib/net/ssh.rb:215:in `start'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:156:in `ssh'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:109:in `block in _execute'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:106:in `tap'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:106:in `_execute'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:54:in `execute'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/capistrano-3.0.1/lib/capistrano/tasks/git.rake:13:in `block (3 levels) in <top (required)>'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:42:in `instance_exec'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/backends/netssh.rb:42:in `run'
/home/christian/.rvm/gems/ruby-1.9.3-p448/gems/sshkit-1.1.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
(See full trace by running task with --trace)
christian@toshichri:~/public_html/rails/myapp$
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
#role :app, %w{[email protected]}
#role :web, %w{[email protected]}
#role :db, %w{[email protected]}
set :keep_releases, 5
set :user, "christian" #user ssh vps
#set :scm_passphrase, "password"
set :deploy_to, '/home/#{user}/#{application}'
#vps
role :web, "192.168.1.103"
role :app, "192.168.1.103"
role :db, "192.168.1.103", :primary => true
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
# and/or per server
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
# setting per server overrides global ssh_options
# fetch(:default_env).merge!(rails_env: :production)
set :stage, :staging
# Simple Role Syntax
# ==================
# Supports bulk-adding hosts to roles, the primary
# server in each group is considered to be the first
# unless any hosts have the primary property set.
role :app, %w{[email protected]}
role :web, %w{[email protected]}
role :db, %w{[email protected]}
# Extended Server Syntax
# ======================
# This can be used to drop a more detailed server
# definition into the server list. The second argument
# something that quacks like a hash can be used to set
# extended properties on the server.
server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value
# you can set custom ssh options
# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options
# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start)
# set it globally
# set :ssh_options, {
# keys: %w(/home/rlisowski/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(password)
# }
# and/or per server
# server 'example.com',
# user: 'user_name',
# roles: %w{web app},
# ssh_options: {
# user: 'user_name', # overrides user setting above
# keys: %w(/home/user_name/.ssh/id_rsa),
# forward_agent: false,
# auth_methods: %w(publickey password)
# # password: 'please use keys'
# }
# setting per server overrides global ssh_options
# fetch(:default_env).merge!(rails_env: :staging)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment