Home > Solaris 10 > Boot Tomcat at Server Startup/Reboot

Boot Tomcat at Server Startup/Reboot

I am running Sun Solaris 11 on a Joyent Machine. This may not apply to typical Tomcat setups.

My resources that helped achieve this. Both Peter Black and Peter Tribble are much more articulate in technical writing. So have a look:
1. Joyent Wiki, i forget which article.
2. Peter black: Solaris 10 manifest for starting up tomcat.
3. Peter Tribble: Peter’s Solaris Zone

Create a Manifest File which will be registered with Solaris. Mine looks like this:

<?xml version="1.0" ?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='Tomcat6'>
  <service name='application/servers/tomcat' type='service' version='1'>
    <create_default_instance enabled='false' />
       <single_instance/>
       <exec_method type='method' name='start' exec='/opt/local/java/tomcat6/bin/startup.sh' timeout_seconds='30' >
         <method_context>
           <method_credential user='tomcat' group='tomcat' privileges='basic,net_privaddr' />
           <method_environment>
             <envvar name="CATALINA_BASE" value="/opt/local/java/tomcat6" />
             <envvar name="CATALINA_HOME" value="/opt/local/java/tomcat6" />
             <envvar name="CATALINA_TMPDIR" value="/opt/local/java/tomcat6/temp" />
             <envvar name="JAVA_HOME" value="/opt/local/java/sun6" />
           </method_environment>
         </method_context>
       </exec_method>
       <exec_method type='method' name='stop' exec='/opt/local/java/tomcat6/bin/shutdown.sh' timeout_seconds='60' >
         <method_context>
           <method_credential user='tomcat' group='tomcat' />
           <method_environment>
             <envvar name="CATALINA_BASE" value="/opt/local/java/tomcat6" />
             <envvar name="CATALINA_HOME" value="/opt/local/java/tomcat6" />
             <envvar name="CATALINA_TMPDIR" value="/opt/local/java/tomcat6/temp" />
             <envvar name="JAVA_HOME" value="/opt/local/java/sun6" />
           </method_environment>
         </method_context>
       </exec_method>
       <stability value='Unstable' />
       <template>
         <common_name>
           <loctext xml:lang='C'> Tomcat </loctext>
         </common_name>
       </template>
   </service>
</service_bundle>

How to customize this manifest file:

Give the service manifest a meaningful name. I chose tomcat6. This can be found in the xml node:

<service_bundle type=’manifest’ name=’Tomcat6‘>

Set the path to file (i think). Here I’ve created the servers directory. And file name is tomcat.xml Note that the .xml extension isnt included in name attribute.
<service name=’application/servers/tomcat‘ type=’service’ version=’1′>

This file is stored in the vendor recommended location on the filesystem:

/var/svc/manifest/application/

And the complete path including the directory and file that I manually created:

/var/svc/manifest/application/servers/tomcat.xml

Next fill in all information regarding your configuration. Such as startup.sh, shutdown.sh scripts and environment variables. Read the Peter Black article for specifics.

Register the Manifest File.

Once the manifest file has been created and saved in the /var/svc/manifest/application/… directory; register it with the Service Management Facility (smf).

To begin, import the file. At terminal command prompt:

svccfg -v import /var/svc/manifest/application/servers/tomcat.xml

A successful import may look like the following:

svccfg: Taking “initial” snapshot for svc:/application/servers/tomcat:default svccfg: Taking “last-import” snapshot for svc:/application/servers/tomcat:default svccfg: Refreshed svc:/application/servers/tomcat:default svccfg: Successful import

Debugging a Manifest File

Originally I had some errors. This required some exploration to understand. Here is what i concluded and this is where Peter Tribble’s Solaris Zone is extremely useful. Specifically he helped me understand how to “correct a fault in a manifest file”.

I attempted to start tomcat svcadm enable tomcat in which nothing happened. So to begin isolating the error I looked at the log file for my service. Take a look:

First attempt to enable my Tomcat service. At this point the manifest file above has been imported. Using the svcadm tool, lets enable tomcat service, check the status, notice its in maintenance mode which means its not running. Then check the logs to determine why its not running and fix accordingly.

svcadm enable tomcat

svcs -lp tomcat

svcs -lp tomcat
fmri svc:/application/servers/tomcat:default
name Apache Tomcat 6.0.35
enabled true
state maintenance
next_state none
state_time February 5, 2012 08:59:59 PM UTC
logfile /var/svc/log/application-servers-tomcat:default.log
restarter svc:/system/svc/restarter:default contract_id

As you can see in the code above, the Tomcat service is in maintenance mode. So Tomcat isnt running. Time to view the log file to see what the issue is. In my case, the environment variables weren’t defined.

cat /var/svc/log/application-servers-tomcat:default.log

I see the log entry below:

Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
At least one of these environment variable is needed to run this program
[ Feb  5 20:59:59 Method “start” exited with status 1. ]

My fix was to add the environment variables in the manifest file shown above. So hopefully you will not see this error. I was able to add the environment variables to the manifest file and startup the service without any other problems.

At this point, I believe that adding environment variables to any of the traditional files (.bashrc,  .bash_profile, /etc/.profile, etc) is not necessary.

Some commands that might be useful:

Start/Stop Tomcat service.
svcadm enable tomcat
svcadm disable tomcat

View Status of a specific service.
svcs -lp tomcat

View Status of all services.
svcs -a

When the tomcat service is enabled, Apache Tomcat Server will start up when the Server is rebooted.

To correct errors in a manifest file:

1. Edit the manifest file.
sudo vi /var/svc/manifest/application/servers/tomcat.xml

2. Disable the entry:
svcadm -v disable svc:/application/web/tomcat:default

3. Delete the entry:
svccfg -v delete svc:/application/web/tomcat:default

4. Import updated manifest file:
svccfg -v import /var/svc/manifest/application/servers/tomcat.xml

5. Start up entry.
svcadm enable tomcat

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: