Rake routes fails with Access denied - ruby-on-rails-3

Trying to run the rake routes command on my remote site, and I get the error message Access denied for user 'xxx'#'localhost' (using password: YES)
The site can access the database, so it's not the settings in database.yml, but it has recently started throwing up Action not found errors after months of working OK. Any thoughts on how I can see the routes so that I can check nothing has been corrupted?
Rails 3.2.3, Ruby 1.8.7, Phusion Passenger.

Had the same issue and just resolved it by setting proper development database configuration options in config/database.yml
development:
adapter: mysql2
encoding: utf8
reconnect: false
database:
pool: 5
username:
password:
socket: /var/run/mysqld/mysqld.sock

Related

Where is Capistrano retrieving the IP Address from?

I have to deploy a rails app after the server had a problem, and the IP Address has changed.
I've updated the IP Address in deploy/production.rb, and also git's remote branches, to the correct value, namely 192.168.30.24, but as you can see from the following output, the deployment is failing due to trying to connect over 192.168.30.23.
Where is Capistrano retrieving 192.168.30.23 from?
INFO [fa83a838] Running /usr/bin/env git remote update as code#192.168.30.24
DEBUG [fa83a838] Command: cd /var/www/paperless_office/repo && ( export RBENV_ROOT="~/.rbenv" RBENV_VERSION="2.3.0" GIT_ASKPASS="/bin/echo" GIT_SSH="/tmp/paperless_office/git-ssh.sh" ; /usr/bin/env git remote update )
DEBUG [fa83a838] Fetching origin
DEBUG [fa83a838] ssh: connect to host 192.168.30.23 port 22: No route to host
Capfile
# Load DSL and Setup Up Stages
require 'capistrano/setup'
# Includes default deployment tasks
require 'capistrano/deploy'
require 'capistrano/rbenv'
require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.cap').each { |r| import r }
production.rb as follows:
role :app, %w{192.168.30.24}
role :web, %w{192.168.30.24}
role :db, %w{192.168.30.24}
server '192.168.30.24', user: 'code', roles: %w{web app}
after 'deploy:publishing', 'deploy:restart'
Thanks
Fixed this by removing the remote repo that Capistrano builds, so that on the next deploy, it was rebuilt using the correct IP Address.
I was deploying to /var/www/app_name so the repo to remove was /var/www/app_name/repo

ssh timing out on second login

I'm trying to set up Rails on my site via ssh. When everything is set up, I start the server with rails server and I get:
=> Rails 5.0.1 application starting in development on http://localhost:3000
=> Run rails server -h for more startup options
Puma starting in single mode...
* Version 3.6.2 (ruby 2.3.3-p222), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Use Ctrl-C to stop
It would be fine if the issue didn't stop there, but when I point my browser at the IP address on port 3000, my browser just hangs instead of displaying the Rails smoke page.
Since I can't type in more commands, I open a new terminal and log in via:
ssh -i /path/to/cloud.key user_name#XXX.XXX.XXX.XXX
I think I've seen it work before, but now it's timing out:
ssh: connect to host xxx.xxx.xxx.xxx port 22: Operation timed out
I found similar problems resolved on stackoverflow, but none of them solved the problem for public key authentication and when I try their solutions (ssh user_name#XXX.XXX.XXX.XXX), I turn up Permission denied (publickey).
So, I want to either learn why my browser is hanging (if I need to install nginx or apache2 or configure puma, etc.), and/or why my attempts to log into a second ssh session are failing.
Any help for this one?
Ubuntu Server 16.04
Rails 5.0.1
Ruby 2.3.0p0
You can't point your browser to the ip because the server is binding to localhost. You must enter rails s -b0.0.0.0

Rails app connecting to MS SQL Server Express on another server

I have developed an application using SQLite (as provided). I've renamed all the columns to fit with the SQL that is running on another server, but cannot get it to connect and to populate with the server database.
My database.yml file looks like this:
production:
adapter: mysql2
host: *IP*
encoding: utf8
reconnect: false
pool: 5
username: *user*
password: *pwd*
database: *DB name*
The IP I use to connect to the server is different to that of the IPv4 address of it, but I've tried both.
I've commented out:
gem 'sqlite3'
and replaced it with
gem 'mysql2', '~> 0.3.11'
Thanks.

ERROR Unkown database: DATABASE_URL after overriding the DATABASE_URL in the heroku app

I am trying to connect two Heroku apps to one database. So I overrided the DATABASE_URL. now the heroku config as:
=== muse-me Config Vars
DATABASE_URL: postgres://rbbcoxizviewiu:taJsBZf...
GEM_PATH: vendor/bundle/ruby/1.9.1
HEROKU_POSTGRESQL_OLIVE_URL: postgres://jnlltenwyvmdup:Q5Doaw...
LANG: en_US.UTF-8
PATH: bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin
RACK_ENV: production
RAILS_ENV: production
Then I run
heroku pg:psql DATABASE_URL
It gave me an error:
! Unknown database: DATABASE_URL. Valid options are: HEROKU_POSTGRESQL_OLIVE_URL
What should I do? Do I really connect to the database with the DATABASE_URL?
Thanks
"DATABASE_URL" is just a placeholder for "HEROKU_POSTGRESQL_OLIVE_URL". If you run:
heroku pg:psql HEROKU_POSTGRESQL_OLIVE_URL
That should work because you're explicitly telling pg which database url to use. To be able to use that command without specifying the db, you need to promote it to be your primary db:
heroku pg:promote HEROKU_POSTGRESQL_OLIVE_URL
heroku pg:psql
More info on promote is located here: https://devcenter.heroku.com/articles/heroku-postgresql#pgpromote
When running
heroku pg:psql DATABASE_URL
heroku tries to connect to the URL : DATABASE_URL, which obviously doesn't exist, it does read the ENV var DATABASE_URL
So if you're in the folder of your app, simply running
heroku pg:psql
is enough, otherwise, you can specify the app
heroku pg:psql --app <YOUR_APP>
And then heroku will read the DATABASE_URL var from the app it's connecting on.

Rails 3: PostgreSQL access denied after renaming app

I just renamed my application (replacing all instances of the old name with the new one), and now my application can no longer connect to the postgres database running on localhost.
PG::Error (could not connect to server: Connection refused (0x0000274D/10061)
Is the server running on host "localhost" (::1) and accepting
TCP/IP connections on port 5432?
Any ideas?
Thanks :-----)
EDIT: This is my database.yml
common: &common
adapter: postgresql
username: <username>
password: <password>
development:
<<: *common
database: development
test:
<<: *common
database: test
production:
<<: *common
database: production
Where username and password are the username and credentials for my postgres installation. However, I can't connect to the server using pgAdmin either!
I found the answer: Apparently my postgres server wasn't running locally, so I had to manually start the Service. :-)