Problems Deploying to Linode with Capistrano - deployment

I`m looking for any guidance on deploying to Linode with Capistrano.
Everything seems fine until the point below:
[example.com :: out] Password: Password: ** [example.com :: out] ** [example.com :: out] HEAD is now at dc70d86 Fixed bugs from Webmaster Tools.
command finished in 9912ms
copying the cached version to /home/deploy/example.com/releases/20121024201633 * executing "cp
-RPp /home/deploy/example.com/shared/cached-copy /home/deploy/example.com/releases/20121024201633 && (echo dc70d867e1b01427a776ef23b59ddd375d39a34b > /home/deploy/example.com/releases/20121024201633/REVISION)"
servers: ["example.com"]
[example.com] executing command ** [out :: example.com] cp: cannot create directory `/home/deploy/example.com/releases/20121024201633' ** [out :: example.com] : No such file or directory
command finished in 661ms
*** [deploy:update_code] rolling back * executing "rm -rf /home/deploy/example.com/releases/20121024201633; true"
servers: ["example.com"]
[example.com] executing command
command finished in 623ms failed: "sh -c 'cp -RPp /home/deploy/example.com/shared/cached-copy /home/deploy/example.com/releases/20121024201633 && (echo dc70d867e1b01427a776ef23b59ddd375d39a34b > /home/deploy/example.com/releases/20121024201633/REVISION)'" on example.com
Any clues to why the directory doesn`t get created or what can I do to fix it?
All answers are appreciated.

It seems that some of the directories in this /home/deploy/example.com/releases/ path do not exist.
Try to run cap deploy:setup and to make sure also mkdir -p /home/deploy/example.com/releases on the servers shell.

Related

Can’t cd to /var/www/discourse/current

I'm following instruction deploying-discourse-with-capistrano
When I'm doing cap deploy:setup I get:
executing "cd /var/www/discourse/current && bundle install"
...
** [out :: ...] sh: 1: cd: can't cd to /var/www/discourse/current
The command cap deploy:check says that everything is ok
What might be a problem here?
Try this.
cd /var/www/discourse
./discourse-setup
Reference article: https://www.digitalocean.com/community/tutorials/how-to-install-discourse-on-ubuntu-16-04

Capistrano Rails Asset Precompile Error

I have a Capistrano script which is deploying my app to an Amazon EC2 machine. It is failing when compiling assets:
* executing "cd -- /home/ec2-user/uc_social_server/releases/20130731161645 && RAILS_ENV=production RAILS_GROUPS=assets rake assets:precompile"
servers: ["ec2-23-22-188-11.compute-1.amazonaws.com"]
[ec2-23-22-188-11.compute-1.amazonaws.com] executing command
** [out :: ec2-23-22-188-11.compute-1.amazonaws.com] Could not find thread_safe-0.1.0 in any of the sources
** [out :: ec2-23-22-188-11.compute-1.amazonaws.com]
** [out :: ec2-23-22-188-11.compute-1.amazonaws.com] Run `bundle install` to install missing gems.
** [out :: ec2-23-22-188-11.compute-1.amazonaws.com]
command finished in 591ms
*** [deploy:update_code] rolling back
* executing "rm -rf /home/ec2-user/uc_social_server/releases/20130731161645; true"
servers: ["ec2-23-22-188-11.compute-1.amazonaws.com"]
[ec2-23-22-188-11.compute-1.amazonaws.com] executing command
command finished in 201ms
failed: "sh -c 'cd -- /home/ec2-user/uc_social_server/releases/20130731161645 && RAILS_ENV=production RAILS_GROUPS=assets rake assets:precompile'" on ec2-23-22-188-11.compute-1.amazonaws.com
Adding following to deploy.rb
require "bundler/capistrano"
require "rvm/capistrano"
before "deploy:assets:precompile", "bundle:install"
and following to Capfile
load 'deploy/assets'
and following to Gemfile
gem 'rvm-capistrano'
resolved the issue for me. If you are not using rvm, maybe you will not need to require rvm/capistrano or the rvm-capistrano gem.
Add this line to your Capfile
require 'capistrano/bundler'

Capistrano deploy:setup works but not deploy:check

Testing capistrano with a simple recipe.
$ cap deploy:setup
* executing `deploy:setup'
* executing "sudo -p 'sudo password: ' mkdir -p /u/apps/ [..]
[..]
deploy:setup works as exprected.
However
$ cap deploy:check
* executing `deploy:check'
* executing "test -d /u/apps/[..]
[..]
When running deploy:check I get the following error:
The following dependencies failed. Please check them and try again:
--> You do not have permissions to write to `/u/apps/
[..]
--> `/u/apps/app/shared is not writable [..]
It seems that capistrano is not using sudo while in deploy:check mode.
I don't get it!
While in deploy:setup the whole directory structure was created by capistrano without any issue?
Why capistrano doesn't use sudo as in deploy:check?
I also ran into this issue and it turned out capistrano was creating all of the folders under the <user> group except for the shared folder. SSH onto your server and do a long listing ls -l. If you see - root - root - for the shared folder, you'll just need to update the permissions on the folder:
sudo chown <user> shared
sudo chgrp <user> shared
I ran into the same issue: the trick is to explicitly configure Capistrano not to use sudo.
You can turn that off in your deploy.rb file with:
set :use_sudo, false
If you need to use sudo, how about using the sudo DSL Action Invocation in your commands:
run "#{sudo} apachectl restart"

Capistrano Deployment: a Task before `deploy:finalize_update` Is not Executed

I'm using Capistrano v2.13.4 for deployment.
A Capistrano task (deploy:special_treats) before deploy:finalize_update is not executed.
The task deploy:special_treats does some preparation (setup the internet access) for bundle:install, otherwise, bundle:install will not be able to reach the Internet ([out :: servername] Could not reach https://rubygems.org/
In config/deploy.rb
before 'deploy:finalize_update', 'deploy:special_treats'
and
namespace :deploy do
task :special_treats do
run "echo 'something special treats: setup the Internet access'"
end
end
The result for cap deploy:update
$ cap deploy:update
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
executing locally: "svn info https://svnlinks --username username --password password --no-auth-cache -rHEAD"
command finished in 10336ms
* getting (via export) revision 33268 to /tmp/20120927171608
executing locally: svn export -q --username username --password password --no-auth-cache -r33268 https://svnlinks /tmp/20120927171608
command finished in 79314ms
* processing exclusions...
* Compressing /tmp/20120927171608 to /tmp/20120927171608.tar.gz
executing locally: tar czf 20120927171608.tar.gz 20120927171608
command finished in 1401ms
servers: ["servername"]
** sftp upload /tmp/20120927171608.tar.gz -> /tmp/20120927171608.tar.gz
[servername] /tmp/20120927171608.tar.gz
[servername] done
* sftp upload complete
* executing "cd /usr/website/rr/releases && tar xzf /tmp/20120927171608.tar.gz && rm /tmp/20120927171608.tar.gz"
servers: ["servername"]
[servername] executing command
command finished in 774ms
* executing `deploy:finalize_update'
triggering before callbacks for `deploy:finalize_update'
* executing `bundle:install'
* executing "cd /usr/website/rr/releases/20120927171608 && bundle install --gemfile /usr/website/rr/releases/20120927171608/Gemfile --path /usr/website/rr/shared/bundle --deployment --quiet --without development
test"
servers: ["servername"]
[servername] executing command
** [out :: servername] Could not reach https://rubygems.org/
command finished in 1403ms
*** [deploy:update_code] rolling back
* executing "rm -rf /usr/website/rr/releases/20120927171608; true"
servers: ["servername"]
[servername] executing command
command finished in 344ms
failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.3-p194' -c 'cd /usr/website/rr/releases/20120927171608 && bundle install --gemfile /usr/website/rr/releases/20120927171608/Gemfile --path
/usr/website/rr/shared/bundle --deployment --quiet --without development test'" on servername
I just had the same issue but in the after deploy:finalize_update trigger. The difference is that my script works in another machine for a long time.
I don't have capistrano locked as a gem in the Gemfile, so I tried reverting to the same version of the working machine which is 2.6.0 but that did not fix it.
After some research and several trials, I have found some issues at the github project like this that leads to that but looks like folks can't fully reproduce it.
I have then headed to the docs and browsing I found that Capistrano behaviors have been affected by recent changes on the 0.9.x versions of rake that have to do with namespace conflicts as you can see in this brief and tiny note that can be found at the deploy:create_symlink section of Capistrano Tasks wiki page
I did not have time to fix the script to work with latest versions of both rake and capistrano but I was able to have it back working on a different machine by reverting rake to version 0.8.7.
I hope this can get you going and provide some clues towards the solution.

Rails 3 - Script doesn't run after cap:deploy

I want to run few commands when i start application on server.
So, i wrote such script in config/deploy.rb:
desc "Start sphinx"
task :start_sphinx, :roles => :app do
run "cd #{current_path} && bundle install --without development test && bundle install --deployment && chmod 777 -R #{current_path}/tmp/ && rake thinking_sphinx:configure && rake thinking_sphinx:start"
end
But when i print
$ cap deploy
It doesn't work. So, please, tell me what is wrong!
Here is log from terminal:
$ cap deploy
* executing `deploy'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
executing locally: "git ls-remote git://github.com/Loremaster/sample_app.git master"
command finished in 367ms
* executing "if [ -d /vol/www/apps/ror_tutorial/shared/cached-copy ]; then cd /vol/www/apps/ror_tutorial/shared/cached-copy && git fetch -q origin && git fetch --tags -q origin && git reset -q --hard b5073e9b9aefd98873489bb6e97249593ea1a978 && git clean -q -d -x -f; else git clone -q git://github.com/Loremaster/sample_app.git /vol/www/apps/ror_tutorial/shared/cached-copy && cd /vol/www/apps/ror_tutorial/shared/cached-copy && git checkout -q -b deploy b5073e9b9aefd98873489bb6e97249593ea1a978; fi"
servers: ["188.127.224.136"]
Password:
[188.127.224.136] executing command
command finished in 3070ms
copying the cached version to /vol/www/apps/ror_tutorial/releases/20120125165835
* executing "cp -RPp /vol/www/apps/ror_tutorial/shared/cached-copy /vol/www/apps/ror_tutorial/releases/20120125165835 && (echo b5073e9b9aefd98873489bb6e97249593ea1a978 > /vol/www/apps/ror_tutorial/releases/20120125165835/REVISION)"
servers: ["188.127.224.136"]
[188.127.224.136] executing command
command finished in 49970ms
* executing `deploy:finalize_update'
* executing "chmod -R g+w /vol/www/apps/ror_tutorial/releases/20120125165835"
servers: ["188.127.224.136"]
[188.127.224.136] executing command
command finished in 1023ms
* executing "rm -rf /vol/www/apps/ror_tutorial/releases/20120125165835/log /vol/www/apps/ror_tutorial/releases/20120125165835/public/system /vol/www/apps/ror_tutorial/releases/20120125165835/tmp/pids &&\\\n mkdir -p /vol/www/apps/ror_tutorial/releases/20120125165835/public &&\\\n mkdir -p /vol/www/apps/ror_tutorial/releases/20120125165835/tmp &&\\\n ln -s /vol/www/apps/ror_tutorial/shared/log /vol/www/apps/ror_tutorial/releases/20120125165835/log &&\\\n ln -s /vol/www/apps/ror_tutorial/shared/system /vol/www/apps/ror_tutorial/releases/20120125165835/public/system &&\\\n ln -s /vol/www/apps/ror_tutorial/shared/pids /vol/www/apps/ror_tutorial/releases/20120125165835/tmp/pids"
servers: ["188.127.224.136"]
[188.127.224.136] executing command
command finished in 150ms
* executing "find /vol/www/apps/ror_tutorial/releases/20120125165835/public/images /vol/www/apps/ror_tutorial/releases/20120125165835/public/stylesheets /vol/www/apps/ror_tutorial/releases/20120125165835/public/javascripts -exec touch -t 201201251659.26 {} ';'; true"
servers: ["188.127.224.136"]
[188.127.224.136] executing command
** [out :: 188.127.224.136] find: `/vol/www/apps/ror_tutorial/releases/20120125165835/public/images': No such file or directory
** [out :: 188.127.224.136] find: `/vol/www/apps/ror_tutorial/releases/20120125165835/public/stylesheets': No such file or directory
** [out :: 188.127.224.136] find: `/vol/www/apps/ror_tutorial/releases/20120125165835/public/javascripts': No such file or directory
command finished in 566ms
* executing `deploy:symlink'
* executing "rm -f /vol/www/apps/ror_tutorial/current && ln -s /vol/www/apps/ror_tutorial/releases/20120125165835 /vol/www/apps/ror_tutorial/current"
servers: ["188.127.224.136"]
[188.127.224.136] executing command
command finished in 56ms
** transaction: commit
* executing `deploy:restart'
* executing "sudo -p 'sudo password: ' touch /vol/www/apps/ror_tutorial/current/tmp/restart.txt"
servers: ["188.127.224.136"]
[188.127.224.136] executing command
command finished in 163ms
It looks like you are missing the callback. For example, if you wanted to run your script after the code has been updated, you can use an after callback like
after "deploy:update_code", "start_sphinx"
For more info on callbacks, check out the callbacks rdoc