Welcome Guest | Login

noob question - deployment with capistrano

hi, i have a running test app on my machine and no problems. the files for capistrano are all set up and cap deploy works fine. all commands get executed and the log looks okay. my problem is that it does not upload my current local version.

i am getting confused. do i have to upload my local changes via svn or should capistrano do this step for me? as far as i understand it capistrano is checking out a svn version and puts it in my specified location on the server (maybe i am wrong).

sorry to bother you with simple things but i have to get a better understanding on how this works.

thanks

2008-06-03 02:20 AM

You will have to commit the changes to the svn repository before cap deployment. Please check the link below for more details. http://www.hostingrails.com/forums/wiki_thread/46

2008-06-03 03:41 AM

Regards,
Rahul
Hi Rahul,

Thank you very much. The site worked fine with fastcgi. I changed to mongrel now and everything was working fine. Now every time i upload a change to svn and run cap deploy it does not take the changes. If i try to restart it tells me that /log/mongrel.pid is missing. I figured that i have to kill the process and run cap deploy:setup and cap deploy:cold and it will take the changes. The server is not down it just does not take my changes. I already updated the crontab -e to:
# restart your mongrel server
@reboot cd /home/username/railsapp && /usr/local/bin/mongrel_rails stop && /usr/local/bin/mongrel_rails start -e production -p 4*** -d

thats all i have in there right now. would be great if you have an idea. I am sure it is a simple thing i am missing. Thanks again for your svn help.

2008-06-04 10:14 PM

Hello,]


I can see that the 'log' directory is a sym-link to a common path where the old 'mongrel.pid' file should exist.

Can you try the below restart task in you cap file/deploy.rb
=
task :restart_web_server, :roles => :app do
 run "cd #{release_path} && /usr/local/bin/mongrel_rails stop && /usr/local/bin/mongrel_rails start -e production -p #{mongrel_port} -d"

end
=

2008-06-04 11:17 PM

Regards,
Rahul
hi rahul,

sorry that it took so long to reply. had to make some $. anyhow, do you want me to add this code to the capfile or the config/deploy.rb file? i used it in both files and no success. if i use cap deploy:setup and then cap deploy:cold it works. i think thats because deploy:setup writes all the necessary files.

this process shows my changes online without problems. but as soon as i make further changes and use cap deploy the changes do not get updated but the server is still running with the previous changes. svn takes the revisions just fine.

if i use ps i can see that mongrel is still running. if i look in the log file i can see the mongrel.pid file but sometimes it is not there at all. very weird. it seems like the code deletes the file but does not restart to create a new one.

load 'deploy' if respond_to?(:namespace) # cap2 differentiator
load 'config/deploy'

here is my capfile:

# ========================
#     For FCGI Apps
# ========================
# NB: running the following :start task will delete your main public_html directory.
# So don't use these commands if you have existing sites in here.
#
#namespace :deploy do
#
#task :start, :roles => :app do
#run "rm -rf /home/#{user}/public_html;ln -s #{current_path}/public /home/#{user}/public_html"
#end
#
#task :restart, :roles => :app do
#run "#{current_path}/script/process/reaper --dispatcher=dispatch.fcgi"
#run "cd #{current_path} && chmod 755 #{chmod755}"
#end
#
#end

# ========================
#    For Mongrel Apps
# ========================
#
namespace :deploy do

  task :start, :roles => :app do
   run "rm -rf /home/#{user}/public_html;ln -s #{current_path}/public /home/#{user}/public_html"
    run "cd #{current_path} && mongrel_rails start -e production -p #{mongrel_port} -d"
  end

  task :restart, :roles => :app do
    run "cd #{current_path} && mongrel_rails restart"
    run "cd #{current_path} && chmod 755 #{chmod755}"
  end

end

# ========================
# For Mongrel Cluster Apps
# ========================

# namespace :deploy do
#
#   task :start, :roles => :app do
#     run "cd #{current_path} && mongrel_rails cluster::configure -e production -p #{mongrel_port}0 -N #{mongrel_nodes} -c #{current_path} --user #{user} --group #{user}"
#     run "cd #{current_path} && mongrel_rails cluster::start"
#     run "rm -rf /home/#{user}/public_html;ln -s #{current_path}/public /home/#{user}/public_html"
#     run "mkdir -p #{deploy_to}/shared/config"
#     run "mv #{current_path}/config/mongrel_cluster.yml #{deploy_to}/shared/config/mongrel_cluster.yml"
#     run "ln -s #{deploy_to}/shared/config/mongrel_cluster.yml #{current_path}/config/mongrel_cluster.yml"
#   end
#
#   task :restart, :roles => :app do
#     run "ln -s #{deploy_to}/shared/config/mongrel_cluster.yml #{current_path}/config/mongrel_cluster.yml"
#     run "cd #{current_path} && mongrel_rails cluster::restart"
#     run "cd #{current_path} && chmod 755 #{chmod755}"
#   end
#
# end



2008-06-06 05:10 PM

and here is my deploy.rb

set :application, "xxxx"            # Can be whatever you want, I use the project name from my SVN repository
set :domain, "xxxxx.com"                # The URL for your app
set :user, "xxx"                  # Your HostingRails username
set :repository,  "svn+ssh://#{user}@#{domain}/home/#{user}/svn/#{application}/trunk"  # The repository location for svn+ssh access
# set :repository, "http://svn.#{domain}/svn/#{application}/trunk"      # The repository location for http access from the server
# set :local_repository, "http://svn.#{domain}:port/svn/#{application}/trunk"      # The repository location for http access from the local machine (this could be different from above if you use ssh port forwarding for svn access
# set :scm_username, "svn_username" #if http
# set :scm_password, "svn_password" #if http
set :use_sudo, false                 # HostingRails users don't have sudo access
set :deploy_to, "/home/#{user}/apps/#{application}"          # Where on the server your app will be deployed
set :deploy_via, :checkout                # For this tutorial, svn checkout will be the deployment method
set :chmod755, "app config db lib public vendor script script/* public/disp*"   # Some files that will need proper permissions
set :mongrel_port, "4140"                # Mongrel port that was assigned to you
# set :mongrel_nodes, "4"                # Number of Mongrel instances for those with multiple Mongrels

default_run_options[:pty] = true
# Cap won't work on windows without the above line, see
# http://groups.google.com/group/capistrano/browse_thread/thread/13b029f75b61c09d
# Its OK to leave it true for Linux/Mac

ssh_options[:keys] = %w(/Path/To/id_rsa)            # If you are using ssh_keys

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

2008-06-06 05:12 PM

Hi Alpine,

I have now started the mongrel instance from the current release. Please issue a command

$ cap deploy:cold

from the local machine and verify if the new release is obtaining via Capistrano deployment. If the issue is still persisting then stop the mongrel instance from the current location using the following command and then do a Capistrano deployment.

$ mongrel_rails stop



2008-06-06 07:54 PM

hi vinayan,

i changed all my files back to default and did a fresh setup. now cap deploy works and restarts the server. i checked the pid with ps and it gives me a new timestamp every time i run cap deploy. so i assume that works fine.

the changes are still not uploaded. i have a feeling that there is a path problem of some kind. i can't figure out what's going on.  its loading the releases in the specified folder on the server but it does not show me the changes even after the server restarted successful.

hmm. i just can't figure it out. everything worked fine with fcgi. but mongrel does not apply my changes. i am sure it is a simple thing. maybe i am missing a step after i made my changes.

thanks  vinayan and thanks to rahul for your help so far.


2008-06-06 10:30 PM

It seems your mongrel didn't restart during the cap deploy. I could see the site content changed from  "whatever the world may be" to "whatever the world may be -- next" when I restarted mongrel from the app's current release. could you verify this ?

2008-06-06 10:59 PM

hi varun,

yes,"whatever the world may be --next" was my last change. this uploaded after i killed the process via ssh with the kill command.  mongrel_rails stop did not work.

i just made a new change and added the following lines:

whatever the world may be -- next -- one more change

1.) i did svn commit -m "xxx"

2.) cap deploy

did not show me any problems but the changes did not take effect.


2008-06-07 12:27 AM

The latest change is now visible online. I killed and restarted your mongrel instance again as shown below to achieve this.

/usr/local/bin/mongrel_rails start -e production -p <your_port> -d

As the problem is due to the cap deploy doesn't restart your mongrel instance, you need to verify your deploy.rb to check it's configured correctly. Also could you try changing the restart commandline to "/usr/local/bin/mongrel_rails start" instead of just "mongrel_rails start" in your Cap file and see if that makes any difference ?

2008-06-07 02:47 AM

hi varun,

here is my current deploy file:

set :application, "xxx"            # Can be whatever you want, I use the project name from my SVN repository
set :domain, "xxx"                # The URL for your app
set :user, "xxx"                  # Your HostingRails username
set :repository,  "svn+ssh://#{user}@#{domain}/home/#{user}/svn/#{application}/trunk"  # The repository location for svn+ssh access
# set :repository, "http://svn.#{domain}/svn/#{application}/trunk"      # The repository location for http access from the server
# set :local_repository, "http://svn.#{domain}:port/svn/#{application}/trunk"      # The repository location for http access from the local machine (this could be different from above if you use ssh port forwarding for svn access
# set :scm_username, "svn_username" #if http
# set :scm_password, "svn_password" #if http
set :use_sudo, false                 # HostingRails users don't have sudo access
set :deploy_to, "/home/#{user}/apps/#{application}"          # Where on the server your app will be deployed
set :deploy_via, :checkout                # For this tutorial, svn checkout will be the deployment method
set :chmod755, "app config db lib public vendor script script/* public/disp*"   # Some files that will need proper permissions
set :mongrel_port, "4140"                # Mongrel port that was assigned to you
# set :mongrel_nodes, "4"                # Number of Mongrel instances for those with multiple Mongrels

default_run_options[:pty] = true
# Cap won't work on windows without the above line, see
# http://groups.google.com/group/capistrano/browse_thread/thread/13b029f75b61c09d
# Its OK to leave it true for Linux/Mac

ssh_options[:keys] = %w(/Path/To/id_rsa)            # If you are using ssh_keys

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

2008-06-07 02:54 AM

where should i place it and should i remove current_path?  thanks for your help.

namespace :deploy do

task :start, :roles => :app do
run "rm -rf /home/#{user}/public_html;ln -s #{current_path}/public /home/#{user}/public_html"
   run "cd #{current_path} && mongrel_rails start -e production -p #{mongrel_port} -d"
 end

 task :restart, :roles => :app do
   run "cd #{current_path} && mongrel_rails restart"
   run "cd #{current_path} && chmod 755 #{chmod755}"
  end

end

2008-06-07 02:59 AM

Please try changing the line run "cd #{current_path} && mongrel_rails restart" as below.



task:restart, :roles => :app do
run "cd #{current_path} && /usr/local/bin/mongrel_rails stop && /usr/local/bin/mongrel_rails start -e production -p #{mongrel_port} -d"

end

2008-06-07 03:20 AM

hi varun,

thank you very much. this line fixed my problem. everything works fine now. you all did a great job. many thanks to rahul and vinayan for their thoughts.

2008-06-07 11:39 AM


Hello Guest! In order to post you must be an active client with us, please log in or sign up.