Ruby issue when doing cap deploy production
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