Capistrano Nginx Rails, After Rake Db:Migrate "Something went wrong" - ruby-on-rails

I needed to migrate my database, so I made the changes to my local system, pushed them to git, then cap production deploy. Once on the service I went to the current and ran rake db:migrate. Now when I visit my site I receive an error We're sorry, but something went wrong (500). There is no other information and my /opt/nginx/logs/error.log is completely blank. How do I fix this?
I'm using Postgresql, capistrano, rails 3, nginx

If you correctly installed ruby, rails, passenger and nginx, then follow my gist. You should go through the files and change the configuration according to your need. Here, you'll find
Gemfile // required gems for capistrano deployment
Capfile
deploy.rb // change the configuration for your server
production.rb // change the configuration for your server
After fully configured according to the gist, run
cap production deploy:check # it'll tell you what is missing for deploying your application
then, cap production deploy
Always check the production.log file if you facing any problem.

Related

Production Rails app fails with almost no log

I did my first deploy with a very simple rails app today on a Digital Ocean droplet running Ubuntu 14.04. I deployed following this article
https://www.digitalocean.com/community/tutorials/deploying-a-rails-app-on-ubuntu-14-04-with-capistrano-nginx-and-puma
and only replaced RVM with rbenv.
Now I get the "We're sorry, but something went wrong." Rails error page. My production.log says the following:
D, [2016-02-13T15:58:41.165515 #1783] DEBUG -- : ^[[1m^[[36mActiveRecord::SchemaMigration Load (1.5ms)^[[0m ^[[1mSELECT "schema_migrations".* FROM "schema_migrations"^[[0m
Puma logs are clean though. I had some trouble with rake in the first place, as migrations weren't executed by capistrano itself. So I updated rake from 10.4.2 to 10.5 and executed the migrations manually, but still the same error. Thanks in advance.
EDIT:
What I just noticed is that my public folder looks like this:
404.html 422.html 500.html assets favicon.ico robots.txt
As this is nginx' root folder, how is the app supposed to load in any way? As I said, this is my first deploy.
Puma logs are clean, but I bet Rails ones aren't. They're located under RAILS_ROOT/log directory, you probably want the production one.
My guess, without seeing those logs are that it's one of the following, ordered by likelihood:
You do not have a secret token generated which is done using rake secret and placing it in an environment variable. Check config/secrets.yml.
Bad database connection
Ruby environment is wrong, a certain gem is missing
It should be one of these three things. Check the log file first, though and maybe post it as an edit
Rails is letting you know that migrations need to be run by trying to load the schema so:
RAILS_ENV=production rake db:migrate assets:precompile

Using Capistrano to deploy a rails app

I am new to Capistrano and this is my first attempt using it to deploy my rails application. I believe I have my config/deploy.rb setup properly, but before I do
cap production deploy:setup
I want to make sure that no harm will happen to my database. The database for this project is already set and has data in it. I could not figure out if doing
cap production deploy:setup
will destroy my production database and re-create it as an empty DB. Opinions?
cap deploy:setup
When you run this command, Capistrano will SSH to your server, enter
the directory that you specified in the deploy_to variable, and create
a special directory structure that’s required for Capistrano to work
properly. If something is wrong with the permissions or SSH access,
you will get error messages. Look closely at the output Capistrano
gives you while the command is running.
This command will do nothing with your database.

run rails applicaton after capistrano deployment

Deploying rails app throw Capistrano first time: I deployed my rails app on another machine (server)
File structure for rails app ## this is my server
akshay#akshay:/var/www/model_demo$ ls
current releases repo revisions.log shared
cap -T ## showing a lots of rake task
like
cap deploy:migrate # Runs rake db:migrate if migrations are set
If I run this task it is not working saying
Stage not set, please call something such as `cap production deploy`, where production is a stage you have defined.
But when I run
cap production deploy # It works
Among all the listed task only cap production deploy
1: what exactly going on under the hood?
2: How might i run rake task which is provided by cap?
Any help would be appreciated !!!
Capistrano recepies are meant to run on local system.
Run it locally.
I catch my mistake. And as I followed Railscasts Capistrano screencasts, stackoverflow Capistrano Tags and deploying-rails-apps-to-a-vps-with-capistrano-v3.
As all cap tasks run locally.
cap production deploy:migrate # Worked for me
Thanks to #maxd !!!

rails console unable to connect to database in staging environment

Using capistrano I'm deploying my Rails 4 app under the environment name "staging". When I ssh onto the server and run rails console, any ActiveRecord queries I do come up with no such table. So I check my Rails.env and sure enough it reads development instead of staging. But even running rails console staging, it does set Rails.env to "staging", but still the ActiveRecord queries say no such table. The app itself is running fine (under Apache and Passenger), but for some reason the rails console is unable to connect to the db.
I've reverted back to when I knew it was working and am still seeing the error, which tells me it is a configuration change i must've made on the server as opposed to a change to the rails app code or capistrano deploy config.
OK, tracked down the answer myself. The RAILS_ENV was originally being set to staging in /etc/environment -- but a while ago this file was removed during some debugging, and not restored.
What does still surprise me is that
rails console staging
does not have the same effect as
export RAILS_ENV=staging
rails console
anyhow, sorted.

Heroku Deployment : Discourse Assets precompile

Hi I'm actually trying to deploy discourse on Heroku.
I'm following the step by step guide here Basic Heroku deployment
I'm facing a problem when I try to rake assets:precompile (I'm precompiling locally).
The rake command is aborted, saying to me that
No such file or directory: mydirectories/discourse/config/database.yml
When I rake assets:precompile I'm in production environment (RAILS_ENV=production).
So I checked if the database.yml was missing in the repo, and yes it was.
I currently have two database.yml but a bit different. There's database.yml.development-sample and
database.yml.production-sample.
I tried renaming database.yml.production-sample to a simple database.yml but it still doesn't work giving me this error:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
What am I doing wrong ?
Cordially,
Rob
PS : The config/redis.yml and public/assets are commented in the .gitignore
# http://shcatula.wordpress.com/2013/07/08/deploying-discourse-to-heroku/ you have a detailed description of deployment of Discourse to Heroku. It also links to a gist with a shell script that does the entire job of pre-compiling and preparing your deploy. The shell script pretty much explains all the steps needed. Hope it helps!

Resources