Showing posts with label capistrano. Show all posts
Showing posts with label capistrano. Show all posts

Monday, November 27, 2017

Capistrano is failing because it cannot connect to remote git repository

Leave a Comment

I am trying to deploy using capistrano 3.x

I configured AgentForwarding in my /.ssh/config file:

Host git-codecommit.*.amazonaws.com   Hostname xxxx   ForwardAgent yes   IdentityFile /path/to/codecommit_rsa 

I did the same thing for my server connection with ForwardAgent 'yes' also.

I verified my server allows agent forwaridng in the /etc/ssh/sshd_config file also.

AllowAgentForwarding yes     INFO ----------------------------------------------------------------    INFO START 2017-11-18 16:09:44 -0500 cap production deploy   INFO ---------------------------------------------------------------------------   INFO [b43ed70f] Running /usr/bin/env mkdir -p /tmp as deploy@50.116.2.15  DEBUG [b43ed70f] Command: /usr/bin/env mkdir -p /tmp   INFO [b43ed70f] Finished in 1.132 seconds with exit status 0 (successful).  DEBUG Uploading /tmp/git-ssh-testapp-production-blankman.sh 0.0%   INFO Uploading /tmp/git-ssh-testapp-production-blankman.sh 100.0%   INFO [b1a90dc1] Running /usr/bin/env chmod 700 /tmp/git-ssh-testapp-production-blankman.sh as deploy@50.116.2.15  DEBUG [b1a90dc1] Command: /usr/bin/env chmod 700 /tmp/git-ssh-testapp-production-blankman.sh   INFO [b1a90dc1] Finished in 0.265 seconds with exit status 0 (successful).   INFO [b323707d] Running /usr/bin/env git ls-remote ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/fuweb HEAD as deploy@50.116.2.15  DEBUG [b323707d] Command: ( export GIT_ASKPASS="/bin/echo" GIT_SSH="/tmp/git-ssh-testapp-production-blankman.sh" ; /usr/bin/env git ls-remote ssh://git-codecommit.us-east-1.amazonaws.com/v1/repos/fuweb HEAD )  DEBUG [b323707d]   Permission denied (publickey).  DEBUG [b323707d]   fatal: Could not read from remote repository.  Please make sure you have the correct access rights and the repository exists. 

What am I missing here?

3 Answers

Answers 1

You need to make Capistrano aware that you expect it to forward your local key. This can be done by going into you project's config/deploy.rb and adding this line:

ssh_options[:forward_agent] = true 

IIRC, Capistrano executes commands remotely through SSHKit, so even if you invoke the ssh-agent and add a key locally, I can't say if it will persist for the next command.

Answers 2

As discussed in the comments, an SSH agent must run on the remote server as well as on the local machine that contains the key because the agents at each end need to cooperate to forward the key information. The agent (ssh-agent) is different from the SSH server (sshd). The server accepts connections, while the (otherwise optional) agent manages credentials.

Some systems start an agent automatically upon login. To check if this is the case, log in to the server and run:

$ env | grep SSH 

...looking for variables like SSH_AGENT_PID or SSH_AGENT_SOCK. If it isn't started, we can execute the following command to start the agent on the server:

$ eval "$(ssh-agent)" 

As we can see, this evaluates the output of the ssh-agent command because ssh-agent returns a script that sets some needed environment variables in the session.

We'll need to make sure the agent starts automatically upon login so that it doesn't interfere with the deploy process. If we checked and determined that the agent does not, in fact, start on login, we can add the last command to the "deploy" user's ~/.profile file (or ~/.bash_profile).

Note also that the host specified in the local ~/.ssh/config must match the name or IP address of the host that we want to forward credentials to, not the host that ultimately authenticates using the forwarded key. We need to change:

Host git-codecommit.*.amazonaws.com 

...to:

Host 50.116.2.15 

We can verify that the SSH client performs agent forwarding by checking the verbose output:

$ ssh -v deploy@50.116.2.15 ... debug1: Requesting authentication agent forwarding. ... 

Of course, be sure to register any needed keys with the local agent by using ssh-add (this can also be done automatically when logging in as shown above). We can check which keys the agent loaded at any time with:

$ ssh-add -l 

Answers 3

This usually helps me:

ssh-add -D    ssh-agent     ssh-add       
Read More

Thursday, September 14, 2017

Passenger doesn't seem to be running (Capistrano/Rails/Apache/Ubuntu)

Leave a Comment

Deploying a Rails app using Capistrano to an Ubuntu VM running Apache with Passenger enabled.

I followed this tutorial: https://www.phusionpassenger.com/library/install/apache/install/oss/trusty/ with a few changes given that I'm on 17.04, not 14.04 LTS.

passenger-config validate-install says everything looks fine with both Passenger and Apache. passenger-memory-stats shows both Passenger and Apache processes.

I have sudo apache2ctl restarted several times, with no warnings. But passenger-status, and therefore the passenger-config restart-app that Capistrano runs, reports that Passenger "doesn't seem to be running." So my deploy stops.

There's only one Ruby on the machine, ruby-2.4.1 installed using ruby-install. I have apt-get update and upgraded in case of version mismatches.

Apache logs don't show any errors, certainly none related to Passenger.

Why would Passenger internally disagree, saying that it's both configured properly and there are processes running, but then later saying that it's not running?

1 Answers

Answers 1

Sorry to harp on this but did you run passenger-config validate-install on the ubuntu server (not osx)? Same for passenger-memory-stats and sudo apache2ctl restart.

Based on /tmp not having a passenger.randomstring dir, it sounds like you are confusing local and remote commands. /tmp is the default location for PassengerInstanceRegistryDirs on Ubuntu so if Passenger is running there should be a dir in /tmp that starts with passenger..

Read More

Sunday, May 14, 2017

Json -v 1.8.6 will not install as part of capistrano deploy

Leave a Comment

This question has been asked a couple of times on stackoverflow and other forums but I can't seem to get passed this error that I am getting. When I run capistrano production deploy, I get this error as part of the deploy process.

cap production bundler:install 00:00 bundler:install       01 bundle install --path /var/local/blackduck_flock_rails/shared/bundle --without development test --deployme…       01 An error occurred while installing json (1.8.6), and Bundler cannot continue.       01 Make sure that `gem install json -v '1.8.6'` succeeds before bundling. (Backtrace restricted to imported tasks) cap aborted!   SSHKit::Runner::ExecuteError: Exception while executing as serv-deployer@oh-utility01.dc1.lan: bundle exit status: 5 bundle stdout: An error occurred while installing json (1.8.6), and Bundler cannot continue. Make sure that `gem install json -v '1.8.6'` succeeds before bundling. bundle stderr: Nothing written   Tasks: TOP => bundler:install (See full trace by running task with --trace) 

I've taken a look at my log/capistrano.log file and here are the relevant contents that I was looking at to trouble shoot.

# Logfile created on 2017-05-03 14:42:16 -0400 by logger.rb/54072   INFO ---------------------------------------------------------------------------   INFO START 2017-05-03 14:42:16 -0400 cap production bundler:install   INFO ---------------------------------------------------------------------------  DEBUG [ec1d281e] Running if test ! -d /var/local/blackduck_flock_rails/current; then echo "Directory does not exist '/var/local/blackduck_flock_rails/current'" 1>&2; false; fi as serv-deployer@oh-utility01.dc1.lan  DEBUG [ec1d281e] Command: if test ! -d /var/local/blackduck_flock_rails/current; then echo "Directory does not exist '/var/local/blackduck_flock_rails/current'" 1>&2; false; fi  DEBUG [ec1d281e] Finished in 0.328 seconds with exit status 0 (successful).  DEBUG [4f633904] Running /usr/bin/env bundle check --path /var/local/blackduck_flock_rails/shared/bundle as serv-deployer@oh-utility01.dc1.lan  DEBUG [4f633904] Command: cd /var/local/blackduck_flock_rails/current && /usr/bin/env bundle check --path /var/local/blackduck_flock_rails/shared/bundle  DEBUG [4f633904]   Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.  DEBUG [4f633904]   The following gems are missing  * json (1.8.6)  * tzinfo (1.2.2)  * activesupport (4.2.6)   etc. etc..........    DEBUG [4f633904]    * uglifier (3.0.4)  DEBUG [4f633904]    Install missing gems with `bundle install`  DEBUG [4f633904] Finished in 0.179 seconds with exit status 1 (failed).   INFO [6c99e662] Running /usr/bin/env bundle install --path /var/local/blackduck_flock_rails/shared/bundle --without development test --deployment --quiet as serv-deployer@oh-utility01.dc1.lan  DEBUG [6c99e662] Command: cd /var/local/blackduck_flock_rails/current && /usr/bin/env bundle install --path /var/local/blackduck_flock_rails/shared/bundle --without development test --deployment --quiet  DEBUG [6c99e662]   An error occurred while installing json (1.8.6), and Bundler cannot continue. Make sure that `gem install json -v '1.8.6'` succeeds before bundling. 

So the first thing to note. The log is telling me that the running version of bundler is out of date and that I should install the newest one. Here is what I don't understand though. On my developing machine, I have Bundler version 1.14.6. On the targeting server that I am trying to deploy to, I also have Bundler version 1.14.6. I've confirmed it on both machines and they are indeed the same. Second, I have the same ruby versions for both developing machine and target machine. The ruby version is 2.2.5.

Second, when I run gem list on the target server, I can see that json 1.8.6 is installed.

json (1.8.3, 1.8.1) 

What gives?

Finally, the problem has to be in this directory on the target machine /var/local/blackduck_flock_rails/shared/bundle. Inside the bundle directory, I have a ruby folder that has 1.9.1 and 2.2.0. Could this be the source of the problem. I'm stumped on this one and it seems that questions like these always relate to something specific on someone's machine that won't necessarily be applied. Help would be greatly appreciated.

1 Answers

Answers 1

The most probable cause is you're missing some system dependencies that capistrano cannot install.

Ssh to your server and try installing sudo apt-get install libgmp3-dev

If it doesn't fix the problem, ssh again and run the gem install json -v '1.8.6' as it tells you and post the error message you get from it here.

Read More

Friday, March 25, 2016

Capistrano doesn't abort deployment when task fails

Leave a Comment

Capistrano doesn't abort when the executed commands exit status is different than 0. And continues to deployment. How can I abort the deployment when the executed command fails, returns an exit status different than 0?

I tried test, execute, capture commands but couldn't make it happened. Here is the recent code that I am testing failure, I actually running real jobs. When I try to execute in on the remote server, the exit status is 1.

   desc "Command to abort"    task :aborting_command do       on roles(:all) do |host|             within release_path do                execute("false")             end          end       end    end 

Output of it:

INFO [0ea66341] Running /usr/bin/env false on remote-server.xxx DEBUG [0ea66341] Command: cd /projectdir/releases/20160315140516 && /usr/bin/env false INFO [0ea66341] Finished in 0.044 seconds with exit status 0 (successful). 

With --trace:

** Invoke deploy:aborting_command (first_time) ** Execute deploy:aborting_command DEBUG [d5f30008] Running /usr/bin/env if test ! -d /projectdir/releases/20160315140254; then echo "Directory does not exist '/projectdir/releases/20160315140254'" 1>&2; false; fi on remote-server.xxx DEBUG [d5f30008] Command: if test ! -d /projectdir/releases/20160315140254; then echo "Directory does not exist '/projectdir/releases/20160315140254'" 1>&2; false; fi DEBUG [d5f30008] Finished in 0.042 seconds with exit status 0 (successful). INFO [50a2e035] Running /usr/bin/env false on remote-server.xxx DEBUG [50a2e035] Command: cd /projectdir INFO [50a2e035] Finished in 0.043 seconds with exit status 0 (successful). 

Working on with Capistrano Version: 3.4.0 (Rake Version: 10.4.2)

0 Answers

Read More