Ask A Question

Notifications

You’re not receiving notifications from this thread.

Deploy Ubuntu 14.04 Trusty Tahr Discussion

Chris Oliver asked in General
Grigory Reznichenko Grigory Reznichenko

The following commands should be slightly modified:
cap install STAGES=production
cap production deploy

I believe it should be the following:
bundle exec cap install STAGES=production
bundle exec cap production deploy

If you run 'cap' directly from the shell, it searches standard linux PATH and says that cap is not installed.
In other words, the binary is in gems folder ( ~/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/capistrano-3.1.0/bin/cap ) and should be called with bundle exec.

At least that's what I found out trying to replicate the installation.

Reply

I believe, if you run rbenv rehash after installing the capistrano gem, the executable should become available without having to run bundle exec. I could be wrong, but that's also the same way that gets the rails command available.

Reply

Thanks for this guide, it's my first time trying to deploy an app in rails. With a little help from google and stackoverflow I managed to set it all up and finally created a db, but when I visit my site in the browser I get an error page. It says to check my log file in var/log/nginx but when I try to go there it says:
-bash: cd: nginx: Permission denied

Any idea how I can see the error log? and also do I maybe need to do anything else not mentioned in this guide to get the site live?

Reply

You need to add a beginning slash to that command: cd /var/log/nginx/ or just view it by doing sudo less /var/log/nginx/error.log

That file will have your Nginx and passenger logs, but your Rails app will contain your Rails errors. Use less /home/deploy/MYAPP/current/log/production.log to view that.

If you send me your error, I can give you some more guidance on fixing it.

Reply
Chris Zempel Chris Zempel

Hey, small typo thing: if you select to install with 2.0.0-p481

the Capfile section still says:

# set :rbenv_ruby, '2.0.0-p451'
# set :rvm_ruby_version, '2.0.0-p451'

Reply

I'm having capistrano failing on this command of deployment [ -f home/deploy/codeblog/repo/HEAD ]

Reply

actually, it looks like that failure is fine.. however when it's trying to mirror my git repo it's giving me this error: fatal: destination path 'home/deploy/codeblog/repo' already exists and is not an empty directory. When i ssh into the server and look at the file structure that folder isn't there.

Reply

Thanks!

Reply

When I run the command (gem 'capistrano', '~> 3.1.0' It returns this error "unknown command capistrano" any ideas why this might be happening?

Reply

I think because that's not a command you run in your terminal but you need to add that to the file named Gemfile instead.

Reply
Jakub Kuchar Jakub Kuchar

This is tutorial is awesome, but i got server hacked withing 3 days on digital ocean. Be sure you close ssh with login/password http://lani78.com/2008/08/0...

Reply

Ouch! Did you have a short password?

Reply

Awesome tut, thank you very much.

I managed to deploy but I have an error "We're sorry, but something went wrong."

when i type sudo less /var/log/nginx/error.log i get the following.

[ 2014-06-17 04:55:18.8418 903/7f6b1e392700 agents/HelperAgent/RequestHandler.h:2262 ]: [Client 20] Cannot checkout session.

Error page:

Your Ruby version is 1.9.3, but your Gemfile specified 2.1.2 (Bundler::RubyVersionMismatch)
/home/deploy/.rvm/gems/ruby-2.1.2/gems/bundler-1.6.3/lib/bundler/definition.rb:390:in `validate_ruby!'
/home/deploy/.rvm/gems/ruby-2.1.2/gems/bundler-1.6.3/lib/bundler.rb:116:in `setup'
/home/deploy/.rvm/gems/ruby-2.1.2/gems/bundler-1.6.3/lib/bundler/setup.rb:17:in `<top (required)="">'

**omitted same lines***

rails -v

WARNING:root:could not open file '/etc/apt/sources.list.d/passenger.list'
The program 'rails' can be found in the following packages:
* ruby-railties-3.2
* ruby-railties-4.0

ruby -v
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]

Been trying the whole day. May you please help.

Reply

Double check that you set your nginx passenger_ruby to point to RVM or Rbenv properly and that you set the global ruby version to 2.1.2.

Reply
Daniel Baldwin Daniel Baldwin

Hi, thanks for the tut, it seems like a very concise and informative resource.

I seem to have hit an issue though, when running:

cap production deploy

I get an error:

ERROR linked file /home/deploy/my_actual_app_name/shared/config/database.yml does not exist on my.server.ip.address
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host my.server.ip.address: exit

The backtrace is pretty unhelpful but the tasks: TOP suggests the issue is originating (as expected) from config/deploy.rb

Tasks: TOP => deploy:check:linked_files

I am using Figaro for keeping my password out of git but that should have nothing to do with the file being sent to the server right?

would you happen to know what may be going wrong here?

Thanks in advance

Reply

Hey Daniel,

You'll need to manually create a database.yml file on your server. It's trying to link it but it hasn't been created yet. So you can ssh in and edit that file

nano /home/deploy/my_actual_app_name/shared/config/database.yml

and put in your database config for the server database that you just setup.

Reply

Where is the Gem File ? Please give me the exact location of the Gemfile.
"like /home/rails or /etc/nginx etc."
To add the lines :

gem 'capistrano', '~> 3.1.0'
gem 'capistrano-bundler', '~> 1.1.2'
gem 'capistrano-rails', '~> 1.1.1'

# Add this if you're using rbenv
# gem 'capistrano-rbenv', github: "capistrano/rbenv"

Reply

The Gemfile is in the top folder in your Rails application.

Reply

Hello Chris,

Here is the error I see when I try to run the command bundle --binstubs

deploy@sparktransfer:~/AsachTimepass$ bundle --binstubs

/home/deploy/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- bundler (LoadError)

from /home/deploy/.rbenv/versions/2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'

from /usr/bin/bundle:7:in `<main>'

I am using passenger_ruby /home/deploy/.rbenv/shims/ruby;

in the nginx.conf file, but it still doesnt work.

Can you help me ?

Reply
Bhuwan Arora Bhuwan Arora

I have managed to go through and run the complete tutorial, but after running touch APP-NAME/current/tmp/restart.txt I only see an nginx welcome page on the server IP. How can I debug the problem.

These are my config files
config/deploy.rb http://pastebin.com/1SXMDYvS
config/deploy/production.rb http://pastebin.com/ZYGejqJF
/etc/nginx/sites-enabled/default http://pastebin.com/0JNG54KH

I also tried with SERVER-IP instead of WEB-ADDRESS in server-name in /etc/nginx/sites-enabled/default

Where am I go wrong

Reply
Bhuwan Arora Bhuwan Arora

Ahh I found out I had created a backup for nginx.conf with the name nginx.conf.backup and that was creating all the problem..

Reply
Nick DelRossi Nick DelRossi

Thanks for the tutorial.

I want to add a helpful tip incase anyone else's Rails app has SSL enabled and is not working.

If you have enabled SSL/https on your Rails app, you will need to add another step to this process. I went through this tutorial and was getting ERR_CONNECTION_REFUSED in chrome when I tried to get to my site. I am new to this and it took me hours before I realized what the problem was.

If you follow the steps in this article it should fix the issue.
https://www.digitalocean.co...

Reply

Thanks for sharing Nick!

Reply
Jakub Kuchar Jakub Kuchar

Soon i would like to write a deployment guide for opensource project https://github.com/sharetri... from non-server guy perspective. And this guide playing a big role, i hope you wouldn't mind that i will reference it via link?

Reply

I don't mind at all Jakub. Let me know if there's anything I can help with.

Reply
Chris Sciolla Chris Sciolla

Hi Chris, I've followed this tutorial exactly and I'm getting the following error and can't figure out why. I also have no idea why example.com is there...

cap production deploy:check

[68f3b617] Running /usr/bin/env [ ! -d ~/.rbenv/versions/2.0.0-p481 ] on ***.***.***.***
[68f3b617] Command: [ ! -d ~/.rbenv/versions/2.0.0-p481 ]
[d8d5b994] Running /usr/bin/env [ ! -d ~/.rbenv/versions/2.0.0-p481 ] on example.com
[d8d5b994] Command: [ ! -d ~/.rbenv/versions/2.0.0-p481 ]
[68f3b617] Finished in 1.144 seconds with exit status 1 (failed).

cap aborted!

SSHKit::Runner::ExecuteError: Exception while executing on host example.com: No route to host - connect(2)

Errno::EHOSTUNREACH: No route to host - connect(2)

Tasks: TOP => rbenv:validate

Any ideas? Thanks for taking the time to write this up.

Reply

Check your config/deploy/production.rb file to make sure it doesn't have example.com in it. I would guess that's where it is coming from. Swap that with your domain or IP and you should be good.

Reply

Hey, thanks a lot for this tutorial. This is one of the most comprehensive one that I've come across thus far!

I am running into some trouble however. For some reason, the app that is actually up and running on my server is an older version (from like two months ago) of my application, but the "current" version of the app is my desired up-to-date one. (I see this when I review the code in that directory.)

I've specified that the master branch should be deployed, restarted the web and app servers, precompiled assets. But, I still have this older version running.
(I am having the same problem this person had http://stackoverflow.com/qu...

Does anyone have any ideas as to why this may be the case?

Reply

One thing is to check and make sure your config points to the right directory. It definitely has happened to me before, but it is almost always a case of either reading the wrong config or the config pointing to the wrong folder.

Reply
Felipe Campos Clarke Felipe Campos Clarke

this was very useful for me. Thank you very much for the article!

Reply

Hi, thanks for this tutorial, I tried to follow every step, I deployed the app with some fails
http://pastebin.com/zgkQXcqE

the vps still showing the nginx welcome message, I can't figure out why!

Reply

Your deploy was successful. The failures are supposed to happen.

Make sure you point nginx to /home/deploy/sample_app/current/ and restart it.

Reply
Rafal Szymanski Rafal Szymanski

Thanks for this, quite helpful. I'm having an issue with capistrano.

cap production deploy

results in

cap aborted!
Don't know how to build task 'deploy:updated'

with a bunch of other errors after it. I think I set everything up as shown here though – any ideas how to solve this?

Reply

I think this comes from your Capfile not being configured appropriately. Double check that step and make sure you've got all the correct require statements.

Reply

Hey Chris, thanks for providing this walkthrough, it's been mostly a breeze. One thing I'm stuck on however is generating the database. When I run RAILS_ENV=production bundle exec rake db:create in the /home/deploy/myapp/current directory, substituting "myapp" for the actual name of my app or course, the vps tells me ruby 2.1.1 is not installed, so I install it, then it wants me to bundle install, and so I do, and finally I'm stuck with "Gem::Ext::BuildError: ERROR: Failed to build gem native extension." type errors as the gems fail to compile. Where did I go wrong? I'd be happy to supply much more insight into this issue, up to and including access to the vps! thanks in advance.

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 86,946+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.