Ruby on IIS with FastCGI

Showing 1-7 of 7 messages
Ruby on IIS with FastCGI Luis Lavena 1/19/11 5:24 PM
I already emailed about FreeTDS, now IIS:

http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx

If we manage get Rails easily working with IIS Express, running Rails
in corporate IIS 7 could be easy.

IIS Express includes FastCGI. I know is not Passenger or mongrel, but
is something. Is old, but doesn't mean is bad ;-)

Getting fastcgi compiled and getting Ruby FastCGI extension working
with MinGW is not complicated, just need to be done.

Please avoid any existing binary on this subject (roriis, rubyforiis I
believe) since their binaries are old, compiled with Visual Studio and
highly unlikely remain maintained.

Since setting a Rails application with IIS can't be automated (I
believe, highly likely I'm wrong), I think once fastcgi and ruby fcgi
is solved, perhaps someone can write a tutorial?

Ok, leaving this now for you guys to explore, I put the building blocks ;-)

Cheers,
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

Re: Ruby on IIS with FastCGI Brian Hogan 1/19/11 6:48 PM
I worked with the IIS folks in 2007 on the FastCGI support they have. Short version is that it doesn't really work well for us. Or at least it didn't with what we tried then,

The IronRuby guys have Rails working with IIS using Rack. Is there something we can use there?

It's been a long time since I attempted this, but what the Java solutions do is use an ISAPI filter to intercept requests to IIS and kick them over to a backend. I have successfully used Helicon's ISAPI_REWRITE plugin to kick these over to Mongrel as a service. We use this in production now, but I don't think the mongrel_service stuff works anymore so we're on a very old version.

I wrote about this setup in "Deploying Rails Applications" from PragProg.
Re: Ruby on IIS with FastCGI Luis Lavena 1/20/11 4:15 AM
On Wed, Jan 19, 2011 at 11:48 PM, Brian Hogan <bph...@gmail.com> wrote:
> I worked with the IIS folks in 2007 on the FastCGI support they have. Short
> version is that it doesn't really work well for us. Or at least it didn't
> with what we tried then,
>
> The IronRuby guys have Rails working with IIS using Rack. Is there something
> we can use there?

AFAIK Is Managed Code, we can't use it.

It need to be an extension that is either C++ or something and talks
to Rack, that will be great.

The problem is also starting the application. Seems this needs to be
something like passenger where the extension loads the application.

Then we have things like manage how many processes, etc.

I will try give a whirl to FastCGI express this weekend and see how it goes.

> It's been a long time since I attempted this, but what the Java solutions do
> is use an ISAPI filter to intercept requests to IIS and kick them over to a
> backend. I have successfully used Helicon's ISAPI_REWRITE plugin to kick
> these over to Mongrel as a service. We use this in production now, but I
> don't think the mongrel_service stuff works anymore so we're on a very old
> version.

ISAPI filters do not work or are present in latest IIS.

mongrel_service does work, what doesn't work is Rails.

We can turn mongrel service into thin service pretty easily, and thing
works with Rails 3.

--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

Re: Ruby on IIS with FastCGI Wayne E. Seguin 1/20/11 4:26 AM
If we can build a Rack extension to IIS that would be a HUGE win for the community.--
  ~Wayne

Wayne E. Seguin
wayneeseguin on irc.freenode.net

Re: Ruby on IIS with FastCGI Wayne E. Seguin 1/20/11 5:39 AM


On Wed, Jan 19, 2011 at 8:24 PM, Luis Lavena <luisl...@gmail.com> wrote:
I already emailed about FreeTDS, now IIS:

http://weblogs.asp.net/scottgu/archive/2010/06/28/introducing-iis-express.aspx

If we manage get Rails easily working with IIS Express, running Rails
in corporate IIS 7 could be easy.

IIS Express includes FastCGI. I know is not Passenger or mongrel, but
is something. Is old, but doesn't mean is bad ;-)

Getting fastcgi compiled and getting Ruby FastCGI extension working
with MinGW is not complicated, just need to be done.
 

If I am reading this correctly we can connect via Rack as it looks like it supports FastCGI?


Perhaps this is doable sooner rather than later...

Re: Ruby on IIS with FastCGI Brian Hogan 1/20/11 6:26 AM

ISAPI filters do not work or are present in latest IIS.

We run IIS 7 in prod with ISAPI filters. Which IIS are you talking about?  

mongrel_service does work, what doesn't work is Rails. 

We can turn mongrel service into thin service pretty easily, and thing
works with Rails 3.

This is a great idea, but you still want to be able to pass requests on from IIS. And occasionally you will want to do reverse proxying and URL rewriting. I had a Rails 2 plugin for that purpose because a few places I worked at wanted apps mounted at  /foo/bar/baz instead of /foo and Rails didn't like that very much.  I stopped maintaining the plugin once I couldn't get Rails 3 apps running on our servers.
 
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

Re: Ruby on IIS with FastCGI Luis Lavena 1/20/11 7:29 AM
On Thu, Jan 20, 2011 at 10:39 AM, Wayne E. Seguin
<waynee...@gmail.com> wrote:
>
> If I am reading this correctly we can connect via Rack as it looks like it
> supports FastCGI?

Yes, it works, dunno how you set it up, but I know it works :-)

Now, did some test:

fcgi 2.4.0, latest release do not compile with DevKit (extract,
configure, make process)

It contains hardcoded "SYSTEM" in configure (unix). Changed to win32,
and it failed:

g++ -DHAVE_CONFIG_H -I. -I. -I.. -I../include -g -O2 -c fcgio.cpp -MT
fcgio.lo -MD -MP -MF .deps/fcgio.TPlo  -DDLL_EXPORT -DPIC -o
.libs/fcgio.lo
fcgio.cpp: In destructor 'virtual fcgi_streambuf::~fcgi_streambuf()':
fcgio.cpp:50:14: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::overflow(int)':
fcgio.cpp:70:72: error: 'EOF' was not declared in this scope
fcgio.cpp:75:14: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::sync()':
fcgio.cpp:86:18: error: 'EOF' was not declared in this scope
fcgio.cpp:87:41: error: 'EOF' was not declared in this scope
fcgio.cpp: In member function 'virtual int fcgi_streambuf::underflow()':
fcgio.cpp:107:35: error: 'EOF' was not declared in this scope
make[2]: *** [fcgio.lo] Error 1
make[2]: Leaving directory
`/c/Users/Luis/Projects/_sandbox/fastcgi/fcgi-2.4.0/libfcgi'

Due missing #include <cstdio> in fcgio.h

Then, it failed due export symbols in the link library, quite common
for shared/static libraries and Windows (dllexport and dllimport), no
matter if I used static or shared library.

This is something I encountered in several libraries like libssh2, but
can{t find the link to libssh2-devel where I discussed this :-(

So, replaced the whole DLLAPI definition fcgi had with this:

#ifdef _WIN32
#  ifdef DLL_EXPORT
#    define DLLAPI         __declspec(dllexport)
#  else
#    ifdef DLL_IMPORT
#      define DLLAPI       extern __declspec(dllimport)
#    endif
#  endif
#endif
#ifndef DLLAPI
#  define DLLAPI           extern
#endif

As documented by autoconf.

http://sourceware.org/autobook/autobook/autobook_255.html
http://sourceware.org/autobook/autobook/autobook_254.html#SEC254

Now is only complaining of missing libraries:

../libfcgi/.libs/libfcgi.a(libfcgi_la-os_win32.o): In function `OS_SetFlags':
c:\Users\Luis\Projects\_sandbox\fastcgi\fcgi-2.4.0\libfcgi/os_win32.c:1873:
undefined reference to `ioctlsocket@12'
c:\Users\Luis\Projects\_sandbox\fastcgi\fcgi-2.4.0\libfcgi/os_win32.c:1875:
undefined reference to `WSAGetLastError@0'
../libfcgi/.libs/libfcgi.a(libfcgi_la-os_win32.o): In function `OS_LibShutdown':
c:\Users\Luis\Projects\_sandbox\fastcgi\fcgi-2.4.0\libfcgi/os_win32.c:585:
undefined reference to `WSACleanup@0'

It needs ws2_32 linking and some other...

Not enough time to hack on this so:

https://github.com/luislavena/fcgi

Steps:

> devkitvars.bat
> git clone git://github.com/luislavena/fcgi.git
> cd fcgi
> sh -c "autonconf"
> mkdir build
> cd build
> sh ../configure --disable-shared --enable-static
> make

[hack]

Cheers,


--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry