Address already in use issue when running rails - ruby-on-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.

Related

Rails generate error: No such file or directory - getcwd

When running rails generate on a new Rails 4.2 project, I keep getting the error:
~/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/spring-1.3.0/lib/spring/configuration.rb:37:in `pwd': No such file or directory - getcwd (Errno::ENOENT)
How can I fix this?
The error is caused by an existing Rails Spring process running in the background.
You can easily solve this by running ps ax | grep spring to find the process id and then kill it.
There's an issue on the Rails GitHub about this:
https://github.com/rails/spring/issues/247
This error may also occur if you are working in a directory which was deleted from some other terminal instance.
If the directory (or some sub directory Rails will work with) you are working was renamed or removed, you'll have to run
cd .
and then you can run rails generate [...].
On my machine the same problem was arising because spring server stopped responding.
1:- To restart the spring server type in terminal
$: spring restart
2:- Try running the generator again.

Ruby on Rails config change while server is running?

Hi I'm new to Ruby on Rails. I have installed the Testia Tarantula application and am trying to read up on Ruby.
My question is how do I start/stop the server.
For example: I want to change the Admin email, so I execute the following command to change the configuration of the app:
RAILS_ENV=production rake db:config:app
But is this command ok to execute while the server is running, it has 'db' in the command which is what would warn me that I shouldn't run it while the server is up. Anyone have some helpful tips for learning Ruby on Rails server app management?
Welcome to Rails!
You can run rake db:xxxxx while the server is running and it won't hurt anything. However I usually stop my server, run my rake command and then start it back up to ensure that all changes will be picked up. If running in production, I would think you may want to restart the server just to make sure. I believe that the schema is generated/updated upon server startup, just fyi.
As far as starting and stopping the server, if you are attached to it you can just use ctrl + c. If it is detached, you can search for the pid and then kill -9 .
Running rake db:anything will load rails on its own. It doesn't matter if you have a server up or not. This will happen in the background. Think of it as the same as running a sql script while the server is running. It's a separate process.

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

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.

How to stop (and restart) the Rails Server?

I'm following the instructions here http://railsinstaller.org/mac to get up and running with Rails on a Mac running OS X 10.8.2
At step 8 I'm asked to restart Rails server but how?
I'm assuming via a command line, but from within the already open ruby terminal window or a new one?
Now in rails 5 you can do:
rails restart
The output of rails --tasks:
Restart app by touching tmp/restart.txt
I think that is usefully if you run rails as a demon
Press Ctrl+C
When you start the server it mentions this in the startup text.
On OSX, you can take advantage of the UNIX-like command line - here's what I keep handy in my .bashrc to enable me to more easily restart a server that's running in background (-d) mode (note that you have to be in the Rails root directory when running this):
alias restart_rails='kill -9 `cat tmp/pids/server.pid`; rails server -d'
My initial response to the comment by #zane about how the PID file isn't removed was that it might be behavior dependent on the Rails version or OS type. However, it's also possible that the shell runs the second command (rails server -d) sooner than the kill can actually cause the previous running instance to stop.
So alternatively, kill -9 cat tmp/pids/server.pid && rails server -d might be more robust; or you can specifically run the kill, wait for the tmp/pids folder to empty out, then restart your new server.
In case that doesn't work there is another way that works especially well in Windows: Kill localhost:3000 process from Windows command line
if you are not able to find the rails process to kill it might actually be not running. Delete the tmp folder and its sub-folders from where you are running the rails server and try again.
I had to restart the rails application on the production so I looked for an another answer. I have found it below:
http://wiki.ocssolutions.com/Restarting_a_Rails_Application_Using_Passenger
I just reboot the server with
Ctrl + c
That worked for me

Finding rails process server ID debian

OK guys,
So i managed to get ruby and rails and all necessary gem installed on out server, (if anyone saw my last question, the firewall was blocking the download of the various packages and gems so they were being currupted) and I started up the rails server, works good, but I called it with -d and now have no idea how to end it..
I've researched, and apparently you have to use the kill command, thats all well and good but I can't find the process ID for the rails server... I'm not even sure what to look for.. in some posts I found before it told me to look in i think usr/lib/tmp, but i dont have a tmp in there..
so, anyone got a better answer for me?
p.s. its a debian server
You can list all ruby processes by running : ps aux |grep ruby.
The second columns contain the process id, you just have to use kill PROCESS_ID (replace PROCESS_ID by your process number) to terminate the server process.

Resources