Postgresql Schema not found after moving to Amazon AWS - ruby-on-rails

I have a multi-tenant rails 3.2 app that uses postgresql 9.3.5 and apartment gem. Everything works fine in my local and even when I ran "rails s -e production" it still works. Also when I use "rails c production" in AWS, its working. I can intercat with the db via rails console. I'm using VPC. My rails app is in ec2 and the db is in RDS.
When I deploy to AWS I get this error in the browser.
Apartment::SchemaNotFound
One of the following schema(s) is invalid: ec2-54-169-xxx-xxx, "public"
Passenger Logs:
App 9023 stderr: Apartment::SchemaNotFound (One of the following schema(s) is invalid: ec2-54-169-xxx-xxx, "public"):
App 9023 stderr: apartment (0.25.2) lib/apartment/adapters/postgresql_adapter.rb:92:in `rescue in connect_to_new'
App 9023 stderr: apartment (0.25.2) lib/apartment/adapters/postgresql_adapter.rb:85:in `connect_to_new'
App 9023 stderr: apartment (0.25.2) lib/apartment/adapters/abstract_adapter.rb:100:in `switch'
App 9023 stderr: apartment (0.25.2) lib/apartment/elevators/generic.rb:20:in `call'
ec2-54-169-xxx-xxx contains the ip of my ec2 I just replaced some with x.

Finally, I was able to fix it. I was using the Public DNS given by AWS to test. Looks like that was the error because my app was listening to the subdomain. When I tried using the ip of the EC2 it worked. So I worked on the Route53 right away to access it via domain name on the browser, then it already worked.

Related

Spring rspec can't connect to the database

I have a new Rails 5 app. I installed the spring and spring-commands-rspec gems as specified in their directions. I can run rspec by itself and the tests run fine. However, if I run the Spring binstub bin/rspec I get this:
Running via Spring preloader in process 227
/usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `initialize': could not connect to server: No such file or directory (PG::ConnectionBad)
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `new'
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:671:in `connect'
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:217:in `initialize'
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `new'
from /usr/local/bundle/gems/activerecord-5.0.0.1/lib/active_record/connection_adapters/postgresql_adapter.rb:37:in `postgresql_connection'
etc...
I have a Rails 4 app that uses the binstubs and bin/rspec works great. What gives?
Incidentally, rake spec fails the same way, with that database connection error.
Embarrassing. I had not set up my database.yml properly to inherit settings from *default, so the message above literally was telling me there was no database running. Once I got that fixed, the binstub worked again.

SemiFixed: Missing `secret_key_base` for 'production' environment

I've created a rails app (Rails 4.1.0) from scratch and I am getting a problem that I am not able to solve. I have installed and configured Apache Passenger Module, it works fine. Any time I try to access the virtual host I get an error 500:
Missing secret_key_base for 'production' environment, set this value in config/secrets.yml
The secret.yml file contains the following configuration:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Even when it's not recommended I did this:
production:
secret_key_base: XXXXXXXXXXXXXXXXXXXXXXXXXXXX (random key)
But Apache logs show this:
# tailf /etc/httpd/logs/error_log
[Tue May 06 12:56:18 2014] [error] [client 192.168.3.1] Premature end of script headers:
App 4405 stderr: [ 2014-05-06 12:56:18.5763 4421/0x9d48bdc(Worker 1) utils.rb:68 ]: *** Exception RuntimeError in Rack application object (Missing `secret_key_base` for 'production' environment, set this value in `config/secrets.yml`) (process 4421, thread 0x9d48bdc(Worker 1)):
App 4405 stderr: from /usr/local/rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/application.rb:440:in `validate_secret_key_config!'
App 4405 stderr: from /usr/local/rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/application.rb:195:in `env_config'
App 4405 stderr: from /usr/local/rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/engine.rb:510:in `call'
App 4405 stderr: from /usr/local/rvm/gems/ruby-2.1.1/gems/railties-4.1.0/lib/rails/application.rb:144:in `call'
App 4405 stderr: from /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/lib/phusion_passenger/rack/thread_handler_extension.rb:74:in `process_request'
App 4405 stderr: from /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/lib/phusion_passenger/request_handler/thread_handler.rb:141:in `accept_and_process_next_request'
App 4405 stderr: from /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/lib/phusion_passenger/request_handler/thread_handler.rb:109:in `main_loop'
App 4405 stderr: from /usr/local/rvm/gems/ruby-2.1.1/gems/passenger-4.0.41/lib/phusion_passenger/request_handler.rb:448:in `block (3 levels) in start_threads'
How I can fix this error? How do I access the development enviroment? I mean how I can write code, test in my browser and then deploy to Heroku or just test in production enviroment?
Update
I manage to fix the error above by setting RailsEnv development on VirtualHost but now I get this other error:
SQLite3::CantOpenException unable to open database file
Rails.root: /var/www/html/moviedb
I'm trying to use this GEM for make queries to TheMovieDB website and get results. Any advice on this new error?
Rails app secret key via bash
If you have access to the bashconsole of the user that is running the rails app, and if you are not using thin, then you could provide the environment variable via the users ~/.bashrc
just add the following:
export SECRET_KEY_BASE=`MY_SECRET_KEY`
Note: MY_SECRET_KEY could be anything but it would be secure to generate a key with rake secret on the bash console substitute that key with "MY_SECRET_KEY" from the example.
Once you have done that you should see a SECRET_KEY_BASE variable in the hash which is returned when you call ENV in your rails console.
Last but not least, reboot your rails app and the error should disappear.
Rails app secret key per rbenv-vars
Further, if you are using rbenv, you can use the rbenv-vars plugin to achive a per rails app secret key environment variable.
A good read on this would be here!
Using god (godrb.com): thanks hlcs
You need to god terminate and then start again.
What I did : On my production server, I create a config file (confthin.yml) for Thin (I'm using it) and add the following information :
environment: production
user: www-data
group: www-data
SECRET_KEY_BASE: mysecretkeyproduction
I then launch the app with
thin start -C /whereeveristhefieonprod/configthin.yml
Work like a charm and then no need to have the secret key on version control
Hope it could help, but I'm sure the same thing could be done with Unicorn and others.
I solved a similar situation with this (perhaps only useful in Ubuntu-like environment). See: Missing secret key base for production environment. Hope it helps.

API Signature is required to make requests to PayPal error, I have an API signature set already

I'm having a big problem right now. My site is written in Ruby on Rails, and I'm using the active merchant gem to interface with PayPal. The site is hosted on heroku.
I have an API key and API signature set as config variables in my heroku app. However, I still get the error:
Running: rake assets:precompile
(in /tmp/build_3pvaswdp7wvca1)
rake aborted!
An API Certificate or API Signature is required to make requests to PayPal
(See full trace by running task with --trace)
I can run heroku run rake assets:precompile separately and that works completely fine.
Furthermore, my staging site has the exact same config variables (RACK_ENV and RAILS_ENV are set to production on the staging site btw) set on my staging site and that seems to be working fine. However, my production site crashes.
Any ideas on what might be happening / how to fix this issue?
I just found out about this command:
heroku labs:enable user-env-compile -a myapp
BUT it is experimental.

"No Heroku apps are configured error" on Heroku Sans

I am configuring heroku_san for deploying Rails to Heroku. When I run any rake task it creates, I keep getting this error:
rake production deploy
No heroku apps are configured. Run:
rails generate heroku:config
I know that there are Heroku apps because I can see them when I run heroku list. What might be happening? Why can't this gem find the Heroku apps?
It looks like the gem was looking for a file called ~/.heroku/credentials. I did not have it. So I created that and added my user email and password separated by a linebreak:
myemail#gmail.com
herokupassword
Worked like a charm.

Cannot start JRuby rails 3.0.10 app on Torquebox with mysqljdbc driver

I 'm getting error message shown below on deploying rails 3.0.10 app on Torquebox server installed as a gem. Same error on both development and production modes. However, it works fine without Torquebox if i run a command "rails server -b 127.0.0.1 -p 3000 -e development". Not so sure something specific to Torquebox server.
ActiveRecord::ConnectionNotEstablished: no connection available: SET SQL_AUTO_IS_NULL=0
Settings
database.yml has
development:
adapter: jdbcmysql
username: root
password: 123
host: localhost
database: gidm_dev
Gemfile has
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter'
It's hard to determine the issue without more information. Would you be willing to join us on IRC (#torquebox on freenode) so we can work with you to figure it out? If IRC doesn't work for you, can you send an email to the TorqueBox user's list with the full log output from torquebox run along with your rails log?
More information about the IRC channel and mailing list can be found at http://torquebox.org/community/.

Resources