Topic: Capistrano Deployment problems with DH using casper recipie

Could anyone have a quick scan through my deployment file?
I've been trying to deploy an application of mine on to my dreamhost account; I'm pretty sure I have everything set up correctly, but i'm still getting an error!

I've been following and using modified scripts from this website
http://casperfabricius.com/blog/2006/05 … dreamhost/

However, I'm using a different location to the application's location for my database.
I've modified deploy.rb accordingly, so it looks like the following

set :user, 'daffy'
set :application, "fyp.mydomain.com"
set :repository, "http://fyp.mydomain.com/repos/meals/trunk"
set :svn_username, "username"

role :web, application
role :app, application
role :db,  "mysql.mydomain.com", :primary => true


I removed the rails engine part in environment.rb because my application doesn't use them.

the output, when running 'rake remote:exec ACTION=setup' on my local machine, looks like the following:

C:0:Warning: require_gem is obsolete.  Use gem instead.
Capistrano/Rake integration is deprecated.
Please invoke the 'cap' command directly: `cap setup'
  * executing task setup
  * executing "umask 02 &&\n    mkdir -p /home/daffy/fyp.mydomain.com /home/daffy/fyp.mydomain.com/releases /home/daffy/fyp.mydomain.com/shared /home/daffy/fyp.mydomain.com/shared/system &&\n
   mkdir -p /home/daffy/fyp.mydomain.com/shared/log &&\n    mkdir -p /home/daffy/fyp.mydomain.com/shared/pids"
    servers: ["fyp.mydomain.com", "mysql.mydomain.com"]
Password: ##########

c:/ruby/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh/session.rb:132:in `initialize': daffy (Net::SSH::Authen ticationFailed)
        from c:/ruby/lib/ruby/gems/1.8/gems/net-ssh-1.0.10/lib/net/ssh.rb:47:in `new'
        ...omitted...
        from c:/ruby/bin/rake.bat:20


any ideas?
I'm not sure what the big 'executing' bit in that means or where it comes from, can anyone enlighten me?
thanks in advance!,
daf

Last edited by daffy_dowden (2007-03-31 09:21:27)

Re: Capistrano Deployment problems with DH using casper recipie

Looks like your SSH is failing. Are you able to log-in to your server through SSH (outside of capistrano)? Are you using the same username & pass for capistrano?

daffy_dowden wrote:

I'm not sure what the big 'executing' bit in that means or where it comes from, can anyone enlighten me?

It's just executing a command to make several directories. It never ends up executing it because of the error.

Railscasts - Free Ruby on Rails Screencasts

Re: Capistrano Deployment problems with DH using casper recipie

yeah, I log into the server using putty. The username i use for capistrano is different to that used for the shell though; but I thought I'd coded this into the files.

Re: Capistrano Deployment problems with DH using casper recipie

Does the SSH login match the ":user" attribute you specified in the deploy.rb file?

Railscasts - Free Ruby on Rails Screencasts

Re: Capistrano Deployment problems with DH using casper recipie

yeah definitely, if I run 'whoami' on putty conncted to DH it says daffy_dowden, just like the deploy.rb file.

Re: Capistrano Deployment problems with DH using casper recipie

I believe the problem lies with the fact that my database is hosted on mysql.mydomain.com not fyp.mydomain.com, which the ap server and web server are set to. When i run 'rake remote:exec ACTION=setup' and change the deploy script using the same, but incorrect, value for the database server as the application and www server (fyp.mydomain.com) then the script will run without error. So my question is this, what commands is the script trying to run on the database server, and why? it seems to me that it shouldn't need to set up any directories or execute anything on that server, or am I wrong?
cheers,
daf

Re: Capistrano Deployment problems with DH using casper recipie

You're right, looks like that's the problem.

Do you have the same problem when running the cap command instead of using "rake"?

cap setup

Railscasts - Free Ruby on Rails Screencasts

Re: Capistrano Deployment problems with DH using casper recipie

I get the error message below; I really don't understand this though because it's not trying to execute any of those commands on the mysql machine, so why is it failing?!?

>cap setup
  * executing task setup
  * executing "umask 02 &&\n    mkdir -p /home/daffy/fyp.mydomain.com /home/daffy/fyp.mydomain.com/releases /home/daffy/fyp.mydomain.com/shared /home/daffy/fyp.mydomain.com/shared/system &&\n
   mkdir -p /home/daffy/fyp.mydomain.com/shared/log &&\n    mkdir -p /home/daffy/fyp.mydomain.com/shared/pids"
    servers: ["mysql.mydomain.com", "fyp.mydomain.com"]
Password: <sshPassword>

authentication failed for `daffy'


This is so annoying lol, I really want to get this working to use as a guide for any other rails projects I deploy on DH! thanks for all your help so far though! much appreciated!
daf

Last edited by daffy_dowden (2007-03-31 09:19:04)

Re: Capistrano Deployment problems with DH using casper recipie

Try removing the ":primary => true" parameter when you specify the :db role.

Although I'm not certain why it is trying to ssh into the database server, one of the assumptions capistrano makes is that all servers use the same password. Not sure why.

What happens when you specify your web server as the database server? I'm thinking capistrano might read the database.yml file when doing migrations and such so I don't think it really needs to be the database server? I'm not sure.

Railscasts - Free Ruby on Rails Screencasts

Re: Capistrano Deployment problems with DH using casper recipie

removing :primary => true, doesn't have any effect, but changing db to the same as the ap server allows the cap setup command to run. But cap migrate breaks, it can't find the current directory on the server, but the releases and shared directories have been created. I'm getting confused over the order and the commands i should be using; is it cap setup => cap migrate => cap deploy (the order I think it is, though i'm only on command 2 of 3), or should i be using the rake commands, i thought those were deprecated though, or a hybrid?

Last edited by daffy_dowden (2007-03-30 18:49:45)

Re: Capistrano Deployment problems with DH using casper recipie

Ok scratch that. I've had a good old read of the manual, apologies for not doing it sooner - it didn't realise it was so short! Anyway, as far as I can tell the cap commands are only for very basic deployments, and the rake commands allow for greater control in more advanced deployments.
The flow of command execution goes something like this:
rake remote:exec ACTION=setup
rake db:migrate (or cap migrate) - to set up the db
rake remote:exec ACTION=cold_deploy
and then rake deploy

all sound good?
anyway, I finally have the ap deployed but not running, upon execution of the cold_deploy command  I get the message that the spinner and the fcgi_handler cannot be found, and if look in the scripts directory they aren't there. So where are they, or where do they come from?

I must be so very close now!

output from cold deploy:

> rake remote:exec ACTION=cold_deploy
C:0:Warning: require_gem is obsolete.  Use gem instead.
Capistrano/Rake integration is deprecated.
Please invoke the 'cap' command directly: `cap cold_deploy'
  * executing task cold_deploy
  * executing task update
** transaction: start
  * executing task update_code
Password: svnPassword
  * querying latest revision...
  * executing "if [[ ! -d /home/daffy/fyp.mydomain.com/releases/20070331123331 ]]; then\n              svn e
xport --no-auth-cache --username svnusername --password svnPassword -q -r43 http://fyp.mydomain.com/repos/meals/trunk /home/daffy/fyp.mydomain.com/releases/20070331123331 &&\n              (test -e /home/daffy/fyp.mydomain.com/revisions.log || (touch /home/daffy/fyp.mydomain.com/revisions.log && chmod 666 /home/daffy/fyp.mydomain.com/revisions.log)) && echo `date +\"%Y-%m-%d %H:%M:%S\"` $USER 43 20070331123331 >> /home/daffy/fyp.mydomain.com/revisions.log;\n           
fi"
    servers: ["fyp.mydomain.com"]
Password: sshPassword

    [fyp.mydomain.com] executing command
    command finished
  * executing task set_permissions
  * executing "chmod -R g+w /home/daffy/fyp.mydomain.com/releases/20070331123331"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
    command finished
  * executing "rm -rf /home/daffy/fyp.mydomain.com/releases/20070331123331/log /home/daffy/fyp.mydomain.com/releases/20070331123331/public/system &&\n    ln -nfs /home/daffy/fyp.mydomain.com/shared/log /home/daffy/fyp.mydomain.com/releases/20070331123331/log &&\n    ln -nfs /home/daffy/fyp.mydomain.com/shared/system /home/daffy/fyp.mydomain.com/releases/20070331123331/public/system"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
    command finished
  * executing "test -d /home/daffy/fyp.mydomain.com/shared/pids && \n    rm -rf /home/daffy/fyp.mydomain.com/releases/20070331123331/tmp/pids && \n    ln -nfs /home/daffy/fyp.mydomain.com/shared/pids /home/daffy/fyp.mydomain.com/releases/20070331123331/tmp/pids; true"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
    command finished
  * executing "TZ=UTC find /home/daffy/fyp.mydomain.com/releases/20070331123331/public/images /home/daffy/fyp.mydomain.com/releases/20070331123331/public/stylesheets /home/daffy/fyp.mydomain.com/releases/
20070331123331/public/javascripts -exec touch -t 200703311234.12 {} \\;; true"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
    command finished
  * executing task symlink
  * executing "ls -x1 /home/daffy/fyp.mydomain.com/releases"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
    command finished
  * executing "ln -nfs /home/daffy/fyp.mydomain.com/releases/20070331123331 /home/daffy/fyp.mydomain.com/current"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
    command finished
  * executing task after_symlink
  * executing "perl -i -pe \"s/#ENV\\['RAILS_ENV'\\] \\|\\|= 'production'/ENV['RAILS_ENV'] ||= 'production'/\" /home/daffy/fyp.mydomain.com/current/config/environment.rb"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
    command finished
  * executing "perl -i -pe \"s/require 'dispatcher'/require '\\/home\\/daffy\\/fyp.mydomain.com\\/current\\/
vendor\\/rails\\/railties\\/lib\\/dispatcher'/\" /home/daffy/fyp.mydomain.com/current/vendor/rails/railties/
lib/fcgi_handler.rb"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
** [out :: fyp.mydomain.com] Can't open /home/daffy/fyp.mydomain.com/current/vendor/rails/railties/lib
/fcgi_handler.rb: No such file or directory.
    command finished
  * executing "chmod a+x /home/daffy/fyp.mydomain.com/current/public/dispatch.fcgi"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
    command finished
** transaction: commit
  * executing task spinner
  * executing "/home/daffy/fyp.mydomain.com/current/script/spin"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
** [out :: fyp.mydomain.com] bash: line 1: /home/daffy/fyp.richarddowden.com/current/script/spin: No such file or directory
    command finished command "/home/daffy/fyp.mydomain.com/current/script/spin" failed on fyp.mydomain.com


UPDATE:
I gather you have to write your own update script but i've no idea what this should contain. The problem with fcgi_handler was because the script was attempting to use edge rails, but my project doesn't use this - Fixed by editing the deploy.rb script. When I run rake deploy all the commands but the last few seem to work, here's the output generated:
 ** transaction: commit
  * executing task restart
  * executing "ruby /home/daffy/fyp.mydomain.com/current/script/process/reaper --dispatcher=dispatch.fcgi"
    servers: ["fyp.mydomain.com"]
    [fyp.mydomain.com] executing command
** [out :: fyp.mydomain.com] /home/daffy/fyp.mydomain.com/current/script/process/../../config/boot.rb:
43:Warning: require_gem is obsolete.  Use gem instead.
** [out :: fyp.mydomain.com] Couldn't find any pid file in '/home/daffy/fyp.mydomain.com/current/tmp/p
ids' matching 'dispatch.[0-9]*.pid'
** [out :: fyp.mydomain.com] (also looked for processes matching "dispatch.fcgi")
    command finished

the site still doesn't work in the browser though...

Last edited by daffy_dowden (2007-03-31 11:18:39)

Re: Capistrano Deployment problems with DH using casper recipie

so... I'm still stumped on this, should it be working now? is my fastcgi handler broken?
man this deployment business is tricky!

Re: Capistrano Deployment problems with DH using casper recipie

Have you figured out why yet?  I've got a similar problem.

Re: Capistrano Deployment problems with DH using casper recipie

I put this forward to the guys at Dreamhost and they believed it was to do with my fcgi script, and they kindly fixed it for me. I've posted the amended script below and my deploy file (just in case), just change a few variables and hopefully, touch wood, it should work. I still have minor problems when updating the site, it takes a while for the changes to appear on the server, but I think this is an issue with dreamhost's setup. One tip is to make sure your ap is pointing to the correct location, mine wasn't, I forgot about the sub domain's directory in the setup.

fcgi script

#!/usr/bin/env ruby

require File.dirname(__FILE__) + "/../config/environment"

require 'fcgi_handler'

RailsFCGIHandler.process!


deploy.rb
set :user, 'ssh_name'
set :application, "subDirectoryName" #e.g. "myapp.mydomain.com"
set :repository, "http://svn.mydomain.com/repos/app/trunk"
set :svn_username, "svnU_Name"

# =============================================================================
# You shouldn't have to modify the rest of these
# =============================================================================

role :web, application
role :app, application
role :db,  application, :primary => true

set :deploy_to, "/home/#{user}/#{application}"
# set :svn, "/path/to/svn"       # defaults to searching the PATH
set :use_sudo, false
set :restart_via, :run
set :checkout, "export"
set(:svn_password) { Capistrano::CLI.password_prompt }


task :after_symlink, :roles => [:web, :app] do

run "perl -i -pe \"s/#ENV\\['RAILS_ENV'\\] \\|\\|= 'production'/ENV['RAILS_ENV'] ||= 'production'/\" #{current_path}/config/environment.rb"

run "chmod a+x #{current_path}/public/dispatch.fcgi"
end

task :restart, :roles => :app do
  run "ruby #{current_path}/script/process/reaper --dispatcher=dispatch.fcgi"
end


I'm not sure if any other files need changing, please let me know if this works.

Cheers,
Daf

Re: Capistrano Deployment problems with DH using casper recipie

I keep getting the following error message. cap deploy:setup and cap deploy:check both work fine. I can ssh in to the server fine. I've tried so many different combinations in deploy.rb it' driving me mad!!! As above I'm trying to deploy to dreamhost. Svn is in the normal location and runs fine.

/usr/lib/ruby/gems/1.8/gems/capistrano-1.99.2/lib/capistrano/recipes/deploy/scm/subversion.rb:56:in `query_revision': undefined method `[]' for false:FalseClass (NoMethodError)

I can run svn info on the server fine. This is so annoying!!

Last edited by aubergene (2007-06-27 16:56:15)