Chris Berry, Bryon Jacob. Updated 11/2/08
This document describes specific details about deploying AtomServer. Basically you have three options;
You should also take a look at these;
Standalone AtomServer
This is the easiest way to deploy AtomServer. Simply:- Download the tar.gz (available here)
- Un-tar it (at, say, ATOMSERVER_HOME)
- Start it up. ($ATOMSERVER_HOME/bin/atomserver.sh)
Using the standalone AtomServer is explained in detail in the Getting Started document, so we won't repeat that information here.
Deploying AtomServer as a War.
To deploy AtomServer as a War you will mostly just- Download the War (available at our maven repository)
- Drop it into your Servlet Engine of choice.
- Set the required AtomServer System properties. Somehow passing them through your Servlet Engine's start script.
- Start it up.
Configuring Tomcat.
Let's use Tomcat as a example. And to simplify the following discussion, lets start from the downloaded tar.gz. This is simpler because the tarball comes with a proper configuration, so we can avoid having to explain that as well. The directory structure and files laid down by the tarball are explained in detail by the Getting Started document. You will be starting up with the provided; myenv.properties from our demo server.- Download the AtomServer tar.gz (available here)
- Un-tar it. Lets assume that you did this at ~/work/atomserver.
cd ~/work
tar -zxvf atomserver-X.X-install.tar
- In your shell, export the ATOMSERVER_HOME environment variable.
Obviously if you are a Windows person you will need all the BAT
equivalents. NOTE: you will probably want to put this in your ~/.bashrc
or ~/.bash_profile)
export ATOMSERVER_HOME=~/work/atomserver
- Copy the atomserver War (now located at $ATOMSERVER_HOME/webapps)
to
$CATALINA_HOME/webapps. Renaming it to atomserver.war as you do.
cp $ATOMSERVER_HOME/webapps/atomserver-X.X.war $CATALINA_HOME/webapps/atomserver.war
-
If you do not already have a $CATALINA_HOME/bin/setenv.sh, copy our tomcat-setenv.sh to $CATALINA_HOME/bin/setenv.sh. If you do already have a $CATALINA_HOME/bin/setenv.sh, you will need to merge the contents of our tomcat-setenv.sh with it. Note that the Tomcat startup script (catalina.sh) already calls out to this script ($CATALINA_HOME/bin/setenv.sh) if it is there. This is Tomcat's convenience mechanism for setting up application specific environments. (NOTE: be sure that your new $CATALINA_HOME/bin/setenv.sh has the proper permissions for whatever user is to run Tomcat). The bottom line here is that AtomServer requires that certain variables be passed into it as it starts up, and these required variables are set for you in setenv.sh)
cp $ATOMSERVER_HOME/bin/tomcat-setenv.sh $CATALINA_HOME/bin/setenv.sh -
Start Tomcat. ($ $CATALINA_HOME/bin/startup.sh)
- The logs from AtomServer will end up in $ATOMSERVER_HOME/logs
- Make certain that $ATOMSERVER_HOME has the proper permissions for whatever user is to run Tomcat.
- All of your configuration lives outside of AtomServer. This is an extremely important point. You can update AtomServer without touching your configuration specifics.
- I've shown the simplest case above. You may wish to set all of this up using $CATALINA_BASE, in which case the procedure would change somewhat. But the basic steps outlined above will hold.
if [ -z "$ATOMSERVER_HOME" ]; then
echo "You MUST set ATOMSERVER_HOME"
exit 1
fi
# ----- AtomServer specific arguments
#
ATOMSERVER_ARGS="-Datomserver.home=$ATOMSERVER_HOME"
ATOMSERVER_ARGS="-Datomserver.data.dir=$ATOMSERVER_HOME/data $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.conf.dir=$ATOMSERVER_HOME/conf $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.ops.conf.dir=$ATOMSERVER_HOME/conf $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.env=myenv $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.port=8080 $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.http.port=8080 $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.http.host=0.0.0.0 $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.jmxhttp.hostname=0.0.0.0 $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.jmxhttp.port=50505 $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.servlet.context=atomserver $ATOMSERVER_ARGS"
ATOMSERVER_ARGS="-Datomserver.servlet.mapping=v1 $ATOMSERVER_ARGS"
export ATOMSERVER_ARGS="$ATOMSERVER_ARGS"
# ----- log4j specific arguments
# NOTE: log4j ONLY takes System vars for substitution in log4j.properties
#
LOG4J_ARGS="-Droot.loglevel=DEBUG -Droot.appender=StdoutFile"
LOG4J_ARGS="-Datomserver.loglevel=DEBUG -Datomserver.logdir=$ATOMSERVER_HOME/logs $LOG4J_ARGS"
LOG4J_ARGS="-Datomserver.logfilename=atomserver $LOG4J_ARGS"
export LOG4J_ARGS="$LOG4J_ARGS"
#---------------------------
export CATALINA_OPTS="$ATOMSERVER_ARGS $LOG4J_ARGS"
Deploying AtomServer as a Jar within your webapp.
Sometimes you may want to embed AtomServer within your project's webapp, rather than deploy the standard AtomServer War. We make this scenario possible too. In this case, your project would produce a War itself, which most likely deploys an AtomServer servlet within. One important reason to embed AtomServer as a Jar is that IDEs can handle Jars dependencies easily, but War dependencies (e.g. Maven War overlays) really confuse them. (Thus, we use this strategy a lot at our day job.)Here is how you wire this up with Maven. In your POM, add the following dependency (note the required; <classifier>classes</classifier>)
<groupId>org.atomserver</groupId>
<artifactId>atomserver</artifactId>
<version>2.0.2</version>
<classifier>classes</classifier>
<type>jar</type>
</dependency>
Next, in your POM, to make things easier,
you will want to add a <properties> section.
<!-- designate the general Spring properties file -->
<mySvcEnv>dev</mySvcEnv>
<!-- the filestore location -->
<mySvcDataDir>file:target/var</mySvcDataDir>
<mySvcConfDir>${basedir}/src/main/dist/server/conf</mySvcConfDir>
<!-- the Servlet setup: /mySvc/v1 -->
<mySvcServletContext>inquiry_store</mySvcServletContext>
<mySvcServletMapping>v1</mySvcServletMapping>
<!-- JMX (jmxBeans.xml) -->
<mySvcJMXHttpPort>50505</mySvcJMXHttpPort>
<mySvcJMXHttpHost>0.0.0.0</mySvcJMXHttpHost>
<!-- log4j properties -->
<rootAppender>Stdout</rootAppender>
<rootLogLevel>DEBUG</rootLogLevel>
<mySvcLogLevel>DEBUG</mySvcLogLevel>
<mySvcLogDir>${basedir}/target</mySvcLogDir>
<mySvcLogFileNamePrefix>inquiry_store</mySvcLogFileNamePrefix>
<!-- used by jettyBeans.xml and jetty:run -->
<mySvcPort>60080</mySvcPort>
</properties>
Finally, in your POM, you will need to add something like the following to your test plugin, your jetty plugin, and anywhere you need System properties:
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.3</version>
<inherited>true</inherited>
<configuration>
<forkMode>once</forkMode>
<reportFormat>plain</reportFormat>
<trimStackTrace>false</trimStackTrace>
<includes>
<include>**/*Test.java</include>
</includes>
<systemProperties>
<!-- used to determine which {atomserver.env}.properties
file to load off the CLASSPATH-->
<property>
<name>atomserver.env</name>
<value>${mySvcEnv}</value>
</property>
<property>
<name>atomserver.conf.dir</name>
<value>${mySvcConfDir}</value>
</property>
<property>
<name>atomserver.data.dir</name>
<value>${mySvcDataDir}</value>
</property>
<property>
<name>atomserver.servlet.context</name>
<value>${mySvcServletContext}</value>
</property>
<property>
<name>atomserver.servlet.mapping</name>
<value>${mySvcServletMapping}</value>
</property>
<property>
<name>atomserver.jmxhttp.port</name>
<value>${mySvcJMXHttpPort}</value>
</property>
<property>
<name>atomserver.jmxhttp.hostname</name>
<value>${mySvcJMXHttpHost}</value>
</property>
<property>
<name>atomserver.port</name>
<value>${mySvcPort}</value>
</property>
<!-- log4j ONLY looks at System properties -->
<property>
<name>root.appender</name>
<value>${rootAppender}</value>
</property>
<property>
<name>root.loglevel</name>
<value>${rootLogLevel}</value>
</property>
<property>
<name>atomserver.loglevel</name>
<value>${mySvcLogLevel}</value>
</property>
<property>
<name>atomserver.logdir</name>
<value>${mySvcLogDir}</value>
</property>
<property>
<name>atomserver.logfilename</name>
<value>${mySvcLogFileNamePrefix}</value>
</property>
</systemProperties>
</configuration>
</plugin>
And you will need to add something like
this to your web.xml:
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Location of the Spring application context configuration files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:org/atomserver/spring/atomServerApplicationContext.xml,
classpath:org/atomserver/spring/ext/*.xml,
classpath:org/atomserver/spring/ext/${atomserver.env}/*.xml
</param-value>
</context-param>
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.atomserver.utils.conf.ExtendedWebContext
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>atomserver</servlet-name>
<servlet-class>org.atomserver.server.servlet.AtomServerServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- this MUST load after the SpringAbderaServlet -->
<servlet>
<servlet-name>aliveservlet</servlet-name>
<servlet-class>org.atomserver.utils.alive.AliveServlet</servlet-class>
<load-on-startup>10</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>atomserver</servlet-name>
<url-pattern>/v1/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>aliveservlet</servlet-name>
<url-pattern>/alive</url-pattern>
</servlet-mapping>
</web-app>
Required Variables to start AtomServer
AtomServer requires certain variables be defined at startup. As you
see above, these variables are passed into AtomServer in each of the
deployment techniques outlined in this document. In fact, you can see a
bash script which sets these variables here.The variables required by AtomServer at startup are as follows;
| atomserver.env | The AtomServer environment.
Tells AtomServer which "env" properties file to load. This variable is critical. This
file is located on the Classpath as; "/env/${env}.properties". I.e. if
"env=foo", the file should be; ".../env/foo.properties" |
| atomserver.data.dir | The AtomServer data directory;
the directory where Entry files (XML) will be written when using
file-based storage. (e.g. $ATOMSERVER_HOME/data) |
| atomserver.conf.dir | The optional configuration
directory. This is another location where AtomServer looks for "env"
files, Spring extension files, etc. This directory is put onto the
Classpath, including ${atomserver.conf.dir}/classes and all JARs in
${atomserver.conf.dir}/lib. |
| atomserver.ops.conf.dir | The optional Operations configuration directory. This is another directory where AtomServer looks for "env" files, Spring extension files, etc. It allows a separate location where you can put configuration files that may require specila protection for Operations. |
| atomserver.home | The root of the atomserver
install. In other words, the root of the expanded AtomServer tarball.
(e.g. $ATOMSERVER_HOME) |
| atomserver.port | The HTTP port to use for
AtomServer (This variable will eventually be removed.) |
| atomserver.http.port | The HTTP port to use for AtomServer (e.g. 8080) |
| atomserver.http.host | The HTTP host to use for AtomServer (e.g. 0.0.0.0) |
| atomserver.jmxhttp.hostname | The JMX HTTP port to use for AtomServer (e.g. 9080) |
| atomserver.jmxhttp.hostname | The JMX HTTP host to use for AtomServer (e.g. 0.0.0.0) |
| atomserver.servlet.context | The base Servlet context (e.g.
"atomserver" in http://localhost:8080/atomserver) |
| atomserver.servlet.mapping | The base Servlet mapping (e.g "v1" in http://localhost:8080/atomserver/v1) |
| root.loglevel |
The root logging level for
log4j. (e.g. WARN) |
| root.appender | The root appender for log4j (should be either StdoutFile or Stdout) |
| atomserver.loglevel | The logging level for AtomServer. (e.g. INFO) |
| atomserver.logdir | The directory to log into. (e.g.
$ATOMSERVER_HOME/logs) |
| atomserver.logfilename | The base name for AtomServer log
files. (e.g. "atomserver" will result in atomserver.stdout.log, etc.) |
Deploying AtomServer