Master ruby with us

Archive for January, 2007


Posted by firstruby on January 5, 2007

Getting Started

The easiest way to get started with Mongrel is to install it via RubyGems and then run a Ruby on Rails application. You can do this easily:

               gem install win32-service (pick the most recent one)
               gem install mongrel (pick the win32 pre-built)

Win32 Support

Win32 is fully supported by Mongrel with services and CPU affinity support.

The main thing with Win32 support is that there is no fork API for Ruby, so you have to use the services features to get persistent servers running. You can get this services support by doing:

              gem install mongrel_service

And then just run mongrel_rails to see what services:: commands are available.

Running The Service

After you do the gem install, find a Rails application you want to run and do:

$ mongrel_rails service::install -N myapp \\ 
       -c c:mypathtomyapp -p 4000 -e production 
       $ mongrel_rails service::start -N myapp

Now hit the port and poof, works (or should).

The application will stop if you use:

$ mongrel_rails service::stop -N myapp

NOTE: Stop reports an exception but does stop the service.

Now the really great thing is that you can just do all this from the Services control panel like your Rails application is a regular Windows service.

Even works in development mode, which is pretty nice.

Making you Service autostart with Windows

By default, the new Mongrel service get installed to be run manually, using Mongrel’s commands or the Service Manager. You could tweak it to start automatically when Windows start, just use the Service Control commandline tool:

$ sc config myapp start=auto

Also, you can configure the services that are neede to make it work, like database support:

$ sc config myapp start=auto dependency=MySql

CPU Affinity

Mongrel’s win32 support actually is able to set the CPU affinity of a running Mongrel service. This is pretty neat since it means if you’re running a fancy SMP machine or a dual core that pretends to be SMP, then you can force Mongrel onto one of them and get a nice little boost.

It’s pretty easy to use, just pass the -u or—cpu option to the install command and give a CPU of 1-X. That means if you have 4 CPUs and you want Mongrel on #4 then do:

$ mongrel_rails service::install -N myapp 
       -c c:mypathtomyapp -p 4000 -e production -u 4

Pretty much the same command, just one more option and you’re done.

Posted in Blogroll, firstruby, Useful Links | Leave a Comment »