Ruby issue when doing cap deploy production
Hi, I'm following the Deploy Rails guide.
However, when I run
cap production deploy
I'm getting this error message:
$cap production deploy
DEBUG[be6b6bd6] Running /usr/bin/env [ -d ~/.rbenv/versions/2.0.0-p451 ] on 95.85.5.6
DEBUG[be6b6bd6] Command: [ -d ~/.rbenv/versions/2.0.0-p451 ]
DEBUG[be6b6bd6] Finished in 1.060 seconds with exit status 1 (failed).
ERRORrbenv: 2.0.0-p451 is not installed or not found in ~/.rbenv/versions/2.0.0-p451
cap aborted!
Not sure what's going on. I guess it has something to do with incompatible versions of Ruby, but is it the Ruby version on my local machine or on the VPS?
thanks for your help,
Anthony
That error says that on the server the ruby version you have doesn't match the one you set in your Capfile
. You'll want to make sure the version in this file matches the version of Ruby on the server.
I see,
I changed the version in my Capfile to :
set :rbenv_ruby, '2.1.2-p95'
but now, when I run
cap production deploy
I get the error:
$cap production deploy
DEBUG[d2d51431] Running /usr/bin/env [ -d ~/.rbenv/versions/2.1.2-p95 ] on 95.85.5.6
DEBUG[d2d51431] Command: [ -d ~/.rbenv/versions/2.1.2-p95 ]
DEBUG[d2d51431] Finished in 0.980 seconds with exit status 1 (failed).
ERRORrbenv: 2.1.2-p95 is not installed or not found in ~/.rbenv/versions/2.1.2-p95
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 95.85.5.6: exit
/Users/acandael/Sites/posplus/vendor/bundle/bundler/gems/rbenv-2332dba20ec1/lib/capistrano/tasks/rbenv.rake:12:in `exit'
/Users/acandael/Sites/posplus/vendor/bundle/bundler/gems/rbenv-2332dba20ec1/lib/capistrano/tasks/rbenv.rake:12:in `block (3 levels) in <top (required)>'
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in `run'
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
SystemExit: exit
/Users/acandael/Sites/posplus/vendor/bundle/bundler/gems/rbenv-2332dba20ec1/lib/capistrano/tasks/rbenv.rake:12:in exit'
block (3 levels) in '
/Users/acandael/Sites/posplus/vendor/bundle/bundler/gems/rbenv-2332dba20ec1/lib/capistrano/tasks/rbenv.rake:12:in
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in instance_exec'
run'
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/backends/netssh.rb:54:in
/Users/acandael/Sites/posplus/vendor/bundle/gems/sshkit-1.5.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => rbenv:validate
(See full trace by running task with --trace)
I don't understand this, I ran 'ruby -v' on my Digital Ocean vps and it told me the Ruby version is:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
greetings,
Anthony
If you type this command, what is the output? ls ~/.rbenv/versions/2.1.2-p95
Also, type which ruby
and make sure the output is /home/deploy/.rbenv/shims/ruby
Hi Chris,
when I run the command as deploy user on the vps
which ~/.rbenv/versions/2.1.2-p95
I get no output, just a new cursor line
when I run
which ruby
I get
/home/deploy/.rbenv/shims/ruby
when I run
ruby -v
I get
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
I also try to solve the issue by changing the line in my Capfile from
set :rbenv_ruby, '2.1.2-p95'
to
set :rbenv_ruby, '2.1.2p95'
but that didn't fix it.
The second answer is good, shows that it's loaded rbenv correctly.
My bad on that first one, I meant ls ~/.rbenv/versions/2.1.2-p95
when I run
ls ~/.rbenv/versions/2.1.2-p95
on the vps, I get
ls: cannot access /home/deploy/.rbenv/versions/2.1.2-p95: No such file or directory
Well hmm, that's potentially your problem. That folder should exist to store your Ruby version in. I'm also running 2.1.2p25 on my machine, but I only have a ~/.rbenv/versions/2.1.2
folder.
Try using this instead:
set :rbenv_ruby, '2.1.2'
ok,
using
set :rbenv_ruby, '2.1.2'
fixed it.
However now I'm running in this error:
[62800640] Warning: Permanently added 'github.com,some id' (RSA) to the list of known hosts.
DEBUG[62800640] Permission denied (publickey).
DEBUG[62800640] fatal: Could not read from remote repository.
DEBUG[62800640]
DEBUG[62800640] Please make sure you have the correct access rights
DEBUG[62800640] and the repository exists.
DEBUG[62800640] Finished in 0.745 seconds with exit status 128 (failed).
Cool, so that's fixed. You'll need to check your git repo in the config to make sure it exists and/or add the forward_agent option to use your local keys for grabbing the code to the server from Github.
ok, again one step further
I ran
ssh-add ~/.ssh/id_rsa
in the terminal
and ran a new
cap deploy production
the deploy proces moved on, but then it failed with
Finished in 0.029 seconds with exit status 1 (failed).
ERRORlinked file /home/deploy/posplus/shared/config/database.yml does not exist on 95.85.5.6
I guess this has to do with the issue about creating the Postgres user which I reported about on this forum under the thread 'setup Postgres user fails'
You'll need to create the database.yml with a production config on the server in the folder that it mentions there since you don't have it in your repository. And yes, it'll need the configuration to postgres that you mentioned in the other thread.
Moved on again with the deployment proces, but the deployment still fails. Now there seems to be a problem with the bundle command
DEBUG[020e32cd] Command: cd /home/deploy/posplus/releases/20140904144347 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 ~/.rbenv/bin/rbenv exec bundle install --binstubs /home/deploy/posplus/shared/bin --path /home/deploy/posplus/shared/bundle --without development test --deployment --quiet )
DEBUG[020e32cd] rbenv: bundle: command not found
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing on host 95.85.5.6: bundle exit status: 127
bundle stdout: Nothing written
bundle stderr: rbenv: bundle: command not found
this is harder then I thought, I installed the bundler gem and now the next error is:
DEBUG[a18e2f6c] rake aborted!
DEBUG[a18e2f6c] ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
DEBUG[a18e2f6c] /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/execjs-2.2.1/lib/execjs/runtim
Googled this issue, seems I have to install Node.js with:
sudo apt-get install nodejs
ok, now I guess I ran into the Posgres issue, I reported on:
DEBUG[00c3d123] rake aborted!
DEBUG[00c3d123] ActiveRecord::AdapterNotSpecified: 'production' database is not configured. Available: []
I tried to solve this by adding settings for the production server in my local config.database.yml file
production:
database: <database>
adapter: postgresql
encoding: unicode
pool: 5
username: <username>
password: <password>
but I keep getting the same error message:
rake aborted!
DEBUG[ffcbeda7] ActiveRecord::AdapterNotSpecified: 'production' database is not configured. Available: []
DEBUG[ffcbeda7] /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/activerecord- 4.1.1/lib/active_record/connection_adapters/connection_specification.rb:257:in `resolve_symbol_connection'
I configured the production database and now the capistrano script is passing the production database error.
Now I'm bumping into another error:
rake aborted!
DEBUG[53a69508] ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
DEBUG[53a69508] /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/fog-core-1.22.0/lib/fog/core/service.rb:237:in `validate_options'
I guess this errror is related to the fact that my app is using Carrierwave and Fog and is storing uploaded images to Amazon S3.
Does this errror mean I should create Environment Variables for aws_access_key_id and aws_secret_access_key?
thanks for your help,
Anthony
I tried to add the environment variables to my vps environment with:
export S3_KEY='my key ...'
export S3_SECRET='my secret key'
but I'm keep getting the same error when I run 'cap production deploy':
DEBUG[4f41f85f] rake aborted!
DEBUG[4f41f85f] ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
DEBUG[4f41f85f] /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/fog-core-1.22.0/lib/fog/core/service.rb:237:in `validate_options'
If you're using Rails 4.1, you can use secrets.yml to set these variables or you can set them in the nginx configuration: https://www.phusionpassenger.com/documentation/Users%20guide%20Apache.html#about_environment_variables
man this is hard, I put the environment variable S3_KEY and S3_SECRET in different files:
~/.bashrc
/etc/default/nginx
home/deploy/posplus/shared/config/secrets.yml
but none solved the problem, I'm stil getting this error message when I try to do 'cap production deploy':
DEBUG[ff424d92] rake aborted!
DEBUG[ff424d92] ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
DEBUG[ff424d92] /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/fog-core-1.22.0/lib/fog/core/service.rb:237:in `validate_options'
Why don't you try hard coding the keys into secrets.yml just to get it working. It's not the most secure way but you will get yourself going, then you can worry about setting env vars.
Also, have you run source ~/.bashrc to reload bash and reading S3_KEY or S3_SECRET to see if it returns the key?
The following is link is pretty thorough on setting env vars:
https://www.digitalocean.com/community/tutorials/how-to-read-and-set-environmental-and-shell-variables-on-a-linux-vps
Hi James, thanks for the help,
I did put the hard coded keys in the secrets.yml file and also sourced the ~/.bashrc file. But it didn't solve the issue. Capistrano keeps giving me the error:
INFO[97d4f95a] Running ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile on 95.85.5.6
DEBUG[97d4f95a] Command: cd /home/deploy/posplus/releases/20140913135409 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 RAILS_ENV=production ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
DEBUG[97d4f95a] rake aborted!
DEBUG[97d4f95a] ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
If this could clear things up, my config/initializers/carrier_wave.rb file looks like this:
CarrierWave.configure do |config|
if Rails.env.staging? || Rails.env.production?
config.storage = :fog
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => ENV['S3_KEY'], # required
:aws_secret_access_key => ENV['S3_SECRET'], # required
}
config.fog_directory = 'posplus' # required
else
config.storage = :file
config.enable_processing = Rails.env.production?
end
end
I always worked on Heroku, where I set the environment variables with the 'heroku set:config ....' command.
greetings,
Anthony
If you use secrets.yml
, you don't access them through the ENV
anymore. Instead you want to use Rails.application.secrets.key_name
to retrieve your values.
Take a look here for a blog post on it: http://richonrails.com/articles/the-rails-4-1-secrets-yml-file
I'll also be sure to do a screencast on this topic because I think it's not documented too well. :)
Hi Chris, thanks, I wasn't aware of that and changed the carrier_wave.rb initializer:
CarrierWave.configure do |config|
if Rails.env.staging? || Rails.env.production?
config.storage = :fog
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => Rails.application.secrets.S3_KEY, # required
:aws_secret_access_key => Rails.application.secrets.S3_SECRET, # required
}
config.fog_directory = 'posplus' # required
else
config.storage = :file
config.enable_processing = Rails.env.production?
end
end
and my secrets.yml file looks like this:
production:
S3_KEY: <%= ENV['S3_KEY'] %>
S3_SECRET: <%= ENV['S3_SECRET'] %>
Then it also struck my that I working in a feature branch called 'capistrano' so I added
set :branch, 'capistrano'
to my config/deploy.rb file and I pushed the feature branch to a remote branch on Github
But I'm still getting the same error when doing 'cap production deploy':
DEBUG[e90c10e8] Command: cd /home/deploy/posplus/releases/20140914000558 && ( RBENV_ROOT=~/.rbenv RBENV_VERSION=2.1.2 RAILS_ENV=production ~/.rbenv/bin/rbenv exec bundle exec rake assets:precompile )
DEBUG[e90c10e8] rake aborted!
DEBUG[e90c10e8] ArgumentError: Missing required arguments: aws_access_key_id, aws_secret_access_key
DEBUG[e90c10e8] /home/deploy/posplus/shared/bundle/ruby/2.1.0/gems/fog-core-1.24.0/lib/fog/core/service.rb:237:in `validate_options'
sigh : (
I don't know why Capistranno isn't picking up the changes. Right now I'm not sure if this could be related to the problems I had with the creation of a postgres user.
Maybe you guys are seeing things I don't see? My remote feature branch is at:
https://github.com/acandael/posplus-rails/tree/capistrano
greetings,
Anthony
Well, the point about using secrets.yml
is that you don't need to put them in the ENV anymore. Just make sure the file is not in your repository.
Create secrets.yml
on the server in the shared directory like you did with database.yml
and then write your keys in it directly. Then add the file to your config/deploy.rb
to make sure it gets symlinked on deploy.
After that, you can use those secrets without having to go through ENV. They did this so that you wouldn't have to deal with this annoying system configuration and you can manage it a lot easier!
Hi Chris, thanks a lot, adding the secrets.yml file to config/deploy.rb solved the issue : )
I'm still not there, as a couple of other challenges await me like dealing with these failure messages:
DEBUG[f06a4082] Finished in 0.081 seconds with exit status 1 (failed).
DEBUG[09ba02b5] Running /usr/bin/env [ -f /home/deploy/posplus/releases/20140914083548/config/database.yml ] on <my-ip>
I'm getting a couple of these error messages when deploying with Capistrano.
Also there seem to be some issues with assets:
DEBUG[da33561d] I, [2014-09-14T04:36:06.122787 #24469] INFO -- : Writing /home/deploy/posplus/releases/20140914083548/public/assets/belfort-081a4bbefd8f4ed5f27bbb624d48f379.png
DEBUG[da33561d] I, [2014-09-14T04:36:06.125691 #24469] INFO -- : Writing /home/deploy/posplus/releases/20140914083548/public/assets/jigsaw-puzzle-1c07a986767187bd9961fe69651705c8.jpg
DEBUG[da33561d] I, [2014-09-14T04:36:06.127459 #24469] INFO -- : Writing /home/deploy/posplus/releases/20140914083548/public/assets/logo-posplus-72x61-c0cc65a8684ac8d9da5d402fcbc58c6e.png
DEBUG[da33561d] I, [2014-09-14T04:36:06.129307 #24469] INFO -- : Writing /home/deploy/posplus/releases/20140914083548/public/assets/logo-posplus-a0276666c4cf6aaeb387a2580cdefc71.png
DEBUG[da33561d] I, [2014-09-14T04:36:06.139111 #24469] INFO -- : Writing /home/deploy/posplus/releases/20140914083548/public/assets/member_placeholder-66af4d62c5dc83d72c054cf50caea6d5.png
But again I'm a step further in my quest to deploy a Rails app on a VPS
thanks for your patience,
Anthony
Hi Chris, James,
Just successfully deployed my Rails app on a Digital Ocean VPS ( a small step for mankind but a giant leap for a devops newbie):
thanks a lot for your help and patience,
greetings,
Anthony
Congrats Anthony!! :) After what seemed like a ton of issues, I'm glad you finally got it all running. I'm sure it will be way quicker next time!
This is awesome news! Getting that first one setup after debugging for what seems like endless amounts of time is a great feeling. Hopefully you learned quite a bit along the way.
@Chris, @James
The first deploy is a bit swimming in the ocean, lot's of new stuff, and not sure about what's going on. But I'm starting to feel more comfortable right now, and I'm glad I made the switch from Heroku to a Digital Ocean vps. The Rails Deploy Guide on GoRails was an awesome help, and I would recommend it to anybody having to deploy a Rails app for the first time.
Just a question (@Chris) about the the Rails Deploy Guide, is there a special reason that you use Passenger over Unicorn?
greetings, and again thanks a lot for your help!
Anthony
Mostly just because it's very simple and easy to get up and running. From some recent benchmarks I read, it also performs comparatively to Unicorn and some other solutions out there. Seemed to be a good mix of convenience to learn and performance.
+1 on using Passenger over Unicorn. I've tried both but I prefer Passenger. Plus it's bundled natively with Nginx which is nice. Configuration takes 30 seconds and you're done. And Chris is right, benchmarks point out that it performs just as good as Unicorn. There is some tuning you can do to make it run even better. If you need some help let me know, I'm very familiar with Nginx/Passenger and use it on all my apps.
If ever any one comes up with an issue with activeadmin and it failing with : NameError: uninitialized constant ActiveAdmin
--- I added
require 'activeadmin'
--- to the top of the initializers/active_admin.rb file, not sure if this breaks anything else but that fixed an issue for me see post - https://github.com/activeadmin/activeadmin/issues/1992
I then ran into the javascript problem and installed nodes, as per Anthony's reply above and that worked and it seems to have finished the deployment with out any other issue.... about to restart everything and check it out....
So after my wishful thinking of everything running smoothly i've tried the command - RAILS_ENV=production bundle exec rake db:create under the /home/deploy/myapp/current folder (i changed the mayor to my app name ) but i got the error - PG::InsufficientPrivilege: ERROR: permission denied to create database
Any help on this would be great!
Gareth - It is probably because your Postgres user doesn't have create database rights. You may want to either fix permissions on the user you are connecting with, or login as the postgres user and create the db manually.
Hey Chris,
Yeah i've been googling it and came across a couple of resources, most say i should run the following command -
psql -U your_username postgres
psql postgres
ALTER ROLE that_username CREATEDB
but that didn't seem to work as i still get that error... I'm not entirely sure how to create a db manually as the postgres user.... i'll google it a bit.... so close i can smell the cogs on the server burning! haha
Hmm, not sure what's wrong exactly. Also you could just create the db after getting into the psql console by doing CREATE DATABASE your_database_name
. Then you need to grant all privileges to that user on the new db.
Great reference for this stuff:
http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/
ok i've followed that somewhat haha (i was actually looking at that same link before you sent it through)
so i did the following
template1=# CREATE USER deploy WITH PASSWORD 'somepassword' SUPERUSER;
then made my way over to - /home/deploy/myapp/current
and ran - RAILS_ENV=production bundle exec rake db:create
seems to have worked a treat... i'll finish off the rest of your tutorial, and fingers crossed no more errors! :)
Cheers again for all the help
Gareth
ok last bit of help needed and i think we're ready to roll!
So i now get this error saying - Incomplete response received from application after restarting passenger and the nginx server, i've googled a couple of things and one link (below) says something to do with the <%= ENV["SECRET_KEY_BASE"] %> in secrets.yml
I'm confused, i thought this was for AWS storage of images etc etc...
How do i rectify this?
ok so i've edited the secrets.yml file from -
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
to
production:
secret_key_base: 1fa75cf22906eaa8bc9a9ebd43dfa80731morestuff
restarted everything and now i get server 500 error - We're sorry, but something went wrong.
I don't want to give up, but i checked the logs in appname/shared/logs/production.log but can't see anything there, maybe i'm looking in the wrong place...
Hey Guys.....
I've still got this dastardly "We're sorry, but something went wrong." error with my nibli site (chris you'll remember doing the code cast for me:) )
I've check the production.log under app/current/log but nothing there, i've also checked the /var/log/nginx/error.log and it's got something to do with the table lead (i'm guessing
App 2163 stdout: Processing by PagesController#index as HTML
App 2163 stdout: PG::UndefinedTable: ERROR: relation "leads" does not exist
App 2163 stdout: LINE 5: WHERE a.attrelid = '"leads"'::regclass
App 2163 stdout: ^
App 2163 stdout: : SELECT a.attname, format_type(a.atttypid, a.atttypmod),
App 2163 stdout: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
App 2163 stdout: FROM pg_attribute a LEFT JOIN pg_attrdef d
App 2163 stdout: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
App 2163 stdout: WHERE a.attrelid = '"leads"'::regclass
App 2163 stdout: AND a.attnum > 0 AND NOT a.attisdropped
App 2163 stdout: ORDER BY a.attnum
App 2163 stdout:
App 2163 stdout: PG::UndefinedTable: ERROR: relation "leads" does not exist
App 2163 stdout: LINE 5: WHERE a.attrelid = '"leads"'::regclass
App 2163 stdout: ^
App 2163 stdout: : SELECT a.attname, format_type(a.atttypid, a.atttypmod),
App 2163 stdout: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
App 2163 stdout: FROM pg_attribute a LEFT JOIN pg_attrdef d
App 2163 stdout: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
App 2163 stdout: WHERE a.attrelid = '"leads"'::regales
App 2163 stdout: AND a.attnum > 0 AND NOT a.attisdropped
App 2163 stdout: ORDER BY a.attnum
App 2163 stdout:
App 2163 stdout: Completed 500 Internal Server Error in 2ms
I thought that when we do the created the database it would do all the tables, how do i create them? do i have to do rake db:migrate?
So creating the database and creating the tables are separate. The migrations are what tells the database which tables and columns to add and the database is just the one place to store everything. You'll want to make sure the migrations run on the server.
You should be able to do that with cap deploy:migrate
I GOT IT WORKING!!!!! haha
sorry for all the spam in this forum post over the last couple of days....
I figured out how to create the table leads and the site is working a treat! (fingers crossed)
check it out - http://46.101.34.7
I tried hitting the URL and it gives
We're sorry, but something went wrong.
If you are the application owner check the logs for more information.
Can you provide some logs from your production server?
So Chris where do i run the cap deploy:migrate? on my local machine or on the server?
when run on the server
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
James this is the latest log - (it was working a moment ago, but my form didn't work - i got a 404 error when i submitted it, so i deleted the table)
pp 5028 stdout: Completed 500 Internal Server Error in 7ms
App 5028 stdout:
App 5028 stdout: ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "leads" does not exist
App 5028 stdout: LINE 5: WHERE a.attrelid = '"leads"'::regclass
App 5028 stdout: ^
App 5028 stdout: : SELECT a.attname, format_type(a.atttypid, a.atttypmod),
App 5028 stdout: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
App 5028 stdout: FROM pg_attribute a LEFT JOIN pg_attrdef d
App 5028 stdout: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
App 5028 stdout: WHERE a.attrelid = '"leads"'::regclass
App 5028 stdout: AND a.attnum > 0 AND NOT a.attisdropped
App 5028 stdout: ORDER BY a.attnum
App 5028 stdout: ):
App 5028 stdout: app/controllers/pages_controller.rb:4:in index'
index'
App 5028 stdout:
App 5028 stdout:
App 5028 stdout:
App 5028 stdout: ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "leads" does not exist
App 5028 stdout: LINE 5: WHERE a.attrelid = '"leads"'::regclass
App 5028 stdout: ^
App 5028 stdout: : SELECT a.attname, format_type(a.atttypid, a.atttypmod),
App 5028 stdout: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
App 5028 stdout: FROM pg_attribute a LEFT JOIN pg_attrdef d
App 5028 stdout: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
App 5028 stdout: WHERE a.attrelid = '"leads"'::regclass
App 5028 stdout: AND a.attnum > 0 AND NOT a.attisdropped
App 5028 stdout: ORDER BY a.attnum
App 5028 stdout: ):
App 5028 stdout: app/controllers/pages_controller.rb:4:in
App 5028 stdout:
App 5028 stdout:
ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "leads" does not exist
Are you sure you ran cap deploy:migrations
? Also does your model have any relations since this is what AR is reporting as a problem. It could also be an issue in your view/form so if you could post the code for that too that'd be helpful.
Well i tried running cap deploy:migrations on my local machine and server (not sure which is the correct one to run it on)
my server produced this -
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
my local machine produced this -
Stage not set, please call something such as cap production deploy
, where production is a stage you have defined.
so i ran it as cap production deploy:migrate -- and got this -
DEBUG [c6d7d298] Running /usr/bin/env [ -d ~/.rvm ] as deploy@46.101.34.7
DEBUG [c6d7d298] Command: [ -d ~/.rvm ]
DEBUG [c6d7d298] Finished in 1.270 seconds with exit status 0 (successful).
DEBUG [9ad5298d] Running ~/.rvm/bin/rvm version as deploy@46.101.34.7
DEBUG [9ad5298d] Command: ~/.rvm/bin/rvm version
DEBUG [9ad5298d] rvm 1.26.11 (latest) by Wayne E. Seguin wayneeseguin@gmail.com, Michal Papis mpapis@gmail.com [https://rvm.io/]
DEBUG [9ad5298d] Finished in 0.279 seconds with exit status 0 (successful).
rvm 1.26.11 (latest) by Wayne E. Seguin wayneeseguin@gmail.com, Michal Papis mpapis@gmail.com [https://rvm.io/]
DEBUG [dc47bb01] Running ~/.rvm/bin/rvm current as deploy@46.101.34.7
DEBUG [dc47bb01] Command: ~/.rvm/bin/rvm current
DEBUG [dc47bb01] ruby-2.1.2
DEBUG [dc47bb01] Finished in 0.275 seconds with exit status 0 (successful).
ruby-2.1.2
DEBUG [a69e5613] Running ~/.rvm/bin/rvm default do ruby --version as deploy@46.101.34.7
DEBUG [a69e5613] Command: ~/.rvm/bin/rvm default do ruby --version
DEBUG [a69e5613] ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
DEBUG [a69e5613] Finished in 0.633 seconds with exit status 0 (successful).
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
this is my git repo - https://github.com/ggomersall/Nibli_leads
You would run cap deploy:migrate
or cap deploy:migrations
from your local machine since this is a deployment callback.
If you deleted the table, then that's a part of the problem. I would start fresh, login to the production server, drop the database, recreate it manually and assign ownership to the db user (as Chris said you may have to create that user) that you have in your database.yml
file. Then after you've manually created the database run cap deploy:migrate
.
Hey James,
ok so just to clarify, i'm going to drop the database (nibli_leads), recreate it manually, and assign it to the db user...
when i'm recreating the database, do i have to manually create the table as well? i.e. table called "leads", with -
t.string "name"
t.string "email"
t.string "device"
t.string "country"
t.datetime "created_at"
t.datetime "updated_at"
and then run cap deploy:migrate?
or just create the database, without the table of "leads" and run cap deploy:migrate on my local machine?
Hey Gareth,
You don't have to recreate the table manually. Drop the database, recreate it, alter owner to your db user, then just run cap deploy:migrate
This should get your database all squared away. Once this happens if your form does not work, please provide a snapshot of the production log and I'll take a look.
Hey again James,
Well i did what was recommended, dropped the database (i even recreated the db user), recreated the db and then granted the access to the db user.... ran the command from my local machine - cap production deploy:migrate
No joy!
checked my production.log in the following locations /appname/current/log and /appname/shared/log but nothing printed in those.
my /var//var/log/nginx/error.log produces this -
App 10656 stdout: Completed 500 Internal Server Error in 2ms
App 10656 stdout:
App 10656 stdout: ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "leads" does not exist
App 10656 stdout: LINE 5: WHERE a.attrelid = '"leads"'::regclass
App 10656 stdout: ^
App 10656 stdout: : SELECT a.attname, format_type(a.atttypid, a.atttypmod),
App 10656 stdout: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
App 10656 stdout: FROM pg_attribute a LEFT JOIN pg_attrdef d
App 10656 stdout: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
App 10656 stdout: WHERE a.attrelid = '"leads"'::regclass
App 10656 stdout: AND a.attnum > 0 AND NOT a.attisdropped
App 10656 stdout: ORDER BY a.attnum
App 10656 stdout: ):
App 10656 stdout: app/controllers/pages_controller.rb:4:in index'
index'
App 10656 stdout:
App 10656 stdout:
App 10656 stdout:
App 10656 stdout: ActiveRecord::StatementInvalid (PG::UndefinedTable: ERROR: relation "leads" does not exist
App 10656 stdout: LINE 5: WHERE a.attrelid = '"leads"'::regclass
App 10656 stdout: ^
App 10656 stdout: : SELECT a.attname, format_type(a.atttypid, a.atttypmod),
App 10656 stdout: pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
App 10656 stdout: FROM pg_attribute a LEFT JOIN pg_attrdef d
App 10656 stdout: ON a.attrelid = d.adrelid AND a.attnum = d.adnum
App 10656 stdout: WHERE a.attrelid = '"leads"'::regclass
App 10656 stdout: AND a.attnum > 0 AND NOT a.attisdropped
App 10656 stdout: ORDER BY a.attnum
App 10656 stdout: ):
App 10656 stdout: app/controllers/pages_controller.rb:4:in
App 10656 stdout:
App 10656 stdout:
I don't want to give up (quitting is for quitters), but it seems as though heroku is a much easier option (for a newbie, but i don't want to be a newbie forever!)... so any help is much appreciated
ok so i've retraced all my steps in the documents for setting up this VPS on digitalocean i couple of things i changed (not sure if it had anything to do with the cap production deploy - but they are as follows -
- config/deploy/production.rb - i added the db part
set :stage, :production
server '46.101.34.7', user: 'deploy', roles: %w{web app db}
- Capfile - i added the rails/assets and rails/migrations
require 'capistrano/rvm'
set :rvm_type, :user
set :rvm_ruby_version, '2.1.2-p95'
require 'capistrano/bundler'
require 'capistrano/rails'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
I've managed to get the site up... on http://46.101.34.7, but now it seems when i fill out my form it takes me to a 404 error
i've checked the production logs and it's showing this -
I, [2015-04-03T11:56:52.639873 #30093] INFO -- : Migrating to CreateLeads (20150327183722)
I, [2015-04-03T11:56:52.696744 #30093] INFO -- : Migrating to CreateActiveAdminComments (20150330091152)
I, [2015-04-03T12:05:28.394905 #31343] INFO -- : Started GET "/" for 81.138.164.169 at 2015-04-03 12:05:28 -0400
I, [2015-04-03T12:05:28.430379 #31343] INFO -- : Processing by PagesController#index as HTML
I, [2015-04-03T12:05:28.519323 #31343] INFO -- : Rendered layouts/_leadsform.html.erb (59.3ms)
I, [2015-04-03T12:05:28.519556 #31343] INFO -- : Rendered pages/index.html.erb within layouts/application (62.4ms)
I, [2015-04-03T12:05:28.522403 #31343] INFO -- : Rendered layouts/_header.html.erb (0.4ms)
I, [2015-04-03T12:05:28.523556 #31343] INFO -- : Rendered layouts/_footer.html.erb (0.3ms)
I, [2015-04-03T12:05:28.524008 #31343] INFO -- : Completed 200 OK in 93ms (Views: 71.2ms | ActiveRecord: 10.7ms)
I, [2015-04-03T12:09:18.540633 #31343] INFO -- : Started GET "/" for 81.138.164.169 at 2015-04-03 12:09:18 -0400
I, [2015-04-03T12:09:18.549313 #31343] INFO -- : Processing by PagesController#index as HTML
I, [2015-04-03T12:09:18.620812 #31343] INFO -- : Rendered layouts/_leadsform.html.erb (61.1ms)
I, [2015-04-03T12:09:18.621050 #31343] INFO -- : Rendered pages/index.html.erb within layouts/application (65.1ms)
I, [2015-04-03T12:09:18.623674 #31343] INFO -- : Rendered layouts/_header.html.erb (0.5ms)
I, [2015-04-03T12:09:18.625089 #31343] INFO -- : Rendered layouts/_footer.html.erb (0.5ms)
I, [2015-04-03T12:09:18.625501 #31343] INFO -- : Completed 200 OK in 76ms (Views: 72.1ms | ActiveRecord: 0.0ms)
i've checked my app on local machine and works fine and redirects to root_path when completing the form, but on the server it tries to redirect to /leads
i've check code matches on both aswell and all seems legit.... strange... maybe James or Chris you know why this is?
Cheers
Gareth
Actually your repo is either gone or private: https://github.com/ggomersall/Nibli_leads I can't see it.
Hi James,
Thanks mate... apologies i turned it private, but i've made it public again... same link
Cheers
Got it, I'm taking a look and your create action in leads looks right. I'd like to see what the production server is doing in realtime. If you want me to login to your droplet I'd be happy to. I'll leave that up to you.
Yeah sure i don't mind giving you access to the production server...
Do you want the deploy account or would you like me to setup a new user with sudo access?
Also do you want me to post those details direct on this thread?
Do you have google chat? If so add me: jelinek at gmail dot com. Or you can email me directly. All I would need is the deploy credentials to take a look for you. I won't need sudo.
This is fixed. Your nginx configuration was wrong with the location directive and server name being set to local host in the same namespace as your FQDN. Your app now serves on 46.101.34.7 and the form submits properly and saves the record from what I can see. Next step is to setup an A record to point nibliapp.com to 46.101.34.7 and you'll be done!
This was a simple fix but we were looking in the wrong spots, focusing too much on Rails and not enough on the infrastructure layer. :) It's happened to me before too.
Let me know how I can be of assistance.
Hey James, that's awesome!
I've also setup the a record now so it's accessible via nibliapp.com
Thanks for all the help from you and Chris
Cheers
Gareth
I'm Brazilian, sorry by my inglish... I'm using bitbucket.
In my case capistrano run all commands ok, but in server no created any file its all empty in folder suppose deploy my project.