rails server stopped working suddenly could not connect to server [duplicate] - ruby-on-rails

I've been using the same Postgres database in this same app for a month with no problems, and I didn't change anything in the database before this error randomly came up today. However, today Postgres randomly started throwing this error when I try to "rails s" (I get the same type of error when running createdb or createuser):
Exiting
/Users/Joe/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `initialize': could not connect to server: No such file or directory (PG::Error)
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
What's really weird is that my friend had the exact same errors yesterday (working on the same app), and it was fixed by him running the script from http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/. After running the script, he uninstalled and reinstalled the PG gem to make everything work. However, he is running OS X Lion, and I am running Snow Leopard, so that script wouldn't work for me.
Any ideas of (1) why this would randomly start happening and (2) how to fix it?

I had a similar problem today, although in my case postgres (installed via homebrew on MacOS 10.8) wasn't running but I couldn't start or restart it. It appeared that due to a crash a zombie was blocking the socket, to resolve it i did the following
lsof -i :5432
this showed the PID of the process blocking, I simply killed it with
kill -9 PID
and postgres restarted fine.
HTH

Maybe something deleted /tmp/.s.PGSQL.5432 socket - a /tmp/ cleaning service for example.
Maybe you'll be able to connect using :host => 'localhost' as connection argument for PG::Connection.new() — it will avoid problems with locating proper path for Unix socket or file permissions problems.
If you do not want to use localhost (it probably is a little slower than a socket) then you can find where it is using lsof | grep PGSQL command as operating system administrator — if it is for example /var/run/postgres/.s.PGSQL.5432 — you would use :host => '/var/run/postres/'.

I was getting the same error when starting rails (No such file or directory). Re-installing postgres with the PostgreSQL one-click installer and rebooting resolved the issue.
In my case this happened after installing Mountain Lion, which probably cleaned the tmp directory.

I had a similar error and found this answer helpfull
Repairing Postgresql after upgrading to OSX 10.7 Lion
I resolved by adding
export PATH=/usr/local/bin:$PATH
to my .bash_profile

I faced same issue and when I checked server.log I can see it was not able to find that var/postgres folder and some of the conf files.
I did this, however I lost my data in that case
brew uninstall postgres
brew install postgres
initdb `brew --prefix`/var/postgres/data -E utf8``
That worked well for me and everything back to normal.

Related

Address already in use issue when running rails

Hi all I am new to rails and I am facing issue with running the rails app in WSL. I generated a new rails project and just set it up for deployment using capistrano. The deployment was successful. However, now I cant run rails locally. rails s gives me error.
I am posting the log here
I tried checking the port to see if any process was using port 3000 but it showed nothing. The commands that I tried are
lsof -wni tcp:3000
ps aux | grep puma
but they show no process that I can kill. I dont think this is an issue with WSL because I can run another newly created rails app.
Any help is highly appreciated. Thanks
I used to get this error too. I then realised that after I deleted the server.pid file found in either:
management\tmp\pids or > gateway\tmp\pids
and restarted the service, it ended up working.
I recommend you make a local copy of the file(s) in the pid folder incase you need it, then delete it, restart your service and see what happens.

How can i setup the path for heroku postgresql app?

I just installed the heroku PSQL app (v1.0) and i'm having trouble being able to connect my rails apps using the gem pg "0.1.4". I already added the path PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH" to my .profile and my .bashrc files, but nothing seems to allow me to run psql simply by calling "psql". I had success using "psql -h localhost". When i go for "psql" i get:
Is the server running locally and accepting
connections on Unix domain socket "/var/pgsql_socket/.s.PGSQL.5432"?
I'm using mountain lion.
Still pretty sure that both of the existing answers are answering the wrong question. The author mentions right in the title that he is having trouble with PATH, not connecting to his DB or configuring rails. This is the situation I got into, and this is my solution.
After getting postgres.app running and setting PATH in my .bashrc file as directed in the postgress.app documentation - http://postgresapp.com/documentation :
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
The problem was that this path setting was not taking effect after restarting terminal.app - running which psql was returning the copy in "/usr/bin/psql", this is the copy that comes installed with Lion and Mountain Lion, not the new version installed in "/Applications/". It even says in the Postgres.app instructions "run which psql to tell that the correct version is being loaded".
Anyway - the odd thing I found was that after I ran:
source .bashrc
Then the command "which psql" would return the correct version located in /Applications/.
At this point I was stumped and had to get some extra help. The guys I tapped also thought it was quite odd too, however they quickly found out that neither the .bashrc OR the .profile files were being loaded. This is very strange, I have not seen this on any of my other macs running leopard through lion.
Now finally the solution- I am not sure this is proper, but it did permanently fix my problem. We found that their was one profile file being loaded into the terminal - the .bash_login file. In the end the solution was just to use the .bash_login to source the .bashrc file. Here is the edit to .bash_login:
source $HOME/.bashrc
And that did it.
Anyway I can't say that this is exactly the fix that diego needed / was looking for, but it is definitely the problem for me.
You'll need to add host:localhost to any database configuration you're using in your development environment (read development / test/ production / etc):
config/database.yml
development:
adapter: postgresql
encoding: unicode
database: my_awesome_app_development
pool: 5
host: localhost
username: my_awesome_app_development
password:
Edit: also see Repairing Postgresql after upgrading to OSX 10.7 Lion
I know this is an old question but I just had the same problem. The issue is that there is a typo in the documentation. The app is Postgres93.app, not Postgres.app, so the path should have Postgres93.app:
PATH="/Applications/Postgres93.app/Contents/MacOS/bin:$PATH"
It's amazing how many posts there are about this and the typo doesn't seem to have been noticed yet. Changing that was all it took to get psql and which psql to work correctly for me.
Your PATH might be wrong. To find out the PATH of your psql script (on mac) open the sql shell script from your finder in Applications/Postgres installation. This will give you a hint as to where it is installed. That opened a window which told me it is located here: /Library/PostgreSQL/8.4/scripts/runpsql.sh
Then, I set the PATH variable from the terminal window by typing:
$ PATH="/Library/PostgreSQL/8.4/bin:$PATH"

Postgres just randomly stopped working (Rails, PGSQL.5432)

I've been using the same Postgres database in this same app for a month with no problems, and I didn't change anything in the database before this error randomly came up today. However, today Postgres randomly started throwing this error when I try to "rails s" (I get the same type of error when running createdb or createuser):
Exiting
/Users/Joe/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.2/lib/active_record/connection_adapters/postgresql_adapter.rb:1194:in `initialize': could not connect to server: No such file or directory (PG::Error)
Is the server running locally and accepting
connections on Unix domain socket "/tmp/.s.PGSQL.5432"?
What's really weird is that my friend had the exact same errors yesterday (working on the same app), and it was fixed by him running the script from http://nextmarvel.net/blog/2011/09/brew-install-postgresql-on-os-x-lion/. After running the script, he uninstalled and reinstalled the PG gem to make everything work. However, he is running OS X Lion, and I am running Snow Leopard, so that script wouldn't work for me.
Any ideas of (1) why this would randomly start happening and (2) how to fix it?
I had a similar problem today, although in my case postgres (installed via homebrew on MacOS 10.8) wasn't running but I couldn't start or restart it. It appeared that due to a crash a zombie was blocking the socket, to resolve it i did the following
lsof -i :5432
this showed the PID of the process blocking, I simply killed it with
kill -9 PID
and postgres restarted fine.
HTH
Maybe something deleted /tmp/.s.PGSQL.5432 socket - a /tmp/ cleaning service for example.
Maybe you'll be able to connect using :host => 'localhost' as connection argument for PG::Connection.new() — it will avoid problems with locating proper path for Unix socket or file permissions problems.
If you do not want to use localhost (it probably is a little slower than a socket) then you can find where it is using lsof | grep PGSQL command as operating system administrator — if it is for example /var/run/postgres/.s.PGSQL.5432 — you would use :host => '/var/run/postres/'.
I was getting the same error when starting rails (No such file or directory). Re-installing postgres with the PostgreSQL one-click installer and rebooting resolved the issue.
In my case this happened after installing Mountain Lion, which probably cleaned the tmp directory.
I had a similar error and found this answer helpfull
Repairing Postgresql after upgrading to OSX 10.7 Lion
I resolved by adding
export PATH=/usr/local/bin:$PATH
to my .bash_profile
I faced same issue and when I checked server.log I can see it was not able to find that var/postgres folder and some of the conf files.
I did this, however I lost my data in that case
brew uninstall postgres
brew install postgres
initdb `brew --prefix`/var/postgres/data -E utf8``
That worked well for me and everything back to normal.

Rails + Pow + Snow Leopard Server: I can't get Pow to work

I'm running Snow Leopard Server 10.6.7, and I need to host some Rails apps locally. Pow seems to be a good fit for what I need, but I can't seem to get it to work. At first, when I went to http://myapp.dev, I would get the OS X Server Welcome page. I asked around, and I was told to disable Web Sharing, which I did by turning off Web under Applications > Server > Server Admin. This hasn't helped.
I tried uninstalling and reinstalling Pow with Web disabled, but that didn't help anything, either. I tried restarting the Pow server by running touch /mydir/myapp/tmp/restart.txt, and that's not helped, either.
Have you followed the help carefully to create app? You must do a symlink of your app in ~/.pow
You can also use the gem powify:
Type 'gem install powify' in term
Type 'powify' in console and look at powify's help. Hint: cd in your app dir the type "powify create myapp" and then go to http://myapp.dev
Good luck!

Can't Get Mongrel_Service Gem to Start Mongrel as a Windows Service

I’m more or less a newb to Ruby on Rails, but I’ve been tasked with debuging a Rails app that guy that’s no longer around wrote. The app is running on a manchine using:
• Windows XP Professional
• Apache 2.2
• Rails 2.3.8
• mongrel (1.1.5 x86-mingw32)
• mongrel_service (0.3.4 i386-mswin32)
I copied the app from the server and did some debugging on it on my personal machine. I just setup a Git repository on my personal machine and cloned it back over to the server. Everything seems to be working great except mongrel_service doesn’t work anymore. Each time I try to start the service from Windows “Services” tool I get this error:
The MYAPP_Mongrel_As_Service service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service
I tried removing the service with:
C:\MyApp>mongrel_rails service::remove --name MYAPP_Mongrel_As_Service
Stopping MYAPP_Mongrel_As_Service if running...
MYAPP_Mongrel_As_Service service removed
and reinstalling it with:
C:\MyApp>mongrel_rails service::install --name MYAPP_Mongrel_As_Service -c "C:\MyApp" --port 3001 --env
ironment production --address localhost --log "log\mongrel_as_service.log" --pid "tmp\pids\mongrel_a
s_service.pid"
MYAPP_Mongrel_As_Service service created.
But no matter how many times I try, or what options I use, I can’t get the service to run. What’s weird is that I can get mongrel to startup by itself just fine.
C:\MyApp>mongrel_rails start -c c:\MyApp --port 3001 --environment production --address localhost --
g "c:\MyApp\log\mongrel_as_service.log" --pid "C:\MyApp\tmp\pids\mongrel_as_service.pid"
** Starting Mongrel listening at localhost:3001
** Starting Rails with production environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. INT => stop (no restart).
** Mongrel 1.1.5 available at localhost:3001
** Use CTRL-C to stop.
It just won’t work when I try to start it as a service. I've done a lot of googling on the subject, but I can't find anything to fix the problem. It's odd that it was working before but now it doesn't. There must be something wrong with my service::install line because I can't get the original unedited Rails app to work with mongrel_as_service either.
I figured it out. It turns out that the log file for mongrel_service didn't exist on my file. To fix the problem, I just made a blank text file and renamed it to the name of my log file. It worked like a charm. It's odd that mongrel_service doesn't make it's own log file if it can't detected it, but oh well.

Resources