Putting Tomcat under SMF

I had brought up the topic of running Tomcat in a zone for students in an educational setting. While not required, it would be nice if Tomcat played nice with the Service Management Facility (SMF). Plus, I'll be doing booth duty talking about Solaris 10 at the AFCEA West 2005. I figure a SMF demo there showing how to integrate existing applications might come in handy. Now, if you really want to learn about SMF, go to those who know much more than me.

While I understand what the benefits of SMF are, this was my first attempt at actually SMF-enabling an application. It's actually pretty easy at an abstract level when you leverage "man smf" and some of the devloper documentation. Another helpful task is to read the actual service description dtd (/usr/share/lib/xml/dtd/service_bundle.dtd.1). Unfortunately the developer documentation doesn't go into much detail yet, but the folks bringing you SMF were working on hard on getting the actual bits out. Expect more documentation to be on it's way.

Here's the net effect of putting Tomcat under SMF control from a lifecycle perspective with some notes:

# svcs tomcat
svcs: Pattern 'tomcat' doesn't match any instances
STATE          STIME    FMRI

Note that SMF has no idea about a Tomcat service out-of-the-box. The first step is to create a service descriptor and import it as follows:
# svccfg import ./tomcat.xml
# svcs tomcat
STATE          STIME    FMRI
offline\*       13:27:04 svc:/application/tomcat:default

The service descriptor has been imported and we check the status of the service using "svcs tomcat". You'll note that it's state at this point is "offline\*". What this means is that SMF is in the process of starting the service.
# svcs tomcat
STATE          STIME    FMRI
offline\*       13:27:11 svc:/application/tomcat:default

Still waiting ...
# svcs tomcat
STATE          STIME    FMRI
online         13:27:16 svc:/application/tomcat:default

Cool, now it's running. One of the semantics of starting a service in SMF is that the application/script that glues the application into SMF has to check to ensure that the service is \*really\* running. It's no rc.d fire & forget here. I chose to use /usr/sfw/bin/wget as a simple means to check that Tomcat was really up and running before returning a "SMF_OK" value. Now lets check to see what services Tomcat depends on. In the Tomcat service descriptor, I defined required dependencies such that if any of the services Tomcat depends on is offline, Tomcat will be offlined. Here's those dependencies:
# svcs -d tomcat
STATE          STIME    FMRI
online         13:21:55 svc:/network/loopback:default
online         13:22:09 svc:/network/physical:default
online         13:22:21 svc:/system/filesystem/local:default

That's simple. If the loopback, physical or local filesystem are not online, Tomcat either will not start or will be offlined. Now let's see what services depend on Tomcat:
# svcs -D tomcat
STATE          STIME    FMRI

None. I knew that :) Now let's disable the physical network interface and see what happens:
# svcadm disable physical
# svcs tomcat
STATE          STIME    FMRI
offline        13:27:50 svc:/application/tomcat:default

Since the physical interface was manually disabled and Tomcat has a required dependency on that interface, SMF automatically offlines Tomcat. Let's say we didn't know that the physical interface was disabled and we wanted to know why Tomcat was offline. How is that "debugged"? Simple "svcs -x":
# svcs -x tomcat
svc:/application/tomcat:default (Tomcat)
 State: offline since Sun Jan 30 13:27:50 2005
Reason: Service svc:/network/physical:default is disabled.
   See: http://sun.com/msg/SMF-8000-GE
Impact: This service is not running.

Cool. Now to fix the problem:
# svcadm enable physical
# svcs tomcat
STATE          STIME    FMRI
online         13:28:16 svc:/application/tomcat:default
Now that was a fun exercise, wasn't it? So what is the point of all this? Now we don't have this very odd and outdated means of dealing with service lifecycles and inter-relationships in Solaris. There are clean relationships and dependencies between services. If you want to see a neat view of boot ordering and bootup times, check out what Dan Price and Eric Schrock have done, leveraging the work done at bootchart.org

Comments:

I'd be extremely helpful to post the tomcat.xml file for us SMF newbies

Posted by Bob on January 30, 2005 at 08:19 AM PST #

BTW, I find a lot of people add "./" even for cases that are not needed: # svccfg import ./tomcat.xml And some people do "cc ./a.c" and "vi ./a.c"... I am so lazy that I setup lots of aliases: alias v vi alias g grep alias f find ...

Posted by Rayson Ho on January 30, 2005 at 01:50 PM PST #

here is an example tomcat.xml Here is a tomcat.xml I made <XMP> <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <!-- Copyright 2004 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. ident "@(#)webmin.xml 1.1 04/11/11 SMI" Service manifest for the Webmin service. --> <service_bundle type='manifest' name='tomcat'> <service name='application/servers/tomcat' type='service' version='1'> <create_default_instance enabled='false' /> <single_instance/> <!-- <dependency name='filesystem' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/system/filesystem/local' /> </dependency> <dependency name='network' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/network/initial' /> </dependency> --> <exec_method type='method' name='start' exec='/jakarta-tomcat-4.1.27/bin/startup.sh' timeout_seconds='30' > <method_context> <method_credential user='<your user>' group='<your group>' /> </method_context> </exec_method> <exec_method type='method' name='stop' exec='/jakarta-tomcat-4.1.27/bin/shutdown.sh' timeout_seconds='60' /> <stability value='Unstable' /> <template> <common_name> <loctext xml:lang='C'> Tomcat </loctext> </common_name> <!-- <documentation> <manpage title='webmin' section='1M' manpath='/usr/sfw/man' /> </documentation> --> </template> </service> </service_bundle> </XMP>

Posted by Clay on May 17, 2005 at 06:44 AM PDT #

Clay, that looks \*amazingly\* familiar :) Of course, the path is a bit different ...

Posted by John Clingan on May 17, 2005 at 07:04 AM PDT #

Yeah... it helps greatly when discussing a subject to have an antecedent. Please post the XML. On the side, what is with almost every Sun blogger never posting their manifests? On another blog, there is a reference made to a ProFTPd manifest and how they are working out it, but the actual manifest is not posted? Come on and share!

Posted by fed-up on September 22, 2006 at 07:06 AM PDT #

What happens if I use jvsc script for tomcat startup instead of the startup.sh on solaris . What is the difference between them ?

Posted by Joy on April 23, 2009 at 06:49 PM PDT #

Great, John! Great, Clay! You helped me a lot. Arigato Gozaimasu.

Posted by Miki Shimizu on October 03, 2009 at 11:05 PM PDT #

there is a problem with this.. when I do svcadm disable tomcat there is a timeout and tomcat goes into maintenance with a killing contract### is there something else that should be done?

thanks

Posted by Mario Garcia Ortiz on November 09, 2010 at 12:40 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed
About

John Clingan

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today