I am trying to set up Capistrano to deploy a website on a remote server. When I run the following command:
cap production deploy
I get the following error:
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host domain.com: Authentication failed for user #domain.com
Here is my deploy.rb file in the config directory of my Rails app:
...
set :application, 'my-app'
set :repo_url, 'git#bitbucket.org:karns/my-app.git'
set :deploy_to, "/var/www/my-app"
# Default value for :scm is :git
set :scm, :git
set :branch, 'master'
set :user, "deploy"
set :use_sudo, false
set :rails_env, "production"
set :deploy_via, :copy
server "domain.com", roles: [:app, :web, :db], :primary => true
...
To my understanding, deploy is supposed to be the user on the remote server.
What am I missing? Why does the error say "Authentication failed for user #domain.com"? Why wouldn't it say "deploy#domain.com"? If you need any other code, please let me know.
Related
I would like to deploy my app using capistrano.
I'm able to connect to the server using ssh my_app_stag, but when I try to docker-compose run web cap staging deploy I get this error :
D, [2018-09-21T11:46:40.858453 #1] DEBUG -- net.ssh.authentication.agent[ac989c]: connecting to ssh-agent
E, [2018-09-21T11:46:40.858662 #1] ERROR -- net.ssh.authentication.agent[ac989c]: could not connect to ssh-agent: Agent not configured
E, [2018-09-21T11:46:40.859037 #1] ERROR -- net.ssh.authentication.session[3f9c0e0cac1c]: all authorization methods failed (tried publickey)
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as ubuntu#34.244.167.85: Authentication failed for user ubuntu#34.244.167.85
Caused by:
Net::SSH::AuthenticationFailed: Authentication failed for user ubuntu#34.244.167.85
Tasks: TOP => rvm:hook
(See full trace by running task with --trace)
I'm using pem key to authenticate, which is located in .ssh/app_name.pem (this key was included on the repo when I cloned the app. So I did not generate it my self)
ssh/config
Host my_app_stag
ForwardAgent yes
Hostname my_Ip_adress
User ubuntu
IdentityFile /Users/my_name/.ssh/app_name.pem
deploy.rb
lock '3.10.0'
set :rvm_ruby_version, '2.3.3'
set :default_stage, 'staging'
set :stages, %w(staging production)
set :application, 'app_name'
set :repo_url, 'git#github.com:my_account/app_name.git'
set :full_app_name, "#{fetch(:application)}"
set :user, 'ubuntu'
set :use_sudo, false
# Default branch is :master
set :branch, fetch(:branch, "master")
# Default deploy_to directory is /var/www/my_app_name
set :deploy_to, "/var/www/apps/#{fetch(:full_app_name)}"
# Default value for :scm is :git
set :ssh_options, {
auth_methods: %w[publickey],
keys: %w(~/.ssh/app_name.pem),
:verbose => :debug
}
set :use_agent, false
set :pty, true
[]).push('config/database.yml', 'config/secrets.yml')
set :linked_files, %w{config/database.yml config/unicorn_init.sh config/unicorn.rb log/session.secret}
set :linked_dirs, %w{log tmp/pids public/assets public/images/promotions public/images/logo public/images/offers public/images/vehicules public/import_logs sitemaps}
# Default value for keep_releases is 5
set :keep_releases, 5
set :bundle_bins, %w{gem rake ruby}
set(:config_files, %w(
nginx.conf
database.yml
unicorn.rb
unicorn_init.sh
))
set(:executable_config_files, %w(
unicorn_init.sh
))
set(:symlinks, [
{
source: "nginx.conf",
link: "/etc/nginx/sites-enabled/#{fetch(:full_app_name)}"
},
{
source: "unicorn_init.sh",
link: "/etc/init.d/unicorn_#{fetch(:full_app_name)}"
}
])
# set :linked_dirs, %w(public/system log tmp)
set :linked_dirs, fetch(:linked_dirs, []).push('log', 'tmp', 'vendor/bundle', 'public/system')
staging.rb
server 'ip_server', user: 'ubuntu', roles: %w(app db web), primary: true
set :stage, :staging
set :rails_env, 'staging'
set :branch, 'develop'
I tried this article but it still doesn't work.
Maybe add your ssh-key to a ssh-agent instead of linking to the file?
ssh-add -K /Users/my_name/.ssh/app_name.pem
So I have a rails app and am deploying to ec2. I successfully did cap deploy:setup, cap deploy:check, and cap:deploy. I then tried to access the url, but I'm not actually sure where my app is or if there are more steps. I tried accessing http://xxx.us-west-2.compute.amazonaws.com/var/www/highlandsfacebookart, but got nothing.
Here is my deploy.rb
set :application, "highlandsfacebookart"
set :repository, "repository-url"
set :user, 'ec2-user'
set :use_sudo, false
set :deploy_to, "/var/www/#{application}#"
#set :deploy_via, :remote_cache
set :deploy_via, :copy
set :normalize_asset_timestamps, false
set :ssh_options, { :forward_agent => true }
ssh_options[:keys] = %w(~/highlandsfbkey.pem)
set :scm, "git"
# 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`
role :web, "xxx.compute.amazonaws.com" # Your HTTP server, Apache/etc
role :app, "xxx.us-west-2.compute.amazonaws.com" # This may be the same as your `Web` server
role :db, "xxx.us-west-2.compute.amazonaws.com", :primary => true # This is where Rails migrations will run
role :db, "xxx.compute.amazonaws.com"
Not sure, but have you configured your instance to serve your website using a web server like Nginx? Set it up so it's listening on port 80 and pointing to the correct folders. Nginx integration in Capistrano is possible I believe.
Can you verify that your instances are running when you're accessing EC2's console on aws.amazon.com/console? (Sorry, I wish I had enough reputation to make this a comment)
I am writing one capistrano script to deploy a PHP application here is my basic script
set :default_stage, "staging"
ssh_options[:forward_agent] = true
server "capistrano.myserver.com", :app, :web, :db, :primary => true
set :application, "PHP_App_capified"
set :scm, :git
set :repository, '.'
default_run_options[:pty] = true
set :user, 'capi5784'
set :deploy_to, "/home/user/public_html"
set :deploy_via, :copy
set :use_sudo, false
set :copy_exclude, [".git", ".DS_Store", ".gitignore", ".gitmodules", "Capfile", "config/deploy.rb"]
when I run the cap deploy I am getting the following error
failed: "sh -c 'cd /home/myserver/public_html/releases && tar xzf /tmp/20130808120301.tar.gz && rm /tmp/20130808120301.tar.gz'" on capistrano.myserver.com
Any suggestions what I am doing wrong ?
Two things:
Can you ssh into capistrano.myserver.com from your machine?
I think you need to enable use_sudo.
set :use_sudo, true
You would need sudo access to delete something from /tmp
I'm following this guide for deploying a rails app via capistrano: https://github.com/capistrano/capistrano/wiki/2.x-From-The-Beginning
I'm using linode as my VPS. I've done all the initial setup and cap deploy:setup/update/deploy all work. When I go to execute this command in my rails directory: $ rake RAILS_ENV=production db:schema:load. I get undefined method 'minutes' for 90:Fixnum. It seems that activesupport is somehow not installed, yet when I type rails --version, I get Rails 3.2.11. Any insight would be extremely helpful!
Here's my deploy.rb file:
require 'bundler/capistrano'
require "capistrano-rbenv"
set :rbenv_ruby_version, "1.9.3-p392"
set :application, "uganda-coords"
# Deploy from your local Git repo by cloning and uploading a tarball
set :scm, :git
set :repository, "git#github.com:benrudolph/myapp.git"
set :deploy_via, :copy
set :scm_passphrase, "mypassword"
set :branch, "master"
set :deploy_via, :remote_cache
set :rails_env, "production"
set :user, :root
set :deploy_to, "/var/www/#{application}"
set :use_sudo, false
set :ssh_options, { :forward_agent => true }
role :web, "176.58.105.165" # Your HTTP server, Apache/etc
role :app, "176.58.105.165" # This may be the same as your `Web` server
role :db, "176.58.105.165", :primary => true # This is where Rails migrations will run
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
Turns out this had to do with using 90.minutes in my application.rb file. I still don't know why this works on dev and not production.
My working deployment script is failing with upload via sftp failed on XX.XXX.XXX.XXX: Net::SFTP::StatusException (Net::SFTP::StatusException write /tmp/20130610114941.tar.gz (4, "failure")) error.
here is my deployment script
require "rvm/capistrano"
require "bundler/capistrano"
set :rvm_type, :user
set :rvm_ruby_string, 'ruby-2.0.0-p0'
set :user, "deployer"
set :application, "myapp"
set :deploy_to, "/home/#{user}/apps/#{application}"
set :bundle_dir, "/home/#{user}/.rvm/gems/ruby-2.0.0-p0"
server "XX.XXX.XXX.XXX", :web, :app, :db, primary: true
set :use_sudo, false
set :deploy_via, :copy
set :repository, "."
set :copy_exclude, %w[.git log tmp .DS_Store]
set :scm, :none
default_run_options[:pty] = true
after "deploy", "deploy:cleanup" # keep only the last 5 releases
namespace :deploy do
task :start do
;
end
task :stop do
;
end
task :restart, roles: :app, except: {no_release: true} do
run "touch #{deploy_to}/current/tmp/restart.txt"
end
end
Any idea?
Thanks
Edit: Just checked and my disk space is full. Obviously this is my problem. An after update hook to prevent this?
From the comments:
check available disk space on the server for /tmp
df /tmp
free up space if necessary
alternatively configure capistrano to use a different folder to deploy to (How do I change the temporary directory that Capistrano uses?)
you may want to look at removing old releases if you are not already doing so
cap deploy:cleanup