rails.vim -> killing the server?

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

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

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.

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.

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?

You can kill processes with name:

sudo killall ruby

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.

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).

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.

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.

If you actually wanted to do this you can also use grep which may be
easier to achieve the results

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!

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.

I have found that adding thin to my Gemfile allows me to successfully

:Rserver! thin

and

:Rserver!-

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