connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed - ruby-on-rails

I'm new to this so... my understanding is that postgres is listening on 5433 but the rails app is trying to connect on 5432
$ pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
14 main 5433 online postgres /var/lib/postgresql/14/main /var/log/postgresql/postgresql-14-main.log
$ sudo netstat -nlp | grep 5433
tcp 0 0 127.0.0.1:5433 0.0.0.0:* LISTEN -
unix 2 [ ACC ] STREAM LISTENING 340041 - /var/run/postgresql/.s.PGSQL.5433
I have read answers to similar questions but I haven't understood them well enough to fix this problem. Am I supposed to try to get postgres to listen on 5432? Or can I direct the app to try to connect on 5433 by editing config files?
-- This is on Codespace so it's running in a container.

Related

Xdebug 3.0 WSL2 and VSCode - address is already in use by docker-proxy

My VSCode in WSL:Ubuntu is unable to listen to the xdebug port, because it is blocked by some docker-proxy.
I was following this Solution, but trying VSCode to listen to the xdebug port, results in the following error:
Error: listen EADDRINUSE: address already in use :::9003
Can anyone help with connecting VSCode to xdebug?
Windows 11 says the port is already allocated by wslhost:
PS C:\WINDOWS\system32> Get-Process -Id (Get-NetTCPConnection -LocalPort 9003).OwningProcess
Handles NPM(K) PM(K) WS(K) CPU(s) Id SI ProcessName
------- ------ ----- ----- ------ -- -- -----------
285 47 2288 4748 0,05 19480 1 wslhost
Ubuntu tells, its allocated by some docker-proxy:
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:9003 0.0.0.0:* LISTEN 17210/docker-proxy
tcp6 0 0 :::9003 :::* LISTEN 17217/docker-proxy
docker-compose-version: docker-compose version 1.25.0
The xdebug.log says:
[Step Debug] INFO: Connecting to configured address/port: host.docker.internal:9003.
[Step Debug] ERR: Time-out connecting to debugging client, waited: 200 ms. Tried: host.docker.internal:9003 (through xdebug.client_host/xdebug.client_port) :-(
For sure as long as nothing is listening.
As to xdebug.client_host I'v tried:
host.docker.internal
xdebug://gateway and xdebug://nameserver refering to this: https://docs.google.com/document/d/1W-NzNtExf5C4eOu3rRQm1WlWnbW44u3ANDDA49d3FD4/edit?pli=1
setting the env-variable with docker-compose.yml: XDEBUG_CONFIG="client_host=..."
Removing the Expose directive from Dockerfile/docker-compose as in this comment doesn't remove the error neither.
Solved it. For others with this challenge:
Inside of wsl-ubuntu -> docker-containter host.docker.internal directs to the wrong ip.
In the wsl-distribution the file /etc/resolv.conf is the ip of the windows host.
To get the correct ip use this answer: How to get the primary IP address of the local machine on Linux and OS X?
My solution is to define an env-variable with this ip:
alias docker_compose_local_ip="ifconfig eth0 | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'"
export DOCKER_COMPOSE_LOCAL_IP=$(docker_compose_local_ip)
and configure the container with it:
services:
service-name:
environment:
- XDEBUG_CONFIG=client_host=${DOCKER_COMPOSE_LOCAL_IP} ...

How to open TCP and UDP ports on Mac

How can I open specific ports in order to use a SDK for a project?
I have already tried netcat, but it seems that you can only listen to a specific port or open a specific port if you have a hosting website.
To open a port and keep listening on it, on macOS this should be working:
nc -lk 8080
To test you can connect to the opened port by doing:
nc -vt 0 8080
To use UDP, you just need to use option -u, for example:
nc -u -lk 8080
To test you can connect:
nc -u -vt 0 8080
Output:
found 0 associations
found 1 connections:
1: flags=82<CONNECTED,PREFERRED>
outif (null)
src 127.0.0.1 port 63214
dst 127.0.0.1 port 8080
rank info not available
Connection to 0 port 8080 [udp/http-alt] succeeded!

rails: port is in use or requires root privileges

I am getting this error when attempting to start up a rails 4.1.1 server:
Listening on 0.0.0.0:3000, CTRL+C to stop
Exiting
/Users/darrenburgess/.rvm/gems/ruby-2.1.2#myflix/gems/eventmachine-1.0.0/lib/eventmachine.rb:526:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
I have tried the following commands to find and kill the process, however none of them reveal any servers running on 3000
ps ax | grep rails
ps ax | grep ruby
lsof -i TCP | grep LISTEN
lsof -i :3000
These, from my research on stack overflow, seem to be all of the available methods for discovering running ports.
In a rails 5 application I am getting the following similar error:
Listening on tcp://0.0.0.0:3000
Exiting
/Users/darrenburgess/.rvm/gems/ruby-2.3.1/gems/puma-3.7.0/lib/puma/binder.rb:269:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
Note that I can start rails servers on other ports.
This error persists even after machine reboot. Seems I have exhausted all avenues for finding and killing ports in use. What other things can I try?
UPDATE:
#hjpotter92 suggests running:
netstat -lntp | grep 3000
This however does not work as an option is required for the p argument. According to man netstat the list of protocols is found in etc/protocols.
I looked in that file and found that tcp is a listed protocol. However, this command does not return any output:
netstat -lntp tcp | grep 3000
Nor does this command return anything either:
netstat -lnt | grep 3000
You can try scanning the port like this lsof -i :3000 and then kill the process using sudo kill -9 <PID>.
Well, it turns out the answer to this is fairly obscure. The Node instance of FileMaker server 16 is running on port 3000. I was running a FileMaker server on the my Rails development machine.
This command helped to discover that:
sudo lsof -P -i :3000
Result
node 562 fmserver 20u IPv6 0x3ef1908b38776fe5 0t0 TCP *:3000 (LISTEN)
I could kill that process, however elected instead to disable the Node instance (The FileMaker REST/Data API).
Documentation here shows that FileMaker 16 is using that port.
http://help.filemaker.com/app/answers/detail/a_id/16319

Could not connect to a primary node for replica set #<Moped::Cluster[<Moped::Node resolved_address="10.10.4.131:27017">]

On my local Mac OSX, I want to run a rake task on a server which is within the my network. All the seeds to the remote mysql database work fine. But when I try to seed the mongodb data, I get the following error:
bundle exec rake db:seed RAILS_ENV=staging
rake aborted!
Moped::Errors::ConnectionFailure: Could not connect to a primary node for replica set
#<Moped::Cluster:70258359778560 #seeds=[<Moped::Node resolved_address="10.10.4.131:27017">]>
/Users/donato/.rvm/gems/ruby-2.1.2#core/gems/moped-2.0.4/lib/moped/cluster.rb:254:in `with_primary'
I am able to deploy to that server using capistrano. So I know it is not a networking issue. I also already tried the solution here. I deleted mongod.lock and then ran service mongod restart, without luck. However in that question, he was trying to run it on localhost, whereas I want to run it on another computer but within my network. What can I do?
Ok, I resolved it. Apparently, mongodb by default does not allow remote connections. It will only be available on the local interface and therefore accessible only within the machine itself:
# netstat -tulpn | grep mongod
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 12963/mongod
To solve this problem find out where your mongodb config file is:
# find / -type f -name mongod*
/etc/mongodb.conf
Then edit the file and add then add the private ip address of your machine (if the remote computer is in the same network as your local machine, otherwise you would have to add the public ip address as well):
bind_ip = 127.0.0.1,10.10.4.131
Then restart mongodb and check that it is listening on the private ip (in addition to the loopback interface):
service mongod restart
# netstat -tulpn | grep mongod
tcp 0 0 10.10.4.131:27017 0.0.0.0:* LISTEN 12963/mongod
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 12963/mongod
If you have a firewall, open the port up:
iptables -A INPUT -p tcp --dport 27017 -j ACCEPT
Then confirm from your local machine that you can now access that port remotely:
$ nc -z 10.10.4.131 27017
Connection to 10.10.4.131 port 27017 [tcp/*] succeeded!
And there you have it. Now we can seed the staging mongodb database from our local machine:
bundle exec rake db:seed RAILS_ENV=staging
This is just because you have not stopped mongodb correctly and mongod lock is created.
just delete mongob lock.Follow this two steps
1.sudo rm /var/lib/mongodb/mongod.lock
2.sudo service mongodb start

After OSX 10.8 upgrade postgres can not connect to the server

After a recent upgrade to Mountain Lion, I've run into problems with my brewed postgres install.
$ rake db:create
>rake db:migratecould not connect to server: Connection refused
> Is the server running on host "localhost" (::1) and accepting
> TCP/IP connections on port 5432?
>could not connect to server: Connection refused
> Is the server running on host "localhost" (fe80::1) and accepting
> TCP/IP connections on port 5432?
>could not connect to server: Connection refused
> Is the server running on host "localhost" (127.0.0.1) and accepting
> TCP/IP connections on port 5432?
After searching around the interwebs, I haven't yet found a solution to this issue.
I have found a suggested steps to help identify the problem but after following these, I'm not sure how to understand the results or what to do next. Can anyone help?
$ pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
>pg_ctl: another server might be running; trying to start server anyway
>server starting
$ pg_ctl -D /usr/local/var/postgres stop -s -m fast
>pg_ctl: could not send stop signal (PID: 865): No such process
$ pg_ctl status
>pg_ctl: no server running
$ ps auxw | grep post
>myuser 19037 2.6 7.7 4388248 324520 ?? S 7:30AM 19:06.02 /Applications/Postbox.app/Contents/MacOS/postbox-bin -psn_0_917728
>myuser 54897 0.1 0.0 2432768 464 s000 R+ 1:47PM 0:00.01 grep post
$ cat /usr/local/var/postgres/server.log
>FATAL: lock file "postmaster.pid" already exists
>HINT: Is another postmaster (PID 821) running in data directory "/usr/local/var/postgres"?
Happy to provide any additional info that may be useful.
try removing:
/usr/local/var/postgres/postmaster.pid
This once worked for me.

Resources