Resin webserver setup with Java and mysql

As per  , Resin provides a fast standalone web server. It serves static pages faster than Apache! .Resin will work well with php,java and mysql.

We can compile resin in two ways, one as a module of apche and the second one as a standalone webserver.  Here i am discussing the installation and configuration of resin stand alone webserver with java and mysql.

When running as a daemon (eg, start) Resin Watchdog Manager is the watchdog and Resin is the actual Resin instance. When running Resin as a foreground process, the process list displays resin.jar, which acts as the watchdog.

The Resin Watchdog Manager is the parent process, providing automatic restarting Resin in cases of failure, and providing a single point of control for the start, stop and restart of all Resin processes. It is responsible for launching Resin with the correct JVM arguments and environment options such as starting Resin as the specified user, e.g. for <user-name> on unix.

Resin Watchdog Manager watches Resin via a Socket connection. When the watchdog socket closes, Resin shuts itself down gracefully. The watchdog closes the socket on a stop or restart or if the watchdog itself is killed. If Resin exits for any reason, the watchdog will automatically start a new Resin process. This socket connection approach avoids the need for any signals or actual killing of Resin from the watchdog, and also makes it easy to stop all the Resins if necessary by just killing the watchdog.

The Resin Watchdog Manager doesn’t actually kill Resin or even check Resin’s status, it just checks to see if Resin is alive or not. So if the JVM were to completely lock up, the watchdog would still think Resin was okay and would take no action.

Because the watchdog is always managing Resin processes, if you ever need to stop Resin with kill, you must kill the watchdog. Just killing the Resin process results in the watchdog restarting it automatically.

The watchdog will log to log/watchdog-manager.log. The Resin standard out/err is log/jvm-servername.log. Resin Watchdog Manager is responsible for creating both of these log files, so jvm-servername.log is not really under the control of the Resin instance. This makes it somewhat more reliable in case of JVM deadlocks, etc.

1) Install JAVA

Download java

Make sure that execute permissions are set
chmod +x  jdk-6u26-linux-x64.bin

Run the self-extracting binary.

Create softlink
ln -s /usr/java/jdk-1_6_26_(version) /usr/java/jdk

Add JAVA_HOME and set classpath

vi /etc/profile
(add the following after the line “export PATH LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC” )

export JAVA_HOME=/usr/java/jdk
export CLASSPATH=$CLASSPATH:/usr/java/jdk/lib/tools.jar
export CLASSPATH=$CLASSPATH:/usr/java/jdk/bin:/usr/java/jdk/jre/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin

Check the java version

#  java -version
java version “1.6.26_00”

2) Install Mysql

You can refer the following lik to install mysql :  LAMP server setup


3) Install Resin

Resin is a fast JavaEE 6 web server. It is built on our distributed-agent technology for the elastic cloud. Our administration and health monitoring tools provide statistics, troubleshooting and application management. The resin cloud scales messaging, caching, load balancing and deployment services for new servers without a need for configuration. Resin runs on all major operating systems .Resin is coming with two version free and licensed version. Resinpro is the license version. Installation and setup is same for both the servers.

# wget
# tar -vzxf resin-pro-4.0.19.tar.gz
# cd resin-pro-4.x.x
# ./configure –prefix=/usr/local/resin
( This will configure Resin to install in /usr/local/resin, with support for OpenSSL if it was detected )
# make
# make install
# ln -s /usr/local/resin-pro-4.x.x  /usr/local/resin
# vi /etc/profile
( add RESIN_HOME in  file )

4)  Configure app-default.xml ( you can use the default configuaration files in /usr/local/resin/conf/app-default.xml  directory after making necessary changes )

Its a global configuration file to declare variable for all the hosts ( with different resin.conf )

The <web-app-default> directive is a default configuration for all [web-apps|web-app] in a [host]. It can contain all the children of a <[web-app]> directive. It can be particularly useful with the <[web-app-deploy]> directive in combination with <[resin:import|resin import]>.

Example configuration :-

<compiling-loader path=”WEB-INF/classes”/>
<library-loader path=”WEB-INF/lib”/>

5)  Configure resin ( you can use the default configuaration files in /usr/local/resin/conf directory after making necessary changes )

Resin uses a tag-based xml configuration file, usually as resin.conf . Default resin configuration will be in RESIN_HOME/conf/resin.conf .  We can give any name for the
resin conf , for example we can give adminlogs.conf.

Vi /usr/local/resin/conf/resin.conf
– Management configuration
– Remote management requires at least one enabled admin user.
– Following section , whenever server load reaches 10 resin will restart the service automatically.
<user name=”admin” password=”password==”/>
<user name=”resin” password=”password==”/>

– SMTP server for sending mail notifications
<system-property mail.smtp.port=”25″/>

– Sets the default character encoding to utf-8

– Configures the keepalive
-Configure Memory and cache
<cache path=”cache” memory-size=”512M” disk-size=”2048M”>

– Check website status and restart the server if its not listening to port 8080
-( Starts a thread that periodically makes a request to the server, and restarts Resin if it fails. This facility is used to increase server reliability – if there is a problem with the server (perhaps from a

-deadlock or an exhaustion of resources), the server is restarted. A failure occurs if a request to the url returns an HTTP status that is not 200 )
<!– a very busy server –>
<!–mail notification when ping fails–>
<mail-to>[email protected]</mail-to>
<mail-from>[email protected]</mail-from>
<mail-subject>Resin ping has failed for server ${}</mail-subject>

-VirtualHost Section

<server id=”adminlogs” address=”″>
<http id=”adminlogs” address=”″ port=”8080″/>
<http id=”adminlogs” address=”″ port=”8443″>

-SSL configuration starts here
<protocol>-ALL +SSLv3 +TLSv1</protocol>
</openssl> </http>

 <host id="">
 <access-log path="/usr/local/www/hosts/" format='%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"' rollover-period="1D"/>
 <stdout-log path="/usr/local/www/hosts/" rollover-count='7' timestamp='%H:%M:%S: ' rollover-period='1D'/>
 <stderr-log path="/usr/local/www/hosts/" rollover-count='4' timestamp='%d/%m/%y %H:%M:%S: ' rollover-period='1W'/>
 <web-app id='/'>
 <servlet-mapping url-pattern="/servlet/*" servlet-name="invoker"/>
 <compiling-loader path='corresponding class file location'/>
 <compiling-loader path='corresponding java core files'/>
 <library-loader path='corresponding lib path'/>
 -DATA BASE connection configuration 
 <driver type="">
 - DATABASE configuration ends here

Once you complete the resin.conf setup , then you need to upload your files to your document root and setup web.xml in WEB-INF/web.xml


6)  Setup web.xml

vi /usr/local/www/hosts/

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "">
 <context-param><param-name>WebsiteName</param-name><param-value>Adminlogs Live</param-value></context-param>

7) Configure resin startup script  to start/stop and restart

vi /usr/local/resin/bin/

# resin         This shell script takes care of starting and stopping
#               the Resin Webserver service.
export JAVA_HOME
export PATH
CURRENT_USER="`id | sed 's/uid=[0-9][0-9]*(\([^)]*\)).*/\1/'`"
if [ $USER = $CURRENT_USER ] ; then
$RESIN_HOME/bin/ -server-root $SERVER_ROOT -conf $SERVER_ROOT/conf/resin.conf -server adminlogs $*
su - $USER -c "$RESIN_HOME/bin/ -server-root $SERVER_ROOT -conf $SERVER_ROOT/conf/resin.conf -server adminlogs $*"

8 ) Setup IPTABLE rules for port forwarding.

resin will listen on the ports 8080 and secure port 8443. We need to write our firewall rules to forward the communication from http port 80 to resin ports

 iptables -t nat -A PREROUTING -d -p tcp -m tcp --dport 80 -j DNAT --to-destination
 iptables -t nat -A PREROUTING -d -p tcp -m tcp --dport 443 -j DNAT --to-destination

/etc/init.d/iptables save


10 )  Start resin

We can start resin as the user resin only , first we need to switch to resin user as follows  ( Also if you are using resin pro, then you should update the license file to ” /usr/local/resin/licenses/license-filename.license ” )

# su resin –
# /usr/local/resin/bin/ start

11) Logs

As per the resin configuration , resin will write the logs for in to the log directory of each host . If resin is not starting properly you need to check the following logs to find the cause.

tail -f /usr/local/www/hosts/
tail -f /usr/local/www/hosts/


Optional section : – Resin directives

>>> Connection settings configuration

keepalive-max : the maximum number of keepalive connections
keepalive-timeout : the maximum time a connection is maintained in the keepalive state
thread-max : maximum number of working threads
spare-thread-min: minimum number of spare working threads

>> ssl configuration

certificate-file: the file containing the server’s certificate
certificate-key-file : the file containing the server’s certificate key, if separate from certificate-file
password: the certificate key password
certificate-chain-file: A file containing an intermediate (untrusted) and root (trusted) certificate ( same as CA bundle )
protocol: SSLProtocol
cipher-suite :SSLCipherSuite

>>> Server Status configuration

Ping Starts a thread that periodically makes a request to the server, and restarts Resin if it fails. This facility is used to increase server reliability – if there is a problem with the server (perhaps from a deadlock or an exhaustion of resources), the server is restarted.A failure occurs if a request to the url returns an HTTP status that is not 200.

url : A url to ping.
sleep-time: Time to wait between pings. The first ping is always 15m after the server starts, this is for subsequent pings.
try-count: If a ping fails, number of times to retry before giving up and restarting
retry-time: time between retries
socket-timeout :time to wait for server to satrt responding to the tcp connection before giving up
stat-service:periodically checks the status of the server, and reports errors as necessary.
cpu-load-exit-threshold : CPU load triggering a Resin exit (and restart)
cpu-load-log-info-threshold: CPU load triggering a log message at the info level
cpu-load-log-warning-threshold:CPU load triggering a log message at the warning level
cpu-load-log-thread-dump-threshold: CPU load triggering thread dump to the log
sample-period:how often to sample the statistics
thread-dump-interval: minimum time between thread dumps

>>> Memory Configuration

Memory-free-min :   improves server reliability by detecting low-memory situations caused by memory leaks and forcing a clean server restart. Since Resin’s watchdog service reliably restarts the server, a website can improve stability by forcing a restart before memory becomes a major problem. The memory-free-min restart will also log a warning, notifying the developers that a potential memory leak needs to be resolved.

The allocation of memory for the JVM is specified using -X options when starting Resin
It is good practice with server-side Java applications like Resin to set the minimum -Xms and maximum -Xmx heap sizes to the same value.

-Xms    initial java heap size
-Xmx    maximum java heap size
-Xmn    the size of the heap for the young generation

As you know its a vast subject and not that much easy to document in a single post. I have tried my best to include all the necessary things to setup a website in resin . Hope this info will helps  🙂
Reference :