Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

On my Linux server I ran:

sudo thin start -p 80 -d

Now I'd like to restart the sever. The trouble is, I can't seem to get the old process to kill it. I tried:

netstat -anp

But what I see on port 80 is this:

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      -         

So, it didn't give me a PID to kill...

I tried pgrep -l thin but that gave me nothing. Meanwhile pgrep -l ruby gives me like 6 processes running. I don't really understand why multiple ruby threads would be running, or which one I need to kill...

How do I kill / restart the thin daemon?

share|improve this question
    
use sudo before netstat. –  gertvdijk Dec 15 '12 at 1:43
    
I would start the process of debugging by not having the thin daemonized. So don't use the -d option. Before doing that, note the processes running, run your thin application, and take another inventory of the processes running. This is Ruby so it is not surprising that you see Ruby processes. Check the PIDS on those processes and you will see which one is the parent and which are the children. –  vgoff Dec 15 '12 at 1:49
    
Please let us know if you ever got this sorted out! –  Michael Hampton May 20 '13 at 3:27

2 Answers 2

thin is a Ruby gem, so it only makes sense that the Ruby interpreter would be running it.

A typical invocation of thin would be:

bundle exec rails server thin -p $PORT -e $RACK_ENV

In the process list, from the ps command, this appears something like:

 6870 pts/3    Rl+    0:01 /usr/bin/ruby script/rails server thin -p 80 -e production

When using pgrep, by default it only matches against the command name (i.e. ruby). This won't match when the pattern you're searching for appears in the arguments. For this, you need to use the -f option as well:

pgrep -l -f thin

The return then appears like this:

6870 /usr/bin/ruby script/rails server thin -p 80 -e production

And voila, there is the process you're looking for.

share|improve this answer

Running netstat -tulpn as root will give you the PID in the output.

[root@hostname ~]# netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      3738/nrpe           
tcp        0      0 127.0.0.1:8005              0.0.0.0:*                   LISTEN      12747/java          
tcp        0      0 127.0.0.1:199               0.0.0.0:*                   LISTEN      3273/snmpd          
tcp        0      0 127.0.0.1:5000              0.0.0.0:*                   LISTEN      30110/python        
tcp        0      0 0.0.0.0:8009                0.0.0.0:*                   LISTEN      12747/java          
tcp        0      0 0.0.0.0:8649                0.0.0.0:*                   LISTEN      19770/gmond         
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      1656/mysqld         
tcp        0      0 0.0.0.0:8651                0.0.0.0:*                   LISTEN      19794/gmetad        
tcp        0      0 0.0.0.0:8652                0.0.0.0:*                   LISTEN      19794/gmetad        
tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN      12747/java          
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1914/httpd          
tcp        0      0 127.0.0.1:53                0.0.0.0:*                   LISTEN      3885/dnsmasq        
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      13549/sshd          
tcp        0      0 127.0.0.1:5432              0.0.0.0:*                   LISTEN      12403/postgres      
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      15834/master        
udp        0      0 0.0.0.0:40462               0.0.0.0:*                               3862/avahi-daemon   
udp        0      0 0.0.0.0:161                 0.0.0.0:*                               3273/snmpd          
udp        0      0 127.0.0.1:53                0.0.0.0:*                               3885/dnsmasq        
udp        0      0 10.182.10.5:8649            0.0.0.0:*                               19770/gmond         
udp        0      0 0.0.0.0:5353                0.0.0.0:*                               3862/avahi-daemon   
udp        0      0 10.182.10.5:123             0.0.0.0:*                               3335/ntpd           
udp        0      0 127.0.0.1:123               0.0.0.0:*                               3335/ntpd           
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               3335/ntpd
share|improve this answer
1  
The key here is running it as root. If you run it as a regular user, you can't get process information. –  Michael Hampton Dec 15 '12 at 4:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.