Ask A Question

Notifications

You’re not receiving notifications from this thread.

Deploy Ubuntu 14.04 Trusty Tahr Discussion

Chris Oliver asked in General
a_disbeliever a_disbeliever

Hi, I am proceeding along with the tutorial, after reading it thoroughly. I find it confusing that the user name is 'deploy' when that term overlaps with Capistrano-installed file and folder names. I used 'deployer' (user) to discriminate from 'deploy' (action). I know this is just a nit, but it cost me some time.

I am deploying to a headless server on my LAN, so I skimmed through the Droplet stuff.

Reply

When i start cap production deploy, i have errors:

cap aborted!

SSHKit::Runner::ExecuteError: Exception while executing on host 104.131.87.26: ln exit status: 1

ln stdout: Nothing written

ln stderr: Nothing written

Reply

After I installed the postgres, I ran the script below
```
sudo su - postgres
createuser --pwprompt

```
However, it showed, "createuser: creation of new role failed: ERROR: role "postgres" already exists"

What's the problem?

Reply

same issue here.

Reply

How about trying

sudo su - postgres
createuser --interactive

Reply
Paul Ericson Paul Ericson

The problem is that installing the postresql apt package creates a role called 'postgres'.

Return to being deploy with:
$ exit

Then run psql as the postgres role with:
$ sudo -u postgres psql

Then set the password:
postgres=# \password postgres

Then to quit:
postgres=# \q

Reply

try "createuser --pwprompt a_random_user_name" instead

Reply

Hey,

Very nice tutorial, it worked for me the first time (with hardcoding the secret and database password). One thing I missed was environment variables, as they are also an important part of deployment. I tried to deploy another project using environment variables, but I couldn't get it to work.

I spend hours looking around on how to get environment variables to work. I used rbenv on my server which needs the 'rbenv-env' plugin. I didn't realize after a few hours that I needed this plugin to get my environment variables to work.

It would be nice to see it added to this tutorial. I am sure others have had problems trying to figure out what the right/easiest way is to achieve this.

Reply

Definitely a pain in the butt! I think my personal suggestion for most people is to use Rails' secrets.yml and symlink that on deploy just like database.yml. It works just like environment variables more or less and is builtin to Rails.

Reply

I ran `ssh-copy-id deploy@IPADDRESS` and I'm able to SSH into the VPS without having to put in a password, however, when I run `$ cap production deploy` I get this error:

[ecc89106] Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
DEBUG[ecc89106] Permission denied (publickey).
DEBUG[ecc89106] fatal: Could not read from remote repository.
DEBUG[ecc89106]
DEBUG[ecc89106] Please make sure you have the correct access rights
DEBUG[ecc89106] and the repository exists.
DEBUG[ecc89106] Finished in 0.742 seconds with exit status 128 (failed).
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host xxx.xxx.xxx.xx: exit

I only have `authorized_keys` and `known_hosts` within /home/deploy/.ssh/. Do I need to manually copy over my public/private keys as well?

Reply

I changed `set :repo_url, 'git@github.com:username/testapp.git'` to `set :repo_url, 'https://github.com/username...` and that fixed the error.

Reply

Thanks for the really clear tutorial. I have however had difficulty getting all of the way through to a working deployment. A couple of points that threw me or might need further clarity are as follows (working with rbenv):

1. The createuser --pwprompt should I believe be createuser [user name] --pwprompt

2. When running the cap commands I need to prefix with bundle exec.

3. The Capistrano section is all run locally, not on the server.

This gets me through to the stage where I deploy, however on running the

bundle exec cap production deploy

I get an error as follows:

rbenv: bundle: command not found

cap aborted!

SSHKit::Runner::ExecuteError: Exception while executing on host 109.74.205.192: bundle exit status: 127

bundle stdout: Nothing written

bundle stderr: rbenv: bundle: command not found

/Users/richardbox/Dropbox/Rails/deploy_app/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/command.rb:97:in `exit_status='

/Users/richardbox/Dropbox/Rails/deploy_app/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:148:in `block (5 levels) in _execute'

/Users/richardbox/Dropbox/Rails/deploy_app/vendor/bundle/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `call'

/Users/richardbox/Dropbox/Rails/deploy_app/vendor/bundle/gems/net-ssh-2.9.1/lib/net/ssh/connection/channel.rb:551:in `do_request'

I do seem to get past this stage by manually performing sudo apt-get install bundler. However that doesn't seem the right approach to me and when successfully deployed after that I get a passenger error as follows:

cannot load such file -- bundler/setup (LoadError)
/home/deploy/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/deploy/.rbenv/versions/2.1.3/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:263:in `block in run_load_path_setup_code'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:366:in `running_bundler'
/usr/lib/ruby/vendor_ruby/phusion_passenger/loader_shared_helpers.rb:261:in `run_load_path_setup_code'
/usr/share/passenger/helper-scripts/rack-preloader.rb:100:in `preload_app'
/usr/share/passenger/helper-scripts/rack-preloader.rb:158:in `<module:app>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:29:in `<module:phusionpassenger>'
/usr/share/passenger/helper-scripts/rack-preloader.rb:28:in `<main>'

I'd appreciate any help in overcoming this issue.

Reply

You want to run gem install bundler to get the appropriate version on your server. apt-get for any ruby related things is bad with this set up because you'll get conflicting things going on (or at least confusing things).

Reply
Gabriel Czirak Gabriel Czirak

Hi Chris!

I followed your tutorial but after deploy and putting the IP of the server to the browser I get a message "We're sorry, but something went wrong." I did asset precompile and db:migrate either. I also tried to run the app with webrick on port 3000 and it went all fine. My nginx log file is empty. What do you suggest?

Thank you.

Reply

That message comes from the Rails 500 error, so you'll want to check your Rails logs to see what's going wrong there.

Reply

Hi, I'm getting this error when I run cap production deploy

DEBUG[9cef5778] Could not locate Gemfile
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host my.server.ip.here: bundle exit status: 10
bundle stdout: Nothing written
bundle stderr: Nothing written

any advice? Thanks!

Reply
Vibhoo Mishra Vibhoo Mishra

Very Nice tutorial

but I could not get how to start rails app as no where rails is installed can please get back to me ASAP

Reply

You don't have to run it manually like you do in development. When you run Capistrano, it runs bundler which installs the Rails gem. Then, Nginx is always running and it fires up Passenger which starts your Rails app for you. So basically Nginx is the thing that runs your Rails app in production and all you need to do is make sure Nginx is running.

Reply
Magzhan Shokparbayev Magzhan Shokparbayev

Thanks for your tutorial! but I have one problem with ssh key. When I trying to deploy I had error with ssh key. The problem is that if I authenticate to server via root@IpAddress it goes via ssh keys but when I try with deploy user it prompts me the password. Should I write deploy's password somewhere like production.rb or do you have any solution? I am very new at deploying projects so any help may help me. Thanks

Reply

The goal is not to use passwords for ssh so it is more secure. You'll just need to copy your ssh public key to the deploy user with ssh-copy-id. Double check that you can ssh into deploy without a password so Capistrano can too.

Reply

Step - Installing Ruby using rvm, there is one more step which needs to be added before rvm could be installed...

gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3

Reply
Vibhoo Mishra Vibhoo Mishra

My migration is not running automatically I have added

require 'capistrano/rails/migrations' -> in Capfile

&

before :starting , 'deploy:migrate' -> config/deploy.rb file still my migration is not running

please Help anyone ASAP

Reply

Awesome setup

Reply

Is there a tutorial that I'm missing for this? I guess I will try with one of my rails apps but if someone could provide me a link to the tutorial on how to build this app or explain this part about the Gemfile to me that would be great( I know what a Gemfile is, just not in context to the tutorial)

Reply

I was able to get one of my Rails up and running on Digital Ocean using this and a tut I found on DO community site. Thanks Chris for all your hard work that went into this site

Reply

is it the same method on EC2

Reply

Yep, pretty much the same thing aside from they connect you differently with .pem keys instead of a password to login initially. May also have to open up the ports to the outside world so you can server HTTP requests.

Reply

is it possible to deploy by using git to push the rails up to the server and then use the same nginx with passenger configurations

Reply

Yep. You can set it up to do a git push like Heroku does, but I've never set a server up that way before so you'll probably need to do some digging to figure out how to do it. Check out this: https://www.digitalocean.co...

Reply
Magzhan Shokparbayev Magzhan Shokparbayev

Hi Chris! Can you help me ?. I get "We're sorry, but something went wrong." then I run "sudo nginx -t" it says syntax is ok and nginx.conf test is successful. What should I do?

Reply

Check your /home/deploy/APP/current/logs/production.log file for the errors. That's the error page from Rails so Nginx is set up properly but Rails isn't just yet.

Reply
Paul Ericson Paul Ericson

The Capistrano section makes a huge assumption that will trip up a newbie (like me).

Up to that point, bundler has not been installed, so there is no Gemfile (beyond the template) and the subsequent 'bundle --binsubs' command will fail.

Don't follow the advice in the shell and install bundler using apt-get, it will reset your Ruby version back to 1.9. Instead, use gem like this:

$ gem install bundler
$ export GEM_HOME=$(ruby -e 'print Gem.user_dir')
$ bundle init

Outputs; "Writing new Gemfile to /home/deploy/Gemfile"

Now you can edit Gemfile and run bundle commands.

WARNING: If you are using rbenv, you have to uncomment this line in your Gemfile:
# gem 'capistrano-rbenv', github: "capistrano/rbenv"

Reply
Paul Ericson Paul Ericson

Stuck on, "cap install STAGES=production".
Getting, "WARNING:root:could not open file '/etc/apt/sources.list.d/passenger.list'

The program 'cap' is currently not installed. You can install it by typing:
sudo apt-get install capistrano"

This seems to work:

$ bundle exec cap install STAGES=production

Guess rbenv users all have the rbenv-binstubs plugin installed?

Reply

You can do "rbenv rehash" to make the cap executable available like a regular command.

Reply

How about:

```
sudo chmod go=r /etc/apt/sources.list.d/passenger.list

```

Reply

Many thx,It is very very helpful :)

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.