PDA

View Full Version : virtual servers sharing servlets


jimmythehand
12-22-2009, 02:09 PM
Hi there,

I want a configuration where i have multiple virtual hosts on the one server, but they all share the same jvm and servlets, ie there's only one instance of each servlet loaded (since some perform background tasks that we only want processed once).

Is this possible? The documentation seems to imply that each virtual host has its own servlets.

thanks

ferg
12-22-2009, 05:20 PM
If the virtual hosts are just aliases of each other, then yes. You can use <host-alias> in the <host> tag to list the aliases:

<pre>
<resin ...>
<cluster ...>
<host id="www.myhost.com">
<host-alias>sub.myhost.com</host-alias>
...
</pre>

But if the virtual host are separate (different databases or different contents), then the web-app and the servlets will be distinct.

It is possible to have shared beans across all the virtual hosts, although that's a different capability.

jimmythehand
12-24-2009, 12:21 PM
the virtual hosts are not aliases of each other. So I'm presuming the only way to handle this is to have apache as the web server. I've tried to configure this but have hit a stumbling block.

I'm really struggling to get apache talking to resin. I can get resin standalone going with all the servlets running, I can get apache running and showing websites, but the two together just don't seem to mix.

The problem seems to lie in the <srun> configuration.

Below is the resin.conf file we're using. It works fine standalone, all the servlets load on startup as expected and run background tasks. However, if we uncomment the srun directive, then the servlets aren't loaded on startup and we can't access them. I'm not convinced this means apache is talking to resin either - how can we test that?

We've tried moving <srun> around the xml file, inside the other <server> tag etc but haven't had any luck. In fact it seems that the <server> and <cluster> tags are round the other way compared to the other cluster we have defined?

I've got the latest fedora/httpd installed, and using the latest resin 3.1.x

Any help appreciated!

thx

<resin xmlns="http://caucho.com/ns/resin"
xmlns:resin="http://caucho.com/ns/resin/core">

<!-- adds all .jar files under the resin/lib directory -->
<stdout-log path='${resin.home}/log/stdout.log' rollover-period='1W'/>
<stderr-log path='${resin.home}/log/stderr.log' rollover-period='1W'/>

<class-loader>
<tree-loader path="${resin.home}/ext-lib"/>
<tree-loader path="${resin.root}/ext-lib"/>

<tree-loader path="${resin.home}/lib"/>
<tree-loader path="${resin.root}/lib"/>
</class-loader>

<!--***SWITCH this defines the srun that causes resin to listen for apache stuff. currently this breaks the servlets if on-->
<!--server>
<cluster>
<srun server-id="xxxx" host="127.0.0.1" port="6802"/>
</cluster>
</server-->


<!--
- Management configuration
-
- Remote management requires at least one enabled admin user.
-->
<management path="${resin.root}/admin">
<user name="admin" password="password" disable="true"/>

<resin:if test="${resin.professional}">
<deploy-service/>
<jmx-service/>
<log-service/>
<xa-log-service/>
</resin:if>
</management>

<!--
- Logging configuration for the JDK logging API.
-->
<log name="" level="fine" path="stdout:"
timestamp="[%H:%M:%S.%s] {%{thread}} "/>

<!--
- 'info' for production
- 'fine' or 'finer' for development and troubleshooting
-->
<logger name="com.caucho" level="info"/>

<logger name="com.caucho.java" level="config"/>
<logger name="com.caucho.loader" level="config"/>

<!--
- For production sites, change dependency-check-interval to something
- like 600s, so it only checks for updates every 10 minutes.
-->
<dependency-check-interval>2s</dependency-check-interval>

<!--
- SMTP server for sending mail notifications
-->
<system-property mail.smtp.host="127.0.0.1"/>
<system-property mail.smtp.port="25"/>

<!--
- Sets the default character encoding to utf-8
-
- <character-encoding>utf-8</character-encoding>
-->

<!--
- You can change the compiler to "javac", "eclipse" or "internal".
-->
<javac compiler="internal" args="-source 1.5"/>

<!-- Security providers.
- <security-provider>
- com.sun.net.ssl.internal.ssl.Provider
- </security-provider>
-->

<!-- Uncomment to use Resin's XML implementations
-
- <system-property javax.xml.parsers.DocumentBuilderFactory
- ="com.caucho.xml.parsers.XmlDocumentBuilderFactory"/>
- <system-property javax.xml.parsers.SAXParserFactory
- ="com.caucho.xml.parsers.XmlSAXParserFactory"/>
-->

<cluster id="app-tier">
<!--srun server-id="" host="127.0.0.1" port="6802"/-->

<!-- sets the content root for the cluster, relative to server.root -->
<root-directory>.</root-directory>

<server-default>
<!-- The http port -->
<http address="*" port="8080"/>
<!--
- SSL port configuration:
-
- <http address="*" port="8443">
- <openssl>
- <certificate-file>keys/gryffindor.crt</certificate-file>
- <certificate-key-file>keys/gryffindor.key</certificate-key-file>
- <password>test123</password>
- </openssl>
- </http>
-->

<!--
- The JVM arguments
-->
<jvm-arg>-Xmx256m</jvm-arg>
<jvm-arg>-Xss1m</jvm-arg>
<jvm-arg>-Xdebug</jvm-arg>
<jvm-arg>-Dcom.sun.management.jmxremote</jvm-arg>

<!--
- Uncomment to enable admin heap dumps
- <jvm-arg>-agentlib:resin</jvm-arg>
-->

<!--
- arguments for the watchdog process
-->
<watchdog-jvm-arg>-Dcom.sun.management.jmxremote</watchdog-jvm-arg>
<watchdog-port>6600</watchdog-port>

<!--
- Configures the minimum free memory allowed before Resin
- will force a restart.
-->
<memory-free-min>1M</memory-free-min>

<!-- Maximum number of threads. -->
<thread-max>256</thread-max>

<!-- Configures the socket timeout -->
<socket-timeout>65s</socket-timeout>

<!-- Configures the keepalive -->
<keepalive-max>128</keepalive-max>
<keepalive-timeout>15s</keepalive-timeout>

<!--
- If starting bin/resin as root on Unix, specify the user name
- and group name for the web server user.
-
- <user-name>resin</user-name>
- <group-name>resin</group-name>
-->
</server-default>




<!-- define the servers in the cluster -->
<server id="" address="127.0.0.1" port="6800"/>

<!--
- Configures the persistent store for single-server or clustered
- in Resin professional.
-->
<resin:if test="${resin.professional}">
<persistent-store type="cluster">
<init path="session"/>
</persistent-store>
</resin:if>

<!--
- For security, use a different cookie for SSL sessions.
- <ssl-session-cookie>SSL_JSESSIONID</ssl-session-cookie>
-->

<!--
- Enables the cache (available in Resin Professional)
-->
<resin:if test="${resin.professional}">
<cache path="cache" memory-size="64M">
<!-- Vary header rewriting for IE -->
<rewrite-vary-as-private/>
</cache>
</resin:if>

<!--
- Enables periodic checking of the server status and
- check for deadlocks..
-
- All servers can add <url>s to be checked.
-->
<resin:if test="${resin.professional}">
<ping>
<!-- <url>http://localhost:8080/test-ping.jsp</url> -->
</ping>
</resin:if>

<!--
- Defaults applied to each web-app.
-->
<web-app-default>
<prologue>
<!--
- Extension library for common jar files. The ext is safe
- even for non-classloader aware jars. The loaded classes
- will be loaded separately for each web-app, i.e. the class
- itself will be distinct.
-->
<class-loader>
<tree-loader path="${resin.root}/ext-webapp-lib"/>
</class-loader>

<!--
- Enable EL expressions in Servlet and Filter init-param
-->
<allow-servlet-el/>
</prologue>

<!--
- Sets timeout values for cacheable pages, e.g. static pages.
-->
<cache-mapping url-pattern="/" expires="5s"/>
<cache-mapping url-pattern="*.gif" expires="60s"/>
<cache-mapping url-pattern="*.jpg" expires="60s"/>
<cache-mapping url-pattern="*.png" expires="60s"/>

more to come because of limit on length of post

jimmythehand
12-24-2009, 12:25 PM
<!--
- for security, disable session URLs by default.
-->
<session-config>
<enable-url-rewriting>false</enable-url-rewriting>
</session-config>

<!--
- For security, set the HttpOnly flag in cookies.
- <cookie-http-only/>
-->

<!--
- Some JSP packages have incorrect .tld files. It's possible to
- set validate-taglib-schema to false to work around these packages.
-->
<jsp>
<auto-compile>false</auto-compile>
<validate-taglib-schema>true</validate-taglib-schema>
<fast-jstl>true</fast-jstl>
</jsp>
</web-app-default>

<!-- includes the app-default for default web-app behavior -->
<resin:import path="${resin.home}/conf/app-default.xml"/>


<!--
- Sample database pool configuration
-
- The JDBC name is java:comp/env/jdbc/test
<database>
<jndi-name>jdbc/mysql</jndi-name>
<driver type="org.gjt.mm.mysql.Driver">
<url>jdbc:mysql://localhost:3306/test</url>
<user></user>
<password></password>
</driver>
<prepared-statement-cache-size>8</prepared-statement-cache-size>
<max-connections>20</max-connections>
<max-idle-time>30s</max-idle-time>
</database>
-->

<!--
- Default host configuration applied to all virtual hosts.
-->
<host-default>
<!--
- With another web server, like Apache, this can be commented out
- because the web server will log this information.
-->
<access-log path="logs/access.log"
format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"'
rollover-period="1W"/>

<!-- creates the webapps directory for .war expansion -->
<web-app-deploy path="webapps"/>

<!-- creates the deploy directory for .ear expansion -->
<ear-deploy path="deploy">
<ear-default>
<ejb-server>
<config-directory>WEB-INF</config-directory>
</ejb-server>
</ear-default>
</ear-deploy>

<!-- creates the deploy directory for .rar expansion -->
<resource-deploy path="deploy"/>
</host-default>

jimmythehand
12-24-2009, 12:26 PM
<!-- configures a deployment directory for virtual hosts -->
<host-deploy path="hosts">
<host-default>
<resin:import path="host.xml" optional="true"/>
</host-default>
</host-deploy>

<!-- configures the default host, matching any host name -->
<host id="" root-directory=".">
<!--
- configures an explicit root web-app matching the
- webapp's ROOT
-->
<web-app id="" root-directory="doc">
<!-- how often to check servlets for changes (id used for brevity) -->

<!--
- The classpath directive may be repeated. Source is optional
- Servlets and beans generally belong in WEB-INF/classes
-->
<class-loader>
<tree-loader path="${resin.root}/doc/WEB-INF"/>
<simple-loader path="${resin.root}/doc/WEB-INF/classes/"/>
</class-loader>

<!--classpath id='WEB-INF/classes'
source='WEB-INF/classes'
compile='false'/-->

<!--
- Expires time for a cacheable file. Production sites will
- normally change this to '15m'
-->
<cache-mapping url-pattern='/' expires='2s'/>

<!--
- set the pages to be used as welcome (index) files
-->
<welcome-file-list>index.html</welcome-file-list>

<session-config>
<session-max>4096</session-max>
<session-timeout>3000</session-timeout>
<enable-cookies>true</enable-cookies>
<enable-url-rewriting>true</enable-url-rewriting>

<!--
- Store sessions in the filesystem, so they can persist across
- servlet and class changes.
-
- Uncomment this during development.
-->

<file-store>WEB-INF/sessions</file-store>

</session-config>

<!-- enable multipart-mime/form processing -->
<!--
- <multipart-form upload-max='-1'/>
-->
<servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>
<servlet-mapping url-pattern='/servlets/*' servlet-name='invoker'/>

<servlet>
<servlet-name>tipping.BookmakerClick</servlet-name>
<servlet-class>tipping.BookmakerClick</servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>/bc</url-pattern>
<servlet-name>tipping.BookmakerClick</servlet-name>
</servlet-mapping>


<servlet>
<servlet-name>tipping.XML</servlet-name>
<servlet-class>tipping.XML</servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>/xml</url-pattern>
<servlet-name>tipping.XML</servlet-name>
</servlet-mapping>


<servlet>
<servlet-name>tipping.TippingCompetition</servlet-name>
<servlet-class>tipping.TippingCompetition</servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>/tc</url-pattern>
<servlet-name>tipping.TippingCompetition</servlet-name>
</servlet-mapping>


<servlet>
<servlet-name>tipping.PuntersParadise</servlet-name>
<servlet-class>tipping.PuntersParadise</servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>/pp</url-pattern>
<servlet-name>tipping.PuntersParadise</servlet-name>
</servlet-mapping>
<servlet-mapping>
<url-pattern>/betting</url-pattern>
<servlet-name>tipping.PuntersParadise</servlet-name>
</servlet-mapping>
<servlet-mapping>
<url-pattern>/odds</url-pattern>
<servlet-name>tipping.PuntersParadise</servlet-name>
</servlet-mapping>
<servlet-mapping>
<url-pattern>/gotennis</url-pattern>
<servlet-name>tipping.PuntersParadise</servlet-name>
</servlet-mapping>


<servlet>
<servlet-name>tipping.UpdateOdds</servlet-name>
<servlet-class>tipping.UpdateOdds</servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>/updateodds</url-pattern>
<servlet-name>tipping.UpdateOdds</servlet-name>
</servlet-mapping>


<servlet>
<servlet-name>tipping.CanberraTimesLeaderboard</servlet-name>
<servlet-class>tipping.CanberraTimesLeaderboard</servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>/TimesLeaderboard</url-pattern>
<servlet-name>tipping.CanberraTimesLeaderboard</servlet-name>
</servlet-mapping>
<servlet-mapping>
<url-pattern>/timesleaderboard</url-pattern>
<servlet-name>tipping.CanberraTimesLeaderboard</servlet-name>
</servlet-mapping>


<servlet>
<servlet-name>tipping.Login</servlet-name>
<servlet-class>tipping.Login</servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>/servlet/tipping.login</url-pattern>
<servlet-name>tipping.Login</servlet-name>
</servlet-mapping>


<servlet>
<servlet-name>com.caucho.jsp.XtpServle</servlet-name>
<servlet-class>com.caucho.jsp.XtpServle</servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>*.xtp</url-pattern>
<servlet-name>com.caucho.jsp.XtpServle</servlet-name>
</servlet-mapping>


<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>com.caucho.jsp.JspServlet</servlet-class>
</servlet>
<servlet-mapping>
<url-pattern>*.jsp</url-pattern>
<servlet-name>jsp</servlet-name>
</servlet-mapping>

<servlet>
<servlet-name>kirkyonline.classes.MailServlet</servlet-name>
<servlet-class>kirkyonline.classes.MailServlet</servlet-class>
<init-param runArbHunter="true"/>
<init-param runTipReminder="false"/>
<init-param runArbs="false"/>
<init-param runOddsFlucs="true"/>
<init-param runSportsTron="true"/>
<init-param runMailPooler="false"/>
<init-param runNotifyPlayed="false"/>
<init-param runCompUpdater="true"/>
<init-param mailServer="localhost"/>
<init-param server="kirkyonline"/>
<load-on-startup/>
</servlet>



<!--
- The following entries configuration the examples. You may safely
- delete anything from here down.
-->

<!-- Application init parameters, see Env.java to get the values -->
<context-param info='An application information string'/>

<!-- /~user maps to user directories -->
<path-mapping url-regexp='^/~([^/]*)' real-path='/home/$1/public_html/'/>
</web-app>

<web-app id="/resin-admin" root-directory="${resin.home}/php/admin">
<!--
- Administration application /resin-admin
-->
<prologue>
<resin:set var="resin_admin_external" value="false"/>
<resin:set var="resin_admin_insecure" value="true"/>
</prologue>
</web-app>
</host>
</cluster>

<!--
- Configuration for the web-tier/load-balancer
-->
<resin:if test="${resin.professional}">
<cluster id="web-tier">
<server-default>
<!-- The http port -->
<http address="*" port="9080"/>
</server-default>

<server id="web-a" address="127.0.0.1" port="6700"/>

<cache path="cache" memory-size="64M"/>

<host id="">
<web-app id="/">

<rewrite-dispatch>
<load-balance regexp="" cluster="app-tier"/>
</rewrite-dispatch>

</web-app>
</host>
</cluster>
</resin:if>
</resin>

emil
12-30-2009, 09:50 PM
the virtual hosts are not aliases of each other.

If you have exactly the same set of webapps/servlets under two hosts, Resin can treat them as aliases. Actually, you could just throw all your webapp/servlets together, alias them as hosts, and then use filtering to weed out any bad url/host combinations. It's not ideal, but I'm not sure what your application mapping is, so that should work in even the more complicated set ups.

I'm really struggling to get apache talking to resin. I can get resin standalone going with all the servlets running, I can get apache running and showing websites, but the two together just don't seem to mix.

The problem seems to lie in the <srun> configuration.


Sounds like you're trying to mix 3.0 clustering concepts with 3.1. You can read the 3.0 -> 4.0 migration guide here:

http://wiki.caucho.com/Migrating_from_Resin_3.0_to_Resin_4.0#Converting_c lustered_setups

Even though it's 4.0 and the clustering is a bit different behind the scenes, they're syntactically the same so it should get you going in the right direction. Quick summary: <srun> doesn't exist any more, <server> is now a child of <cluster> and <cluster> is a child of <resin>.

Emil

jimmythehand
02-01-2010, 01:19 AM
What we have is basically different skins of the same content, with each different skin having a different website.

So for example we could have websites like
http://www.website1.com
http://www.website2.com

The websites look different, but the main content is the same or is customised within the servlets for each domain.

We want each website to have different document directories, so that they serve a different home page.

We also want all the servlets to be shared across the websites. The servlets look at the domain name, and depending on what it is serves up different html.

Because the servlets do all sorts of background tasks and other stuff, we also want there to be one instance of the servlets only, with each website sharing the same classes.

From what I can gather, this does not seem possible with Resin. If it is possible, can you please point us in the right direction?

thanks

emil
02-04-2010, 06:20 PM
If your servlet is actually looking at the host, then you can just treat them as aliases for Resin's purposes. Just use the <host-alias> configuration that Scott mentioned above and have all of your Servlets configured in the same webapp.

Emil

AlisonRuther
06-25-2010, 02:12 AM
The solution worked for me! I was this problem for quite a while a now and I didn't really bother to ask yet, until I found this forum.