WEBrick won't start after using Vagrant - ruby-on-rails

I had a new Rails app up and running with Vagrant, with the forward port set to 3000 like this in the Vagrant file
config.vm.forward_port 3000, 3000
After I shut down the server and exited vagrant I got this output `Connection to 127.0.0.1 closed,' however when I tried to start my Rails app without using Vagrant it's telling me
[2013-07-30 12:18:41] INFO WEBrick 1.3.1
[2013-07-30 12:18:41] INFO ruby 2.0.0 (2013-05-14) [x86_64-darwin12.4.0]
[2013-07-30 12:18:41] WARN TCPServer Error: Address already in use - bind(2)
Exiting
/Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:85:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:85:in `new'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:85:in `block in create_listeners'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:82:in `each'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/utils.rb:82:in `create_listeners'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/server.rb:132:in `listen'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/server.rb:113:in `initialize'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/2.0.0/webrick/httpserver.rb:45:in `initialize'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:11:in `new'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:11:in `run'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/server.rb:264:in `start'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:84:in `start'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:78:in `block in <top (required)>'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `tap'
from /Users/mm.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands.rb:73:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
A google search told me that I should do this
ps ax | grep ruby
and then kill the process but I was told there wasn't process with the number returned by grep.
michael$ ps ax | grep ruby
3604 s001 R+ 0:00.00 grep ruby
michael$ kill -9 3604
-bash: kill: (3604) - No such process
If this is connected to my use of Vagrant, any idea how I can fix the problem?
Update
Trying the command lsof -wni tcp:3000 found at this SO answer TCPServer Error: Address already in use - bind(2) also failed to kill the process
michael$ lsof -wni tcp:3000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
VBoxHeadl 601 mm 22u IPv4 0x888bec8d3960ddb1 0t0 TCP *:hbci (LISTEN)
michael$ kill -9 PID
-bash: kill: PID: arguments must be process or job IDs

Related

Can't start Rails localhost - (no processes running on port 3000)

tried to start my rails server, but I got that error
=> Booting Puma
=> Rails 5.1.4 application starting in development
=> Run `rails server -h` for more startup options
[25156] Puma starting in cluster mode...
[25156] * Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
[25156] * Min threads: 5, max threads: 5
[25156] * Environment: development
[25156] * Process workers: 2
[25156] * Preloading application
[25156] * Listening on tcp://0.0.0.0:3000
Exiting
/home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:269:in `initialize': Address already in use - bind(2) for "0.0.0.0" port 3000 (Errno::EADDRINUSE)
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:269:in `new'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:269:in `add_tcp_listener'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:105:in `block in parse'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:88:in `each'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/binder.rb:88:in `parse'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/runner.rb:144:in `load_and_bind'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/cluster.rb:391:in `run'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/puma/launcher.rb:174:in `run'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/puma-3.9.1/lib/rack/handler/puma.rb:69:in `run'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/rack-2.0.5/lib/rack/server.rb:297:in `start'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:44:in `start'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in `block in perform'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
from /home/ahmed/Rails/sample_app/bin/rails:9:in `require'
from /home/ahmed/Rails/sample_app/bin/rails:9:in `<top (required)>'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
from /home/ahmed/.rvm/gems/ruby-2.4.1/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
from /home/ahmed/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /home/ahmed/.rvm/rubies/ruby-2.4.1/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
from /home/ahmed/Rails/sample_app/bin/spring:15:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
I thought there's some process or something running on port 3000, so I tried to find it using
lsof -wni tcp:3000
but the command returns nothing, so that looks very strange, any solutions?
Update #1
I run this code from another question on stackoverflow and I got that
➜ ~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000
ruby 1595 beef-xss 17u IPv4 32839 0t0 TCP *:3000 (LISTEN)
so I tried
kill -9 1595
and
kill -9 32839
but nothing worked
also I restarted my computer, but the same problem exists, and there are no files inside my "tmp/pids" folders
Update #2
Solved it after uninstalling something called beef-xss using
sudo apt-get --purge remove beef-xss
If you are using a Linux operating system
First we will use the fuser command which identifies which processes are using a file or a socket.
fuser -n tcp 3000
3000 / tcp: 7425
The -n parameter is used when we want to identify processes that are using TCP or UDP sockets, in my case I want to know who is using port 3000.
The command returns the pid of the process, with this data and with the help of the ps command we will obtain more information about it.
ps x | grep 7425
7425 pts / 3 Tl 1:15 /home/carlos/.rvm/rubies/ruby-1.9.3-p0/bin/ruby
script / rails s
With this we see that an instance of the rails test server was hung, to free the port we killed the process using the pid that we already have.
kill -9 7425
And then we see that indeed the process has been completed.
ps x | grep 7425
7973 pts / 3 S + 0:00 grep --color = auto 7425
[1] + Finished (killed) rails s
I hope it will be you useful
The article of the answer http://community.logicalbricks.com/node/103
Have you tried to delete the pid files in tmp/pids?
If there is anything in the folder try to find a Puma process with pgrep -lf puma and take a look if there's any process of that.
I think you have run another server on the same port and you did not stop this unfortunately and command prompt closed, that's why it's showing this error. SO you can resolve this if you restart your computer.
Just restart your computer then try again.
Also, you can try to remove the files from tmp/pids/
I run this code from another question on stackoverflow and I got that
➜ ~ sudo lsof -iTCP -sTCP:LISTEN -P | grep :3000
ruby 1595 beef-xss 17u IPv4 32839 0t0 TCP *:3000 (LISTEN)
so I tried
kill -9 1595
and
kill -9 32839
but nothing worked
also I restarted my computer, but the same problem exists, and there are no files inside my "tmp/pids" folders
Update #2
Solved it after uninstalling something called beef-xss using
sudo apt-get --purge remove beef-xss

Slanger: Eventmachine port exception

I've installed slanger (and redis) for a rails project. Every rails instance is off.
I run redis-server and it works properly. But then I run:
slanger --app_key MyPusherApiKey --secret MyPusherSecret
and it raises the next exception:
my-directory/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:534:in `start_tcp_server': no acceptor (port is in use or requires root privileges) (RuntimeError)
from my-directory/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:534:in `start_server'
from my-directory/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/em-websocket-0.5.1/lib/em-websocket/websocket.rb:46:in `run'
from my-directory/.rvm/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/em-websocket-0.5.1/lib/em-websocket/websocket.rb:39:in `block in start'
from my-directory/.rvm/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:170:in `call'
from my-directory/.rvm/rubies/ruby-2.2.3/lib/ruby/gems/2.2.0/gems/eventmachine-1.0.9.1/lib/eventmachine.rb:170:in `run'
I thought that if the port was in use, I could just change it like this:
slanger --app_key MyPusherApiKey --secret MyPusherSecret -a 0.0.0.0:3646
But I still get the same error. Any ideas?
Finally I saw that the port 8080 was being used by Nginx.
Stopped nginx and I got it working fine.
nginx -s stop

Cannot kill process on port 3000

I cannot seem to figure out how to kill this process.
I already know that i can, and have been, just running the server on a different port, but it's just annoying me that i can't figure this out.
Below you'll see first the error i get when i try to run rails s then all of my attempts to find the PID and kill.
// ♥ rails s
=> Booting Puma
=> Rails 5.0.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.2.3-p173), codename: Sleepy Sunday Serenity
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://localhost:3000
Exiting
/Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:266:in `initialize': Address already in use - bind(2) for "::1" port 3000 (Errno::EADDRINUSE)
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:266:in `new'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:266:in `add_tcp_listener'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:260:in `block in add_tcp_listener'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:259:in `each'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:259:in `add_tcp_listener'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:102:in `block in parse'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:85:in `each'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/binder.rb:85:in `parse'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/runner.rb:133:in `load_and_bind'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/single.rb:85:in `run'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/puma/launcher.rb:172:in `run'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/puma-3.6.2/lib/rack/handler/puma.rb:51:in `run'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/rack-2.0.1/lib/rack/server.rb:296:in `start'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands/server.rb:79:in `start'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:90:in `block in server'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `tap'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:85:in `server'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/railties-5.0.0.1/lib/rails/commands.rb:18:in `<top (required)>'
from /Users/jrogers2/Development/code/presently/bin/rails:9:in `require'
from /Users/jrogers2/Development/code/presently/bin/rails:9:in `<top (required)>'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `load'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/spring-2.0.0/lib/spring/client/rails.rb:28:in `call'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/spring-2.0.0/lib/spring/client/command.rb:7:in `call'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/spring-2.0.0/lib/spring/client.rb:30:in `run'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/spring-2.0.0/bin/spring:49:in `<top (required)>'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `load'
from /Users/jrogers2/.rvm/gems/ruby-2.2.3/gems/spring-2.0.0/lib/spring/binstub.rb:31:in `<top (required)>'
from /Users/jrogers2/Development/code/presently/bin/spring:14:in `require'
from /Users/jrogers2/Development/code/presently/bin/spring:14:in `<top (required)>'
from bin/rails:3:in `load'
from bin/rails:3:in `<main>'
[09:28:36] (master) presently
// ♥ sudo lsof -n -i4TCP:3000 | grep LISTEN
postgres 101 postgres 5u IPv4 0x97a8cfe190b174f1 0t0 TCP *:hbci (LISTEN)
[09:28:43] (master) presently
// ♥ kill -9 101
-bash: kill: (101) - Operation not permitted
[09:28:45] (master) presently
// ♥ ps aux | grep puma
jrogers2 27960 0.0 0.0 2432804 1972 s000 S+ 9:28AM 0:00.00 grep puma
[09:28:58] (master) presently
// ♥ kill -9 27960
-bash: kill: (27960) - No such process
[09:29:14] (master) presently
// ♥ ps aux | grep 3000
jrogers2 27971 0.0 0.0 2442612 1196 s000 R+ 9:29AM 0:00.00 grep 3000
[09:29:28] (master) presently
// ♥ kill -9 27971
-bash: kill: (27971) - No such process
// ♥ lsof -wni tcp:3000
[09:32:03] (master) presently
// ♥ lsof -i tcp:3000
[09:32:41] (master) presently
// ♥ ps aux | grep rails
jrogers2 28035 0.0 0.0 2442612 1172 s000 R+ 9:34AM 0:00.00 grep rails
[09:34:14] (master) presently
// ♥ kill -9 28035
-bash: kill: (28035) - No such process
find your rails s process PID and kill it
$ ps aux | grep -v grep | grep rails
$ sudo kill -9 <pid_of_rails_s_from_above>
or you can try this one liner
$ sudo kill -9 $(lsof -i tcp:3000 -t)
tmp/pids $ kill -9 $(cat server.pid)
While I run rails, I get the following output for lsof:
$ sudo lsof -n -i4TCP:3000 | grep LISTEN
ruby 23582 username 14u IPv4 0x2c5fd1f36e3c475f 0t0 TCP *:hbci (LISTEN)
So you already seem to have figured out what process is runnning on port 3000, a postgres process owned by the postgres user and probably not rails related. Given that it is running on a very low pid, 101, it was very likely started within the boot process. So instead on focussing how to kill it, I would look what caused it to start in the first place. Perhaps you should check your postrgres config (postgres.conf), was it's setup changed to run on port 3000?
If you really want to kill it, sudo is your friend:
sudo kill 101
I'd be careful with using kill -9 as there are certain risks in killing databases with that signal (SIGKILL), the process will die immediately and can't clean up after itself (more on this: GIYF, for example https://www.linuxvoice.com/core-technology-signals/. There was a good answer on signals on stackoverflow (IIRC), but can't seem to find it just now...)
ps aux | grep 3000
sudo kill -9
Which kill process force fully

Rails: Address already in use - bind(2) (Errno::EADDRINUSE)

I am trying to deploy Rails app with the Puma web server. When trying to start Puma server with a config file bundle exec puma -C config/puma.rb I get an error that the address is already in use.
Does someone know how to fix this?
bundle exec puma -C config/puma.rb
[23699] Puma starting in cluster mode...
[23699] * Version 2.11.3 (ruby 2.0.0-p353), codename: Intrepid Squirrel
[23699] * Min threads: 5, max threads: 5
[23699] * Environment: development
[23699] * Process workers: 2
[23699] * Preloading application
Jdbc-MySQL is only for use with JRuby
[23699] * Listening on tcp://0.0.0.0:3000
/.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:210:in `initialize': Address already in use - bind(2) (Errno::EADDRINUSE)
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:210:in `new'
from /Users/lexi87/.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:210:in `add_tcp_listener'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:96:in `block in parse'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:82:in `each'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/binder.rb:82:in `parse'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/runner.rb:119:in `load_and_bind'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/cluster.rb:302:in `run'
from /.rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/lib/puma/cli.rb:216:in `run'
from /rvm/gems/ruby-2.0.0-p353/gems/puma-2.11.3/bin/puma:10:in `<top (required)>'
from /.rvm/gems/ruby-2.0.0-p353/bin/puma:23:in `load'
from /.rvm/gems/ruby-2.0.0-p353/bin/puma:23:in `<main>'
from /.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `eval'
from /.rvm/gems/ruby-2.0.0-p353/bin/ruby_executable_hooks:15:in `<main>'
You need to use kill -9 59780 with 59780 replaced with found PID number (use lsof -wni tcp:3000 to see which process used 3000 port and get the process PID).
Or you can just modify your puma config change the tcp port tcp://127.0.0.1:3000 from 3000 to 9292 or other port that not been used.
Or you can start your rails app by using:
bundle exec puma -C config/puma.rb -b tcp://127.0.0.1:3001
To kill the puma process first run
lsof -wni tcp:3000
to show what is using port 3000. Then use the PID that comes with the result to run the kill process.
For example after running lsof -wni tcp:3000 you might get something like
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ruby 3366 dummy 8u IPv4 16901 0t0 TCP 127.0.0.1:3000 (LISTEN)
Now run the following to kill the process. (where 3366 is the PID)
kill -9 3366
Should resolve the issue
you can also try this trick:
ps aux | grep puma
sample output:
myname 77921 0.0 0.0 2433828 1972 s000 R+ 11:17AM 0:00.00 grep puma
myname 67661 0.0 2.3 2680504 191204 s002 S+ 11:00AM 0:18.38 puma 3.11.2 (tcp://localhost:3000) [my_proj]
then:
kill -9 67661
Found the script below in this github issue. Works great for me.
#!/usr/bin/env ruby
port = ARGV.first || 3000
system("sudo echo kill-server-on #{port}")
pid = `sudo lsof -iTCP -sTCP:LISTEN -n -P | grep #{port} | awk '{ print $2 }' | head -n 1`.strip
puts "PID: #{pid}"
`kill -9 #{pid}` unless pid.empty?
You can either run it in irb or inside a ruby file.
For the latter, create server_killer.rb then run it with ruby server_killer.rb
SOLUTION FOR GENERAL Address already in use - bind(2) (Errno::EADDRINUSE)
This issue is because we are trying to use the same port which is already is use. so we have to stop the services running on that port so that we can run another services.
we can use kill like kill -9 {PID}where {PID} is the PID of the services running on that port. To know the PID of any services lets say "firefox" we can use commands like pidof firefox, ps aux | grep -i firefox ,pgrep firefox and then use the kill command to stop that service.
sometime we might get into the situation where we don't know the PID or the service name to search for in this case we can use the following little ruby code to do it for us.(in this case port 3000, you can change it according to your need)
#!/usr/bin/env ruby
port = ARGV.first || 3000
system("sudo echo kill-server-on #{port}")
pid = `sudo lsof -iTCP -sTCP:LISTEN -n -P | grep #{port} | awk '{ print $2 }' | head -n 1`.strip
puts "PID: #{pid}"
`kill -9 #{pid}` unless pid.empty?
save it as something.rb and run sudo ruby something.rb
If the above solutions don't work on ubuntu/linux then you can try this
sudo fuser -k -n tcp port
Run it several times to kill processes on your port of choosing. port could be 3000 for example. You would have killed all the processes if you see no output after running the command
You can find and kill the running processes: ps aux | grep puma
Then you can kill it with kill PID
I had this issue on my Macbook Air, running Rails 5.0.3, Puma 5.2.2
Tried running
lsof -wni tcp:3000 but there's no process on this port number.
Managed to fix this by running:
export PORT=3000 on my terminal, then I just added this extra line to my .bash_profile
It might be old but in my case, it was because of docker. Hope it will help others.

foreman start error (server.rb:33, missing argument...)

After trying to start foreman, I get this error (note that it does seem to work on heroku though so I guess this is a strictly local problem):
hrn039:textthechange jon$ foreman start
02:20:00 web.1 | started with pid 7363
02:20:01 web.1 | /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/server.rb:33:in `parse!': missing argument: -e (OptionParser::MissingArgument)
02:20:01 web.1 | from /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:280:in `parse_options'
02:20:01 web.1 | from /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/rack-1.4.1/lib/rack/server.rb:180:in `options'
02:20:01 web.1 | from /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/server.rb:54:in `set_environment'
02:20:01 web.1 | from /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands/server.rb:42:in `initialize'
02:20:01 web.1 | from /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:50:in `new'
02:20:01 web.1 | from /Users/jon/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.1/lib/rails/commands.rb:50:in `<top (required)>'
02:20:01 web.1 | from script/rails:6:in `require'
02:20:01 web.1 | from script/rails:6:in `<main>'
02:20:01 web.1 | process terminated
02:20:01 system | sending SIGTERM to all processes
The Procfile only has one line as specified by heroku
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
And my gemfile has
gem 'thin'
Google isn't being very helpful with this error.
Thanks!
This is not about executing on Heroku - see that the original question about is about executing with Foreman - which is local execution.
You can replicate your error by executing the following:
rails server thin -e
That's effectively what Foreman is running, given your Procfile:
web: bundle exec rails server thin -p $PORT -e $RACK_ENV
So I'm going to guess that you're not passing in an argument to -e. ie. you haven't defined RACK_ENV locally.
What you can do is create a .env file in your local directory, something like
RACK_ENV=development
PORT=3000
Foreman will automatically pick up the local .env file and set the environment appropriately, before creating the process based on your process type declaration.
I had the same problem with rails v3.2 in Ubuntu 10.04.
I managed to get thin running by doing the following steps:
Change your Procfile as follows:
web: bundle exec rails server thin -p $PORT -e development
Add $stdout.sync = true on the top of your config.ru file, to direct server output to your terminal (otherwise you do not get output in your terminal)
Tell me if it works!
I just ran into this same problem. If you change your Procfile to just
web: bundle exec rails server thin -p $PORT
it should work. Note, this uses the default Thin port of 5000 rather than 3000 (which means you'll need to go to http://localhost:5000 to see your app.
Having just
web: bundle exec rails server thin
in your Procfile will use port 3000, but this will cause errors on Heroku.

Resources