I'm getting an "upload via scp failed" error when I run cap deploy, with the following output:
* executing `deploy:assets:update_asset_mtimes'
...
** Updating mtimes for ~8 assets...
** scp upload #<StringIO:0x007fca13a94f40> -> /apps/my_app/TOUCH_ASSETS
*** upload via scp failed on <ip>:
*** (
*** )
*** [deploy:update_code] rolling back
When I ran cap deploy:cold, there were no errors.
What is the source of this error and how do I go about debugging it?
In your Capistrano deployments file, you are passing a StringIO to the scp command instead of a file name. If the StringIO object in question contains the name of the file(s) you wish to copy, then you must convert the StringIO to a string:
stringIOobject.read()
It may be that your asset manifest file isn't correctly formatted, such as having a typo. Look in the following manifest files in your project and double check everything.
app/assets/javascripts/application.js
app/assets/stylesheets/application.css
If you have any other custom manifest files be sure to check them out too. Look at the examples here to make sure the formatting is correct.
Try compile your assets locally and then upload via rsync, like this
namespace :deploy do
namespace :assets do
desc "Precompile assets on local machine and upload them to the server."
task :precompile, roles: :web, except: {no_release: true} do
run_locally "bundle exec rake assets:precompile"
find_servers_for_task(current_task).each do |server|
run_locally "rsync -vr --exclude='.DS_Store' public/assets #{user}##{server.host}:#{shared_path}/"
end
end
end
end
Related
The Capistrano production.rb file executes 3 tasks
composer install --no-dev
mkdir storage
upload! ".env.production", ".env"
The first 2 are executed, but the upload fails: "No such file or directory".
I was able to scp the file successfully from the command line.
How to copy a file to the current release directory?
$ cap --version
Capistrano Version: 3.11.0 (Rake Version: 12.3.1)
$ cap production deploy
...
01 mkdir -p ~/public_html/app/releases/20181122210112
...
composer install --no-dev
...
mkdir storage
...
SSHKit::Runner::ExecuteError:
Exception while executing as me#site.com:
scp: ~/public_html/app/releases/20181122210112/.env:
No such file or directory
DEBUG Uploading .env.production 0.0%
...
$
scp the file successfully from the command line:
$ scp .env.production me#site.com:~/public_html/app/releases/20181122210112/.env
production.rb
# use absolute path
set :deploy_to, "/home/user/public_html/app"
namespace :deploy do
desc "Install app dependencies with composer"
after :updated, :build do
on roles(:web) do
within release_path do
execute :composer, "install --no-dev"
execute :mkdir, "storage"
end
end
end
end
namespace :deploy do
desc "Copy Env"
after :finished, :copy do
on roles(:all) do
upload! ".env.production", "#{release_path}/.env"
end
end
end
if your need is to copy your local application.yml to the server, and you are already using capistrano, you can use the capistrano figaro gem, it creates a task to update this file on server. in theory, you could run the task automatically and make this file to be updated. is an old gem, but works like a charm and do the work.
I am deploying a Rails application using AWS OpsWorks. To precompile the assets, I use the following Chef recipe:
node[:deploy].each do |application, deploy|
deploy_to = node[:deploy][application][:deploy_to]
rails_env = node[:deploy][application][:rails_env]
directory "#{deploy_to}/shared/assets"
link "#{deploy_to}/current/public/assets" do
to "#{deploy_to}/shared/assets"
end
execute "rake assets:precompile" do
cwd "#{deploy_to}/current"
command "bundle exec rake assets:precompile"
environment "RAILS_ENV" => rails_env
end
end
It precompiles correctly, but in following deployments it goes through the whole precompile process again, even though no asset was modified and the assets folder is shared. I also tried a Chef hook, as suggested here, with the same result. How could you make it run only when needed?
You can add not_if or only_if clause to the statement:
Something like this:
execute "rake assets:precompile" do
cwd "#{deploy_to}/current"
command "bundle exec rake assets:precompile"
environment "RAILS_ENV" => rails_env
not_if { File.exists?("<path to expected precompiled asset>") }
end
If you want it to run every time there is a change in a certain directory, you can use chef notifications.
I can get the index.html and a test page to come up in the browser from the public folder, but the exact/path in the controller is not coming up. The browser continues to search for the page until I stop it. It works in my test environment and it works in Heroku, but doesn't not work on my amazon ec2 server. I am using Ubuntu 11.10. Why would this be? Thanks in advance.
Update: It looks like I am getting a 500 Internal Server error and the controller is not seen.
It turns out I needed to prcompile the assets by doing one of the folling
Adding this to my deploy.rb file
after "deploy:restart", "deploy:precompile"
namespace :deploy do
desc "Compile assets"
task :precompile, :roles => :app do
run "cd #{release_path} && rake RAILS_ENV=#{rails_env} assets:precompile"
end
end
Running this in the current directory
RAILS_ENV=production rake assets:precompile
Or adding this to the capfile
load 'deploy/assets'
I cannot start delayed job process using a capistrano recipe. Here's the error I am getting.
/usr/local/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.1/lib/delayed/command.rb:62:in `mkdir': File exists - /my_app/server/releases/20101120001612/tmp/pids (Errno::EEXIST)
Here's the capistrano code (NOTE-: I have tried both start/restart commands)
after "deploy:restart", "delayed_job:start"
task :start, :roles => :app do
run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job -n 2 start"
end
More detail errors from deployment logs -
executing command
[err :: my_server] /usr/local/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.1/lib/delayed/command.rb:62:in `mkdir': File exists - /my_app/server/releases/20101120001612/tmp/pids (Errno::EEXIST)
[err :: my_server] from /usr/local/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.1/lib/delayed/command.rb:62:in `daemonize'
[err :: my_server] from script/delayed_job:5:in `<main>'
command finished
failed: "sh -c 'cd /my_app/server/current; RAILS_ENV=production script/delayed_job -n 3 restart'" on myserevr
This is a Rails 3 app (v3.0.3)
Seeing the same problem.
It turns out I was missing the ~/apps/application_name/shared/pids directory.
Finally creating it made this problem go away.
No need to set up custom dj_pids directory.
I also got this error and found a couple of issues:
Ensure you have a shared/pids folder.
Ensure you have the correct hooks setup
Your deploy.rb script should contain:
require "delayed/recipes"
after "deploy:stop", "delayed_job:stop"
after "deploy:start", "delayed_job:start"
after "deploy:restart", "delayed_job:restart"
I'd copied the hooks from an old post and they appear to be incorrect now. These are from the actual delayed_job recipe file comments.
I believe cap deploy:setup should create the pids folder but I set things up a different way and it was not created. app/current/tmp/pids links to app/shared/pids and this was causing the false directory exists error.
This is how I fixed the issue, I passed an explicit pids dir parameter using "--pid-dir". Not sure if this is perfect, but it worked.
task :restart, :roles => :app do
run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job -n #{dj_proc_count} --pid-dir=#{app_root}/shared/dj_pids restart"
end
Add the creation of this directory before
after "deploy:restart", "delayed_job:start"
task :start, :roles => :app do
run "mkdir #{current_path}/tmp/pids"
run "cd #{current_path}; RAILS_ENV=#{rails_env} script/delayed_job -n 2 start"
end
I had the same issue. Turned out that there was an existing
application_name/shared/pids/delayed_job.main.pid
file, which had incorrect owner permissions, which was causing the deployment to fail. Fixing this file's permissions solved the issue for me.
Since the creation of the directories is cheap and fast, use the following callback:
before 'deploy', 'deploy:setup'
This will ensure that structure is always there before each deploy.
I am trying to deploy my rails application for the first time.
Server is running Ubuntu 10.4 server (64bit)
Local machine is running Windows XP.
Repository is at github
I have successfully run
cap deploy:setup
but when I run
cap deploy:cold
I get the following error:
D:\Rails\rails_apps\fx>cap deploy:cold
You are running Ruby 1.8.6, which has a bug in its threading implementation.
You are liable to encounter deadlocks running Capistrano, unless you install
the fastthread library, which is available as a gem:
gem install fastthread
* executing `deploy:cold'
* executing `deploy:update'
** transaction: start
* executing `deploy:update_code'
updating the cached checkout on all servers
*** [deploy:update_code] rolling back
* executing "rm -rf /var/www/fx/releases/20100818215651; true"
servers: ["pragmaticriskmanagement.gotdns.com"]
[pragmaticriskmanagement.gotdns.com] executing command
command finished
D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy.rb:37:in ``': No such file or directory - git rev-parse master (Errno::ENOENT)
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy.rb:37:in `load'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy.rb:87:in `with_env'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy.rb:37:in `load'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistran/recipes/deploy/scm/git.rb:154:in `query_revision'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy/scm/base.rb:35:in `send'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy/scm/base.rb:35:in `method_missing'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy/scm/base.rb:63:in `local'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/recipes/deploy/scm/base.rb:35:in `method_missing'
... 39 levels...
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/lib/capistrano/cli/execute.rb:14:in `execute'
from D:/Rails/ruby/lib/ruby/gems/1.8/gems/capistrano-2.1.0/bin/cap:4
from D:/Rails/ruby/bin/cap:19:in `load'
from D:/Rails/ruby/bin/cap:19
Here is my 'deploy.rb' file
set :application, "fx" #"pragmaticriskmanagement.gotdns.com"
set :repository, "git#github.com:jmedding/Fx.git"
set :deploy_to, "/var/www/#{application}"
set :git_enable_submodules, 1 # Make sure git submodules are populated
set :location, "pragmaticriskmanagement.gotdns.com"
set :user, "xxxxx"
set :use_sudo, false
set :scm, :git
role :app, location #"your app-server here"
role :web, location #"your web-server here"
role :db, location, :primary => true #"your db-server here", :primary => true
namespace :deploy do
desc "Restart Application"
task :restart, :roles => :app do
run "touch #{current_path}/tmp/restart.txt"
end
desc "Make symlink for database.yml"
task :symlink_dbyaml do
run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
end
desc "Create empty database.yml in shared path"
task :create_dbyaml do
run "mkdir -p #{shared_path}/config"
put '', "#{shared_path}/config/database.yml"
end
end
after 'deploy:setup', 'deploy:create_dbyaml'
after 'deploy:update_code', 'deploy:symlink_dbyaml'
after "deploy", "deploy:cleanup"
and now I'm stuck...
Any help would be greatly appreciated.
Thanks,
Jon
Sorry to resurrect such an old thread, but I solved this by adding the default location of my git binaries (C:\Program Files (x86)\Git\bin) to my PATH variable.
Ok, I have made some progress.
It seems that the error indicates that the git ls-remote command could not be found on the local system (win xp). As a test, I opened the GIT Bash shell and tried the command - it worked. Next, I tried
cap deploy
from the GIT Bash shell. Command not found. OK, I added my rails path
D:\Rails\ruby\bin
to the windows 'path' variable. Now, try
cap deploy
from the bash shell. This seems to have solved this problem, which now leads to my next problem
** [xxxxxxxx.com :: out] Cloning into /var/www/fx/shared/cached-copy...
** [xxxxxxxx.com :: err] Permission denied (publickey).
** [xxxxxxxx.com :: err] fatal: The remote end hung up unexpectedly
I can successfully run cap deploy from my linux box with the same public key. Also, I can push to my Github repo from this laptop with this key. Of course, the key in question should be on the server, but if it works when I run 'cap' from the linux box, why wouldn't it run from here?