Searchkick and remote elastic search server configuration - ruby-on-rails

I have an elastic search running on a different server (Ubuntu 14.0.4), different from my web server and database server ( Database server is on a different server as well).
From the documentation, they suggested to set the
ENV["ELASTICSEARCH_URL"] = "http://username:password#api.searchbox.io"
and run the
rake searchkick:reindex CLASS=Product
When I do this, and run rake command, I get the following error
Mysql2::Error·Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
Any thoughts or suggestions?

You need to start your MySQL server using
service mysqld start or service mariadb start

Related

Chrome connects fine to Rails server started with `rails s`, fails with ERR_CONNECTION_REFUSED during system specs

I've got a docker-compose stack consisting of four services:
rails: a Rails app based on ruby:2.7.2-alpine
db: a Postgres database (postgres:12.2)
selenium a Selenium hub (selenium/hub)
selenium-chrome: a Selenium instance for debugging over VNC, based on selenium/node-chrome-debug
When I start up the stack, log into the rails container, and run rails s, I can connect to the selenium-chrome container over VNC, launch Chrome (via a docker exec command line), and navigate to http://rails:3000 with no difficulty. (This works even if I start the server with RAILS_ENV=test rails s.)
When I run system specs, however, they all fail with Chrome unable to load any of the Rails app pages, always failing with ERR_CONNECTION_REFUSED.
I added a byebug call before one of the failing visit calls, so I could try hitting the site manually with the in-container Chrome instance, and got this:
curl from within the Selenium container fails similarly:
root#6d92f4e4f0c0:/# curl -v http://rails:3000/
* Trying 172.27.0.5:3000...
* TCP_NODELAY set
* connect to 172.27.0.5 port 3000 failed: Connection refused
* Failed to connect to rails port 3000: Connection refused
* Closing connection 0
curl: (7) Failed to connect to rails port 3000: Connection refused
Is there a reason why during system tests the app would:
not be running, or
be running on the wrong port?
Turns out there were two problems:
Capybara was configured (in spec_helper.rb) to talk to a remote server, rather than an in-process Rack application:
Capybara.run_server = false # <-- oops! actually, we DO want a server
With this line removed, Capybara started the application, but on a random port (see Avdi Grimm, “Run Rails 6 System Tests in Docker Using a Host Browser”).
The fix was to remove run_server=false, but also add the following lines to my Capybara config:
Capybara.server_host = '0.0.0.0' # <-- could be "rails", but then tests *only* work in Docker
Capybara.server_port = 3000
Now Capybara starts a test server, and starts it on the port where the tests tell Selenium to find it.

Why can't I migrate my postgres database in windows?

I switched my database from sqlite to postgres for deployment on heroku. When I did that and attempted to run heroku run rake db:migrate -a I saw this error:
ActiveRecord::StatementInvalid: PG::DatatypeMismatch: ERROR: column "pay_date" cannot be cast automatically to type date HINT: You might need to specify "USING pay_date::date". : ALTER TABLE "recurring_payments" ALTER COLUMN "pay_date" TYPE date
So i created a migration to fix this, but when I run rake db:migrate to run the migration, I see this error:
PG::ConnectionBad: 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"?
However, when I check my services, I see that it is running, and it is configured to listen on port 5432. What else could be causing this issue?
Also, if I add this line to database.yml:
host: localhost
The error changes to this:
PG::ConnectionBad: could not translate host name "localhost" to address: Name or service not known
Perhaps this is more promising?
You seem to have multiple problems:
By default Rails uses Unix sockets to connect to PostgreSQL. Hence the original error message.
Adding the host key switches Rails to a TCP/IP connection instead, which is what you want in Windows.
Now you seem to have another problem: localhost cannot be resolved to an IP address, which suggests that you have general configuration problems on your Windows machines which are unrelated to Rails or PostgreSQL.
Check if your hosts file is messed up or if your (personal) firewall is blocking Rails or PostgreSQL. Try running ping localhost.
If all else fails try using host: 127.0.0.1 instead.

How to connect rails application(locally run on zeus) in another machine using IP?

I am using two rails applications, running both with rails s and zeus s -p3001 locally. When I am trying to run my application in another machine, the server started with webbrick is running fine on another system but couldnot run zeus. PLease help me out.
I just gave the url in browser 192.168.1.111:3000 (running). And
`192.168.1.111:3001` (server not found).
I tried zeus s -b 192.168.1.111:3001 but didn't help me.
The problem is, that the zeus bind to the local address (127.0.0.1) prohibiting connections from remove hosts. The proper solution would be to setup the reverse proxy using apache2 or nginx.
http://glasz.org/2013/10/25/reverse-proxy-a-rails-app.html
https://www.digitalocean.com/community/tutorials/how-to-deploy-rails-apps-using-unicorn-and-nginx-on-centos-6-5
Alternatively you may also want to use firewall to redirect requests.
http://forum.slicehost.com/index.php?p=/discussion/2497/iptables-redirect-port-80-to-port-8080/p1
But a quick and dirty solution is to use SSH port forwarding like this:
Start zeus on remote machine on port 3000
On local machine
local-machine$ ssh -L 3001:localhost:3000 remote-machine
On local machine: Connect to localhost:3001 instead of to remote-machine:3000
http://blog.trackets.com/2014/05/17/ssh-tunnel-local-and-remote-port-forwarding-explained-with-examples.html

Creating Users on Postgres - Authentication Issues - Installing

I'm attempting to create a Ruby on Rails web app that uses postgres as its database. I am having trouble connecting to the server with postgres
I have installed PostgreSQL and have successfully created a Rails app that uses postgres. However, when I run "rails server", it returns..
=> Booting WEBrick
=> Rails 3.2.13 application starting in development on XXX:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/lib/ruby/vendor_ruby/active_record/connection_adapters/postgresql_adapter.rb:1215:in `initialize': could not connect to server: Connection refused (PG::ConnectionBad)
Is the server running on host "localhost" (127.0.0.1) and accepting
TCP/IP connections on port 5432?
I believe I have an authentication problem. I've tried to follow two SO links, which appear to have worked for a great number of people, but for which the first steps have failed for me.
How to configure postgresql for the first time?
The first step of this link (su root) resulted in: "su: Authentication Failure".
I am trying to use this guide:
https://www.digitalocean.com/community/articles/how-to-install-and-use-postgresql-on-ubuntu-12-04
If I use "sudo -i", the "su - postgres" command works.
"createuser" then results in:
Enter name of role to add: XXX(root username)
Shall the new role be a superuser? (y/n) n
Shall the new role be allowed to create databases? (y/n) y
Shall the new role be allowed to create more new roles? (y/n) n
createuser: could not connect to database postgres: 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"?
When trying to follow the Ubuntu Postgres guide at https://help.ubuntu.com/community/PostgreSQL I had less success, with
sudo -u postgres psql postgres
returning:
psql: 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"?
Thanks! I'm still a beginner, so please explain things as simply as possible and elaborate.
You still need to start the postgres server. In ubuntu sudo /etc/init.d/postgresql-8.4 restart

How to allow multiple rails apps access to local postgreSQL database

I am new to Ruby/Rails and PostgreSQL. Is it possible to have to multiple rails apps access a psql local database at the same, if not how do you switch between applications?
Currently RailsApp1 is interacting with my psql db as expected, however RailsApp2 cannot connect and rake commands abort.
Running on: OSX Mountain Lion, ruby 1.9.3p194, rails 3.2.8, psql 9.2.1.
~/RailsApp2 #: rake db:migrate
rake aborted!
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Thank you in advance for the help.
PostgreSQL uses a client-server model, so the fact is you just connect to the server and multiple applications can make it work. Your specific problem sounds like the server isn't running or isn't accepting connections. Steps to try in order:
ps -A | grep post looking for postgres or postmaster processes. If not found start the server using the pg_ctl program.
Assuming it is running try setting the PGHOST environment variable to "localhost" so that it forces rake, psql, etc. to connect over TCP/IP. This would help if the UNIX socket is missing or just not where the client apps expect it to be.
If those two fail, find your postgresql logs (sometimes called serverlog, and sometimes in a pg_log directory) and post error messages.

Resources