What is a Rack - "no acceptor" error? - ruby

While trying to run my config.ru, I'm getting an odd error I can't seem to debug called a 'No acceptor' error.
Full error message:
eventmachine.rb:572:in `start_tcp_server': no acceptor (RuntimeError)
Does anyone know what this error means? Thanks.

As #Fivell says, I think the problem is that you have a previous instance of thin still running. Rather than start on another port though, I would recommend killing the previous instance. Something like this should do the job (I recreated the problem here, so this is real output on my end):
telemachus caps $ ps ax | grep ruby
153 ?? S 7:52.18 ruby /usr/local/bin/djsd
15801 ?? S 0:00.40 ruby caps.rb # this is our problem, get it's PID
15973 s000 S+ 0:00.00 grep ruby
telemachus caps $ kill -9 15801 # thin needs -9 - hard to kill
telemachus caps $ ps ax | grep ruby
153 ?? R 7:52.86 ruby /usr/local/bin/djsd
16057 s000 S+ 0:00.00 grep ruby
Depending on how you started your app, you may need to grep for something different (say if you used shotgun or rackup).

I think the problem is that using port is already binded (maybe you started your application earlier) Try to change port
rackup config.ru -p port #default port is 9292 change to something else
or if you use thin
thin start -p port -a 0.0.0.0 -R config.ru #default port is 8080 change to something else

I am getting this error although there are no zombie processes and the port is not binded.
This works:
thin -p9292 start
But this does not:
rackup

Related

how to stop http-server on a specific port?

I am using http-server in order to load http://localhost:8484 on a specific folder. (For testing purposes)
the os commands I run in my code are:
http-server -p 8484 test/
and after I finish downloading whatever I run:
http-server stop
However, after the test is done, I see that the http-server with port 8484 is still alive!
by running ps aux | grep http
What command should I run in order to stop it?
I am using Mac OSX (El Capitan version)
I write the code in erlang (though I don't think it matters since I am running shell commands from the code).
http-server: https://www.npmjs.com/package/http-server
My code in erlang:
my_test_() ->
Pid = spawn(fun() ->
Info = os:cmd("http-server -p 8484 test/resources"),
io:format(user,"*** Server: ~p~n",[Info])
end),
%%% Do some job %%%
Pid2 = spawn(fun() ->
Info = os:cmd("http-server stop"),
timer:sleep(200),
io:format(user,"*** Server stop: ~p~n",[Info])
end),
timer:sleep(200),
exit(Pid2, kill),
exit(Pid, kill).
Use:
kill -9 {pid}
Also, out of interest, if you want to see all processes running on a specific port, use:
lsof -i :{port}
EDIT: Using kill -9... is a bit harsh, I know, there is probably a more graceful way of doing it, but it does get the job done ;-)
For Windows users use the command prompt (cmd):
Method 1:
Just do Control+c on the same console where the http-server is running
Method 2: Find and Kill the process:
i. Find the process-id which uses the particular port number (say 8484)
netstat -ano | findstr 8484
Result: TCP 0.0.0.0:8484 0.0.0.0:0 LISTENING 21816
ii. Kill the process using the found process-id (say 21816)
taskkill /F /PID 21816
You can use perc - since Node.js http-server is not Erlang process, but Unix process, you need to use the module (or dig it's code to see the implementation ;) ) .
Alternatively, from Erlang os:cmd("kill -9 5607"). (where 5607 is your unix pid);

How to disable guard after uninstalling Ruby?

I installed Ruby on a server (1.9.3 via RVM), set up Guard on some directories, then established I didn't need any of this anymore and uninstalled Ruby (via an RVM command).
My problem is, any directory access to the directories Guard was watching still triggers an attempt to launch Ruby (which is no longer there), therefore causing an error.
I thought that, since Guard was a Ruby gem, uninstalling Ruby would "turn off" guard. It seems there's more to it than that, and that some process still remains.
How do I kill the ghost of guard?
Another thread suggested I run ps aux | grep guard to find the PID of the guard process then kill it, but the only thing that finds is the grep guard itself:
root 6754 0.0 0.0 6384 676 pts/1 S+ 13:45 0:00 grep guard
It seems like whatever this "ghost of guard" is, it's not called guard.
It's probably not relevant, but in case it is, guard was launched via the Drupal Drush command drush omega-guard which is part of the Drupal theme Omega-4, and here's an example of an error that the ghost of guard is causing (this is accessing the Centos server from windows using SFTP):
This command should list all the processes using Linux inotify subsystem on which Guard is based:
$ ps -p `find /proc -name task -prune -o -type l -lname anon_inode:inotify -print 2> /dev/null | cut -d/ -f3`
PID TTY STAT TIME COMMAND
1102 ? Ssl 0:16 evince
3651 ? Ss 0:01 //bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
4071 ? Sl 0:00 /usr/lib/x86_64-linux-gnu/ibus/ibus-gconf
4075 ? Sl 1:08 /usr/lib/x86_64-linux-gnu/ibus/ibus-x11 --kill-daemon
4092 ? Sl 0:18 /usr/lib/ibus-mozc/ibus-engine-mozc --ibus
4468 ? Ssl 188:36 skype
4788 ? S<l 622:27 /usr/bin/pulseaudio --start --log-target=syslog
7102 pts/0 S+ 0:00 inotifywait -r -m -e modify --format %f JavaFXSceneBuilder2.0/
7998 ? Ssl 6:53 gvim
8549 ? Ssl 11:11 /opt/google/chrome/chrome
8597 ? Ssl 307:04 /usr/lib/firefox/firefox
9459 ? Sl 50:05 /usr/lib/firefox/plugin-container /usr/lib/flashplugin-installer/libflashplayer.so -greomni /usr/lib/firefox/omni.ja -appomni /usr/lib/firefox/browser/omni.ja -appdir /usr/lib/firefox/browser 8597 true plugin
16444 ? Ssl 1:31 gvim
16452 ? Ssl 24:39 /home/nodakai/.dropbox-dist/dropbox-lnx.x86_64-2.10.27/dropbox
24514 ? S 0:01 /usr/lib/gvfs/gvfs-gdu-volume-monitor
24527 ? Sl 0:00 /usr/lib/gvfs/gvfs-afc-volume-monitor
32491 ? Sl 11:10 /usr/lib/libreoffice/program/soffice.bin --splash-pipe=5
You might as well install Ruby and Guard again to uninstall them in a proper way.

Unable to stop Webrick launched by "rackup"

I'm developing a Sinatra application and I'm using "rackup" to start Webrick. What should I do to stop it? Now I'm using Ctrl+Z and it seems like it stops. However when I try to start it again it will say that the port is already bound.
I tried it with many ports and each time it started, stopped and then said it was in use when I restarted it again.
How do I solve it?
Ctrl+Z will just "pause" the process, not terminate / kill it.
To truly kill it, find it in the process table and do kill -9 [PID]
like:
ps auxwww | grep ruby
slivu 16244 0.0 0.5 2551140 61220 s020 R+ 1:18AM 0:10.70 ruby app.rb
the second column(16244) is the PID.
The other way is to "catch" the INT signal with Ruby and exit the app explicitly.
in your app:
Signal.trap 'INT' do
Process.kill 9, Process.pid
end
Extending on slivu's reply,
use CTRL+C to kill the process if you are still in the same terminal.
If you are launching it in the background, or want to kill from a different terminal, use
ps aux | grep [r]ackup | awk '{print $2}' | xargs sudo kill -9

kill pid started with gem net-ssh

If you start a command in a remote server with the net/ssh gem, and the command is on a deadlock, how do find the pid of the process running in the remote server and kill it?
Does net/ssh gem support this?
Well, if you can ssh into the remote server, you can use this to get the pid of the process:
# Assuming the command you want to kill is a ruby program.
# If the program is something else, say sparrow mail app, you should replace
# ruby with sparrow below.
ps -ax | grep ruby
And then, perhaps:
kill -9 <pid>

Kill a child process that has detached from the shell

I want to control many different Sinatra apps from a central (Sinatra) app.
The problem I have is no matter which way I exec/spawn/fork the call to start it, I cannot get the pid of the Sinatra server so that I can kill (:int) it?
This is due to my shell exec string, which contains a few other commands first, so I get the pid of the first.
My command string is like
command = source ~/.profile; rbenv #{ver}; some_env=1234 ruby app.rb
So I get the pid of the sh process of the sourcing command.
The question is, how can I get the pid of the ruby command launched above?
I am currently using spawn, but have tried most others as well, but I don't think that is the problem!?
pid = Process.spawn(command)
pid # => 1234
The ruby app itself starts
$ ps aux
1234 sh -c . ~/.profile; shell_script
4567 shell_script
I want to know 4567!?
There's no easy way of getting your '4567', but you should be able to make your process have the same pid as Process.spawn returns.
Try ending your command with an exec rather than a straight call to ruby, i.e.:
source ~/.profile; rbenv #{ver}; export some_env=1234; exec ruby app.rb
you can check whether the process "shell_script" is a child of "sh -c . ~/.profile; shell_script".you can check this through "ps -axgf" command.
if it is a parent then u can use the group id of pid 1234 (get it form the output of ps -axgf) to kill the child with pid 4567 using this command .
kill -9 -1234(assumming 1234 is the group id)

Resources