Forum: Ruby on Rails rails.vim -> killing the server?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-03 13:48
In macvim, I started the server like this:

:Rserver

But I'm trying to debug something in my application, and I want to use
puts to output a message in the server's output window.  Before
installing macvim and rails.vim, I kept a Terminal window open where I
started the server using:

/myapp$ruby script/server

and the server(Mongrel) would log output to the window about what it was
doing.  Then if I used puts in my program, the output would go to the
server window, and I could examine it.

I want to set up a separate Terminal window for the sever like before,
so I can examine the server's output, but I can't figure out how to kill
the server I started in macvim/rails.vim.  If I try to start a server in
Terminal, I get an "address already in use" error:

/myap$ ruby script/server
=> Booting Mongrel
=> Rails 2.3.2 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/usr/local/lib/ruby/gems/1.8/gems/mongrel-1.1.5/lib/mongrel/tcphack.rb:12:in
`initialize_without_backlog': Address already in use - bind(2)
(Errno::EADDRINUSE)

I tried closing every macvim and Terminal window, quitting the macvim
and Terminal programs, and shutting down Firefox, then relaunching
Terminal.  But I when I open a Terminal window and try to start the
server using:

/myapp$ ruby script/server

I get the same error message: "address already in use".  Here is what
the top command produces:

$ top
-----------
  PID COMMAND      %CPU   TIME   #TH #PRTS #MREGS RPRVT  RSHRD  RSIZE
VSIZE
 1200 top          6.9%  0:06.71   1    18    20   544K   428K  1.01M
27.0M
 1195 bash         0.0%  0:00.01   1    14    16   220K   824K   804K
27.1M
 1194 login        0.0%  0:00.00   1    16    40   172K   508K   660K
26.9M
 1192 Terminal     1.0%  0:02.26   4    90   142  1.99M  10.7M+ 8.01M+
231M+
 1167 ruby         0.1%  0:04.17   2    10   132  20.3M  2.59M  21.7M
50.4M
 1141 lookupd      0.0%  0:00.19   2    34    38   464K  1.02M  1.26M
28.5M
 1138 MDCPdUSB     0.0%  0:00.01   1    23    20   312K   772K   996K
27.1M
 1136 pppd         0.0%  0:00.04   1    26    30   332K  1.02M  1.43M
27.4M
 1130 mdimport     0.0%  0:00.33   4    65    56  1.23M  3.67M  4.08M
39.7M
  357 Preview      0.0%  0:00.36   1    69   118  1.73M  7.95M  6.29M
225M
  217 AppleSpell   0.0%  0:01.45   1    44    34   700K  3.18M  2.37M
37.8M
  214 Safari       0.0% 29:11.21   9   298  3311   407M  52.6M   323M
700M
  207 automount    0.0%  0:00.01   3    39    30   308K   924K  1.09M
28.7M
  203 automount    0.0%  0:00.01   3    41    34   316K   956K  1.13M
29.0M
  200 rpc.lockd    0.0%  0:00.00   1    10    17   124K   452K   220K
26.7M
  191 nfsiod       0.0%  0:00.00   5    30    24   124K   352K   208K
28.6M

-------------

That ruby process looks suspicious.  I don't know what that is.

Currently, the only way that I can kill the server is to reboot my
computer, which is not very convenient.
53be54e5db4dc58e4980db5a8255621b?d=identicon&s=25 Harold (Guest)
on 2009-05-03 17:28
(Received via mailing list)
I don't have a mac, but this is pure unix and should be applicable to
you as well.

Get the PID of the server process and kill it manually:
$ ps aux |grep ruby
hgimenez 30736 24.8  1.6  48772 33252 pts/0    Sl+  11:22   0:03 ruby
script/server
hgimenez 30802  0.0  0.0   4204   704 pts/1    S+   11:22   0:00 grep
ruby
$

In my case, you want to kill process 30736. Same thing could be
achieved with pgrep:

$ pgrep ruby
30736
$

But if you have many ruby processes going on, you won't know which one
to kill.

Now that you have the process ID, kill it:

$ kill 30736
$

The server should be gone, and you should be able to start the server
again on the same port:
$ ps auxwww |grep ruby
$ script/server [...]

Hope that helps,
-Harold
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-03 17:59
Harold wrote:
> I don't have a mac, but this is pure unix and should be applicable to
> you as well.
>
> Get the PID of the server process and kill it manually:
> $ ps aux |grep ruby
> hgimenez 30736 24.8  1.6  48772 33252 pts/0    Sl+  11:22   0:03 ruby
> script/server
> hgimenez 30802  0.0  0.0   4204   704 pts/1    S+   11:22   0:00 grep
> ruby
> $
>
> In my case, you want to kill process 30736. Same thing could be
> achieved with pgrep:
>
> $ pgrep ruby
> 30736
> $
>
> But if you have many ruby processes going on, you won't know which one
> to kill.
>
> Now that you have the process ID, kill it:
>
> $ kill 30736
> $
>
> The server should be gone, and you should be able to start the server
> again on the same port:
> $ ps auxwww |grep ruby
> $ script/server [...]
>
> Hope that helps,
> -Harold

Yes, I'm aware that you can do that --although I don't have enough unix
experience to kill processes I'm not sure about.

I was hoping that there was a simple command in rails.vim that I could
use.  I pored over the rails.vim help, but I can't find anything.  I'm
certainly not going to run the server in rails.vim ever gain unless I
can find an easy way to kill it after I've started it.
53be54e5db4dc58e4980db5a8255621b?d=identicon&s=25 Harold (Guest)
on 2009-05-03 18:22
(Received via mailing list)
The issue is that rails.vim starts the server with the --daemon
option, so it just sits there in the background. :Rserver! will try to
kill it first, and restart it from vim, but I'd just use the terminal
for controlling your server during development.
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-04 00:19
Harold wrote:
> The issue is that rails.vim starts the server with the --daemon
> option, so it just sits there in the background. :Rserver! will try to
> kill it first, and restart it from vim, but I'd just use the terminal
> for controlling your server during development.

Ok.  Will do.
Af2ce6689213fdb78913a9662b18da6b?d=identicon&s=25 Rick Lloyd (ricklloyd)
on 2009-05-04 00:48
(Received via mailing list)
I don't understand, when I issue the rails.vim command ":Rscript
server thin" the thin server is started in the current VIM window with
output visible.  The behavior is identical to that in a terminal
window which has has the command "script/server thin" issued.

i.e. I can see the output from the thin server as if I were tailing
the logfile and I can stop the thin server by issuing a Ctrl-C in the
VIM window (vimdoh?).

Doesn't this accomplish what you're after?
C59cae5d861c9f84f6ead08e445745a0?d=identicon&s=25 冷血儿 (Guest)
on 2009-05-04 01:44
(Received via mailing list)
You can kill processes with name:sudo killall ruby
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-04 03:04
Rick Lloyd wrote:
> I don't understand, when I issue the rails.vim command
> ":Rscript server thin"
> the thin server is started in the current VIM window with
> output visible.

What's a 'thin server'?   As I mentioned in my op, this is what I had
been doing in Terminal:

/myapp$ ruby script/server

The window then showed the log output from the server.  I could kill the
sever by hitting Ctrl+C.

The rails.vim help says this:

:Rserver {options}  Launches script/server {options} in the background.
      On win32, this means |!start|.  On other systems, this
      uses the --daemon option.


/myapp$ ruby script/server -h

Usage: server [options]
    -p, --port=port                  Runs Rails on the specified port.
                                     Default: 3000
    -b, --binding=ip                 Binds Rails to the specified ip.
                                     Default: 0.0.0.0
    -c, --config=file                Use custom rackup configuration
file
    -d, --daemon                     Make server run as a Daemon.
    -u, --debugger                   Enable ruby-debugging for the
server.
    -e, --environment=name           Specifies the environment to run
this server under (test/development/production).
                                     Default: development
    -P, --path=/path                 Runs Rails app mounted at a
specific path.
                                     Default: /

    -h, --help                       Show this help message.

Nothing about 'thin' in there.


> The behavior is identical to that in a terminal
> window which has has the command "script/server thin" issued.
>
> i.e. I can see the output from the thin server as if I were tailing
> the logfile and I can stop the thin server by issuing a Ctrl-C in the
> VIM window (vimdoh?).
>
> Doesn't this accomplish what you're after?

I don't know.  I'll have to try it the next time I am ready to logout.
53be54e5db4dc58e4980db5a8255621b?d=identicon&s=25 Harold A. Giménez Ch. (Guest)
on 2009-05-04 03:20
(Received via mailing list)
Thin is just another webserver for ruby apps (mongrel, webrick, thin,
...)
http://code.macournoyer.com/thin/

You could've done :Rscript server to accomplish the same Rick Lloyd is
describing (which would default to whatever server you're using).

On Sun, May 3, 2009 at 9:04 PM, 7stud --
Af2ce6689213fdb78913a9662b18da6b?d=identicon&s=25 Rick Lloyd (ricklloyd)
on 2009-05-04 04:53
(Received via mailing list)
or to avoid trusting the default just go ":Rscript server mongrel".
If I'm not mistaken, you're probably using ":Rserver" which
automatically starts the server in the background.

On May 3, 3:19 pm, Harold A. Giménez Ch. <harold.gime...@gmail.com>
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-04 14:36
Rick Lloyd wrote:
> or to avoid trusting the default just go ":Rscript server mongrel".
> If I'm not mistaken, you're probably using ":Rserver" which
> automatically starts the server in the background.
>

Ok. I get it now.  This is what I need to do in rails.vim:

:Rscript server

which is equivalent to the following in a terminal window:

/myapp$ ruby script/server

Then to kill the server in either window, I can hit Ctrl+C.

Thanks.

Why is :Rserver useful?  I hate that command.
Af2ce6689213fdb78913a9662b18da6b?d=identicon&s=25 Rick Lloyd (ricklloyd)
on 2009-05-05 00:55
(Received via mailing list)
>
> Why is :Rserver useful?  I hate that command.
>
Does seem kind of like belts and suspenders doesn't it?

I've actually found that ":Rserver thin" does not work in my
environment.   Thin is started in the background and then silently
dies.  However, ":!thin -d start" is the bee's knees.

You might take a look at ":Rlog" to view your logfile in macvim.  It
does the magic# -> color mapping so the logfile looks pretty.  There
seems to be some delay in the logfile update.

I'm not sure I'll stay with this for my development, I think that the
rails package on aquamacs is a little more intuitive but that's a
really subjective assessment.
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-05 06:24
Rick Lloyd wrote:
>>
>> Why is :Rserver useful? �I hate that command.
>>
> Does seem kind of like belts and suspenders doesn't it?
>
> I've actually found that ":Rserver thin" does not work in my
> environment.   Thin is started in the background and then silently
> dies.  However, ":!thin -d start" is the bee's knees.
>
> You might take a look at ":Rlog" to view your logfile in macvim.  It
> does the magic# -> color mapping so the logfile looks pretty.  There
> seems to be some delay in the logfile update.
>
> I'm not sure I'll stay with this for my development, I think that the
> rails package on aquamacs is a little more intuitive but that's a
> really subjective assessment.

Ok, I'll try :Rlog.

Do you use macvim?  I have a problem with regular vim now.  When I open
a file in regular vim, I get colored blocks around all the text, which
makes it almost impossible to read.  Is there some setting that I can
add to .vimrc to prevent regular vim from colorizing the text?

Thanks.
68fc4cc5cb2cab91c0084e41c003a890?d=identicon&s=25 Dave Sherratt (Guest)
on 2009-05-06 22:02
(Received via mailing list)
If you actually wanted to do this you can also use grep which may be
easier to achieve the results

Sent from my iPod

On May 3, 2009, at 11:19 PM, 7stud -- <rails-mailing-list@andreas-
54404bcac0f45bf1c8e8b827cd9bb709?d=identicon&s=25 7stud -- (7stud)
on 2009-05-06 23:08
7stud -- wrote:
> Rick Lloyd wrote:
>>>
>>> Why is :Rserver useful? �I hate that command.
>>>
>> Does seem kind of like belts and suspenders doesn't it?
>>
>> I've actually found that ":Rserver thin" does not work in my
>> environment.   Thin is started in the background and then silently
>> dies.  However, ":!thin -d start" is the bee's knees.
>>
>> You might take a look at ":Rlog" to view your logfile in macvim.  It
>> does the magic# -> color mapping so the logfile looks pretty.  There
>> seems to be some delay in the logfile update.
>>
>> I'm not sure I'll stay with this for my development, I think that the
>> rails package on aquamacs is a little more intuitive but that's a
>> really subjective assessment.
>
> Ok, I'll try :Rlog.
>

Ok, I've had it.  I had some problems closing the Rlog window, and then
ONCE AGAIN, I could not kill the server.  The other macvim window
containing the server completely froze up.  It was unresponsive to
Ctrl+C, and I couldn't even kill the window.  I had to quit macvim, and
then once again I had to reboot to be able to start a server again.

As a result, I am NEVER using macvim/rails.vim to start a server again!
Af2ce6689213fdb78913a9662b18da6b?d=identicon&s=25 Rick Lloyd (ricklloyd)
on 2009-05-07 06:30
(Received via mailing list)
Yes, it can be frustrating.  I've been using vi since 1978 and emacs
since 1979.  My experience includes using sed to diddle system files
on an init0 system in order to bring it up to init4.  So I kind of
have the functional forms of several editors hard wired in.  I've
actually had nightmares that I've tried to exit by dream chanting
ControlX ControlC.  I know, it's a sad statement on my sense of how
reality works.

Anyway, one of the environments I use is:

MacVim 7.2 stable 1.2 (33.3) on
OSX 10.5.6

I've found that setting MacVim->Preferences->General->"Launch vim
processes in a login shell" is worth setting just to avoid surprises
re which ruby/rails/gem is being used.  I'm running ksh (but that's
just a personal preference) and my primary environment set to
Ruby1.9.2dev/Rails2.3.2 with Ruby1.8.[67] and Rails2.2.[0-2] available
as mix and match alternates.

Regarding your :Rserver problem with mongrel, the simplest way to kill
a process (for example, my server thin started in MacVim with
":Rserver thin") is to use the ps command to find it followed by the
kill command to do the snuff.  These are both unix commands so, in a
terminal window:

$ ps -elf | grep thin (or mongrel in your
case)
  501  5127     1       0   0  31  0   111016  32164 -      S
5f9b540 ??         2:02.41 ruby -C /Users/rick/vimtest script/server
thin -d                  0:59.80
  501 12872  6637    4002   0  31  0    66152      8 -      R+
5f9cb70 ttys000    0:00.00 grep
thin                                                          0:00.00

$ kill -9 5127

Did you see where the 5127 came from?

Another thing to understand about vim, any process (or edit session
for that matter) that starts in the foreground can be easily killed by
using the quit command ":q" or quit with extreme predjudice ":q!".  If
you have more than one vim frame in the current window the :q will
leave the window displaying the other frame - unless the one you
killed was the initial frame for that window.  I know, very confusing.

Here's a suggestion, either:

  get in the habit of grabbing a new window for each command or edit
session - that way you won't lose anything precious when your window
disappears

or:

  use the File->New Tab menu before issuing your new command - that
way your window will have multiple, browser-like tabs, that can be
independantly killed.

On a mac, you should never have to reboot to clean out a hung
application.  Check out the menu sequence "Apple->Force Quit" for a
point and click variation on the unix "kill -9 ...".  Of course it
won't work for applications started in the background (ala :Rserver)
but for wedged browsers et al it's the cat's pajamas.

Don't get discouraged - keep trying until you find an editor that
you're comfortable with, here are two others that I think are worth a
look.  They both have the benefit of context sensitive formatting
(color and autoindent) which I find very helpful when I'm looking for
the missing magic character.  They also all have the benefits of being
free and portable - although you might need to push a unix environment
onto a windoz box.

Aquamacs - a port of GnuEmacs to the mac that originates in New
Zealand (go conchords).  I like this a lot with the emacs-rails
package installed.  Like I said above, I'm actually way older than
emacs and have been using it since it was temacs so I'm kind of past
the learning curve.

NetBeans - from Sun.  Definitely worth a try - install the minimal
Ruby/Rails version only, unless you also need to do development in
any  of the other supported languages.  Does a lot of stuff, some of
it only almost.  Development continues with an active support group.
9a407fed25defc3fe5935d286dd30586?d=identicon&s=25 Gordon Mccreight (gmccreight)
on 2009-08-19 23:36
I bumped into this page while looking for the same answer: namely, how
do you stop the server when using rails.vim.

Since this thread didn't help, I looked into the source code for
rails.vim

The answer is (notice the minus after the !)
:Rserver!-

Without the minus it will kill, then restart the server.  With the
minus, it will just kill the server.

I decided I'd update this thread in case anyone ends up here in search
of the solution.
B1f60d51852944d0c497955eb7d09889?d=identicon&s=25 Philip C. (philip_c)
on 2011-03-22 20:22
I have found that adding thin to my Gemfile allows me to successfully

:Rserver! thin

and

:Rserver!-
D7e150e675abb80df7659fe14e7ac0a0?d=identicon&s=25 Kedar Mhaswade (kedarmhaswade)
on 2011-05-15 15:47
Gordon Mccreight wrote in post #844159:
> I bumped into this page while looking for the same answer: namely, how
> do you stop the server when using rails.vim.
>
> Since this thread didn't help, I looked into the source code for
> rails.vim
>
> The answer is (notice the minus after the !)
> :Rserver!-
>
> Without the minus it will kill, then restart the server.  With the
> minus, it will just kill the server.
>
> I decided I'd update this thread in case anyone ends up here in search
> of the solution.

Thank you, Gordon. Your response should be highlighted as the summary of
this thread!

Regards,
Kedar
This topic is locked and can not be replied to.