<document>
  <header>
    <product>resin</product>
    <title>Resin with IIS</title>

    <description>
      <p>For sites requiring the use of IIS, Resin provides a fast servlet
runner, allowing IIS to run servlets and JSP files.</p>

    </description>
  </header>

  <body>

<s1>
      <figure src="iis_srun.gif"/>

      <p>If you have not yet done so, we suggest you
consider the <a href="resin-web-server.xtp">Resin
web server</a> option first, either as a standalone web server or as
a web-tier server load-balancing to Resin app-tier servers.
Resin's Java web server provides management, clustering,
and load-balancing with failover.
</p>
</s1>

    <localtoc/>

<s1 title="Prerequisites and Environment Variables">

<p>Resin requires a 1.5 JDK.  You can download one from Sun and install it.</p>
 
<p>The Control Panel is used to configure two environment variables:</p>
<example>
JAVA_HOME=C:\jdk1.5.0
RESIN_HOME=C:\resin-3.2
</example>
</s1>

<s1 title="Configuring IIS/PWS">

<p>To configure Resin with IIS, you must follow the following steps:</p>
<ol>
<li>Configure IIS/PWS
</li><li>Configure resin.xml
</li><li>Start resin.exe
</li></ol>


<s2 title="ISAPI Filter">

<p>You should run <code>RESIN_HOME/setup.exe</code> to setup your
configuration.  If setup.exe is not used, or it fails, the steps in <a href="#Manual-Configuration">Manual Configuration</a> are necessary.</p>

</s2>

<s2 title="ISAPI Filter Priority">

<p>isapi_srun.dll installs itself as the default priority.  Some users may need
to set the priority to a higher level, e.g. to override IIS's DAV support.
</p>

<example title="resin.ini">
ResinConfigServer localhost 6802
CauchoStatus yes
IISPriority high
</example>

</s2>

<s2 title="Configuring resin.xml">

<p>resin.xml should mirror the configuration of IIS.  In other words, you 
need to configure the document root and any directory aliases.</p>

<p>For many users, the only need to change needed in Resin is to change the
<a config-tag="document-directory"/> attribute from 'webapps/ROOT' to something
like 'C:/inetpub/wwwroot'.  The mapping of url paths from the browser to real
files on the disk must be the same for Resin as they are for IIS. For more
complicated configurations that use mappings in IIS, you'll need to add <a href="webapp-tags.xtp">path-mapping</a> attributes
to match.</p>

<example title="Example: resin.xml" language="xml">
&lt;resin xmlns="http://caucho.com/ns/resin">
&lt;cluster id="">

  &lt;!-- configures the default host, matching any host name --&gt;
  &lt;host id=""&gt;

  &lt;!-- configures the root web-app --&gt;
  &lt;web-app id='/'&gt;
    &lt;root-directory&gt;C:/inetpub/wwwroot&lt;/root-directory&gt;
    &lt;!-- adds xsl to the search path --&gt;
    &lt;class-loader&gt;
      &lt;simple-loader path="$host-root/xsl"/&gt;
    &lt;/class-loader&gt;
  &lt;/web-app&gt;
&lt;/host&gt;

&lt;/cluster&gt;
&lt;/cluster&gt;
</example>

</s2>

<s2 title="Testing the servlet engine">

<p>From a <code>cmd</code> shell run <code>RESIN_HOME/resin.exe</code> to start the
servlet runner.</p>

<example title="Run resin.exe">
C:\&gt; cd %RESIN_HOME%
C:\resin-3.2&gt; resin.exe
</example>

<p>Now browse http://localhost/test.jsp.  You should get a 'file not
found' message.</p>

<p>Create a test file 'd:\inetpub\wwwroot\test.jsp'</p>

<example>
2 + 2 = &lt;%= 2 + 2 %&gt;
</example>

<p>Browse http://localhost/test.jsp again.  You should now get</p>

<results>
2 + 2 = 4
</results>
</s2>

</s1>

<s1 title="Command line arguments">

<p>The following configuration line arguments are recognized by resin.exe.
When command line arguments are used along with <code>-install</code> to
install as a service, the arguments are used each time the service starts.</p>

<deftable>
<tr><th>Argument</th><th>Meaning
</th></tr><tr><td>-verbose</td><td>Write more verbose information to the log file
</td></tr><tr><td>-resin_home &lt;path&gt;</td><td>Sets the location of Resin
</td></tr><tr><td>-java_home &lt;path&gt;</td><td>Specify the JDK location
</td></tr><tr><td>-msjava</td><td>Use Microsoft's JVM
</td></tr><tr><td>-nojit</td><td>Disable JIT compilation to help debugging
</td></tr><tr><td>-classpath &lt;cp&gt;</td><td>Add to the classpath
</td></tr><tr><td>-J&lt;arg&gt;</td><td>Set a Java command line argument, e.g. -J-nojit.
</td></tr><tr><td>-X&lt;arg&gt;</td><td>Set a Java -X command line argument, e.g. -Xms128m.
</td></tr><tr><td>-D&lt;foo=bar&gt;</td><td>Set a Java variable, e.g. -Dresin.home=here.
</td></tr><tr><td>-install</td><td>Install as an NT service
</td></tr><tr><td>-install-as &lt;name&gt;</td><td>Install as an NT service with the specific name.
</td></tr><tr><td>-remove</td><td>Remove as an NT service
</td></tr><tr><td>-remove-as &lt;name&gt;</td><td>Remove as an NT service with the specific name.
</td></tr></deftable>

<s2 title="Memory Configuration">

<p>Memory configuration is part of the JVM's arguments.  For most JVMs,
you can find the full list by starting "java -X".</p>

<deftable title="Memory Configuration">
<tr><th>Argument</th><th>Meaning
</th></tr><tr><td>-Xms&lt;size&gt;</td><td>Initial Java heap size, e.g. -Xms32m
</td></tr><tr><td>-Xmx&lt;size&gt;</td><td>Maximum Java heap size, e.g. -Xmx128m
</td></tr><tr><td>-Xms&lt;size&gt;</td><td>the size of the heap for the young generation
</td></tr></deftable>

<p>See <a href="jvm-tuning.xtp#memory">Performance : JVM Tuning : Memory</a> for more information on JVM memory usage.</p>

</s2>

</s1>

<s1 title="Deploying as an NT Service">

<p>Once you're comfortable with using Resin with IIS, you can install it
as an NT service.  As a service, Resin will automatically start when
NT reboots.  The service will also automatically restart Resin if it
unexpectedly exits.</p>

<p>To install the service, use</p>

<example>
win&gt; resin-3.2.x/resin.exe -install
</example>

<p>To remove the service, use</p>

<example>
win&gt; resin-3.2.x/resin.exe -remove
</example>

<p>You will either need to reboot the machine or start the service
from the Control&#160;Panel/Services panel to start the server.  On a
machine reboot, NT will automatically start the servlet runner.</p><p/>

<note>There is a bug in many JDKs which cause the JDK to exit when the
administrator logs out.  JDK 1.4 and later can avoid that bug if the
JDK is started with -Xrs. </note>

<example>
win&gt; resin-3.2.x/resin.exe -install -Xrs
</example>

</s1>

<s1 name="balance" title="Load Balancing">

<p>With Resin, you can distribute requests to multiple machines.  All
requests with the same session will go to the same host.  In addition, if one
host goes down, the IIS filter will send the request to the next
available machine.</p>

<p>In addition, you can specify backup machines.  The backup only will serve
requests if all primaries are down.</p>

<p>See the <a href="cluster.xtp">Resin config</a> section for more
details.</p>

<example title="resin.xml">
&lt;resin xmlns="http://caucho.com/ns/resin"&gt;
&lt;cluster id="app-tier"&gt;

    &lt;server id="a" address="host1" port="6802" index="1"/&gt;
    &lt;server id="b" address="host2" port="6802" index="2"/&gt;
    &lt;server id="c" address="backup" port="6802" index="3" backup="true"/&gt;
  ...
&lt;/cluster&gt;
&lt;/resin&gt;
</example>

<example title="installing multiple servlet runners as services">
win&gt; resin-3.2.x/resin.exe -install-as "Resin-A" -server a -Xrs
win&gt; resin-3.2.x/resin.exe -install-as "Resin-B" -server b -Xrs
win&gt; resin-3.2.x/resin.exe -install-as "Resin-C" -server c -Xrs
</example>
</s1>

<s1 title="Manual Configuration">

<p>Experts may want to configure Resin/IIS by hand instead
of using the setup program.  The steps involved are:</p>

<ol>
<li>Make sure resin.exe works
</li><li>Copy isapi_srun.dll to the IIS scripts directory, <var>d:\inetpub\scripts</var>.
You may need to run <var>net stop w3svc</var> to get permission to overwrite the file.
</li><li>If you have a virtual site (virtual hosts), you must configure IIS to have
the virtual directory <var>/scripts</var> point to <var>d:\inetpub\scripts</var> for
each virtual site.

</li><li>(optional) Create a resin.ini in <var>d:\inetpub\scripts</var> pointing to the ResinConfigServer
</li><li>(optional) Add a "CauchoStatus yes" line to the resin.ini for debugging
</li><li>Configure IIS to load isapi_srun.dll as an ISAPI filter.
</li><li>Restart IIS (control panel/services) or <var>net stop w3svc</var> followed
by <var>net start w3svc</var>.
</li><li>Browse /servlet/Hello and /foo.jsp.
You should see a "cannot connect" error.
</li><li>Start resin.exe
</li><li>Browse /servlet/Hello and /foo.jsp.  You should now see the servlet.
</li></ol>

<p>Copying isapi_srun.dll to <var>inetpub/scripts</var> directory is relatively
straightforward.  If you're upgrading to a new version of Resin, you
may need to stop IIS (control panel/services) to get permission to
overwrite isapi_srun.dll.</p>

<p>The resin.ini is an optional file in <var>inetpub/scripts</var> to
override the automatic registry $RESIN_HOME/conf/resin.xml configuration
file.  If you only have one Resin server, you should not create a resin.ini
and let isapi_srun.dll use the registry value set by the setup.exe program.</p>

<p>resin.ini is only needed if you have multiple Resin configuration
files for different IIS virtual hosts.</p>

<p>The resin.ini should contain the following line:</p>
<example>
ResinConfigServer localhost 6802
</example>

<p>You can change the host from <var>localhost</var> to a backend server.
You can also add multiple <var>ResinConfigServer</var> items to cluster the
configuration.</p>

<p>For debugging, you can add a "CauchoStatus yes" line to the resin.ini:</p>

<example>
ResinConfigServer localhost 6802
CauchoStatus yes
</example>

<p>For security purposes, the default value of CauchoStatus is "no" when
you have a resin.ini.</p>

<p>Adding an ISAPI filter is accomplished in the IIS manager.</p>

<s2 title="IIS and Resin on different machines">

<p>When Resin and IIS are on different machines, you'll change
the ResinConfigServer from "localhost" to the IP address of the
Resin server.</p>

<example>
ResinConfigServer 192.168.0.10 6802
CauchoStatus yes
</example>

</s2>

</s1>

<s1 title="Virtual Sites (Virtual Hosts)">

<p>If IIS is managing multiple virtual sites (everyone else calls them virtual
hosts), then you need to configure IIS to use the isapi_srun.dll filter for
each virtual site.  Configure IIS to have the virtual directory <var>/scripts</var>
for each virtual site point to <var>d:\inetpub\scripts</var>, so that each virtual site uses the isapiu_srun.dll.</p>

<p>Resin is configured to recognize virtual hosts with the <var>id</var> attribute
of <a config-tag="host"/>. </p>

<example title="resin.xml with virtual hosts">
&lt;resin xmlns="http://caucho.com/ns/resin"&gt;
  ...
  &lt;server&gt;
    ...

    &lt;host id="foo.com"&gt;
      ...
    &lt;/host&gt;

    &lt;host id="bar.com"&gt;
      ...
    &lt;/host&gt;

    &lt;host id="baz.com"&gt;
      ...
    &lt;/host&gt;

  &lt;/server&gt;
&lt;/resin&gt;
</example>

<p>Resin recognizes which host to use by examing the url.  With the above
example, a url of <code>http://foo.com/some/path</code> will use host
<code>id="foo.com"</code> and a url of <code>http://bar.com/some/path</code>
will use host <code>id="bar.com"</code>.</p>

</s1>

<s1 title="Virtual Sites with different JVM's">

<p>If a seperate JVM for each virtual site is desired, a seperate
<code>resin.ini</code> is used for each virtual site.  The resin.ini file is placed
in the <code>scripts</code> directory.</p>

<example title="resin-foo.xml">
<!-- for foo.com jvm -->
&lt;resin xmlns="http://caucho.com/ns/resin"&gt;
&lt;cluster id=""&gt;

  &lt;server port="6800"/&gt;

  ...
  &lt;host id="*"&gt;
    ...
  &lt;/host&gt;
  
&lt;/cluster&gt;
&lt;/resin&gt;
</example>

<example title="resin-bar.xml">
<!-- for bar.com jvm -->
&lt;resin xmlns="http://caucho.com/ns/resin"&gt;
&lt;cluster id=""&gt;

  &lt;server port="6801"/&gt;

  ...
  &lt;host id="*"&gt;
    ...
  &lt;/host&gt;
&lt;/cluster&gt;
&lt;/resin&gt;
</example>

<example title="installing a servlet runner for each virtual site">
win&gt; resin-3.2.x/resin.exe -install-as "Resin-foo" \
    -conf resin-foo.xml -Xrs
win&gt; resin-3.2.x/resin.exe -install-as "Resin-bar" \
    -conf resin-bar.xml -Xrs
</example>

<example title="resin.ini for IIS virtual site foo.com">
ResinConfigServer localhost 6802
</example>

<example title="resin.ini for IIS virtual site bar.com">
ResinConfigServer localhost 6803
</example>

<p>The ResinConfigServer tells the isapi_srun.dll the port number to use to
connect to the Resin instance.  You can change the host from <var>localhost</var>
to a backend server.  You can also add multiple <var>ResinConfigServer</var> items
to cluster the configuration.</p>

<p>resin-foo.xml and resin-bar.xml contain a &lt;host id="*"&gt;, you do not
need to specify the host name because each conf/JVM is only going to
receive requests from a particular virtual site (because of the unique
resin.ini files).</p>

</s1>

<s1 title="Troubleshooting">

<ol>
<li>Check your configuration with the standalone web server.
In other words, add a &lt;http port='8080'/&gt; block and
browse http://localhost:8080.
</li><li>Check <var>http://localhost/caucho-status</var>.  That will tell if
the ISAPI filter/extension is properly installed. 
</li><li>Each server should be green and the mappings should
match your resin.xml.
</li><li>If caucho-status fails entirely, the problem is in the <var>isapi_srun</var>
installation.  Try
<var>http://localhost/scripts/isapi_srun.dll/caucho-status</var> directly
(bypassing the filter).  If this fails, IIS can't find isapi_srun.dll.
<ul>
<li>Check that isapi_srun.dll is in <var>c:\inetpub\scripts.</var>
</li><li>Make sure that both IIS and the underlying NTFS file system have permissions set appropriately for isapi_srun.dll.
</li><li>Make sure that your IIS host has a mapping from <var>/scripts</var>
to <var>c:\inetpub\scripts</var> and that the <var>/scripts</var> has execute
permissions.
</li><li>IIS 6 users may need to take <a href="#iis6">additional steps</a>.
</li></ul>
</li><li>If you've created a new
IIS web site, you need to create a virtual directory <var>/scripts</var> pointing
to the <var>d:\inetpub\scripts</var> directory.
</li><li>If caucho-status shows the wrong mappings, there's something wrong
with the resin.xml.
</li><li>If caucho-status shows a red servlet runner, then resin.exe hasn't
properly started.
</li><li>If you get a "cannot connect to servlet engine", caucho-status
will show red, and resin.exe hasn't started properly.
</li><li>If resin.exe doesn't start properly, you should look at the logs
in resin3.2/log.  You should start <var>resin.exe -verbose</var> to get
more information.
</li><li>If you get Resin's file not found, the IIS configuration
is good but the resin.xml probably points to the wrong directories.
</li></ol>

<s2 name="iis6" title="Troubleshooting IIS 6">
<p>
IIS 6/Windows 2003 users may need to perform additional steps.
</p>

<ul>

<li>Make sure that the System account has suffiicient privleges to
read the <code>C:\InetPub</code> and <code>C:\InetPub\Scripts</code> directory
and the <code>isapi_srun.dll</code>.

</li><li>Check the `Web Service Extensions' listed in the `Internet Service Manager'
to make sure that Resin is listed as a Web Service Extension and has a status
of "enabled". You may need to click "add a new web service extension...", 
under Extension name add .jsp or whatever your file extension is, 
click Add and browse to the isapi_srun.dll, check the "Set extension status
to allowed box", click OK.


</li><li>Check that the user specified as the
"application pool identity" for Resin has read/write
permission to the Resin installation directory.
In the Internet Service Manager, open the Properties dialog for
"Application Pools".  Find the User on the "Identity" tab, it may
be the user named "Network Service" in the drop-down list associated
with the radio button labeled "predefined".
Then check physical file permissions on the Resin installation
directory and all its subdirectories and subfiles, to ensure that
that user has read/write permission status is "Enabled".

</li></ul>

</s2>
</s1>
</body>
</document>
