Sun Microsystems - Solaris Support website.

Thursday, December 01, 2005

CONFIGURING JBOSS WITH SMF

CONFIGURING JBOSS WITH SMF

The Solaris 10 OS uses the Service Management Facility (SMF) to handle services.

Traditional means like /etc/rc?.d scripts still work, but as a legacy means. (For more information on SMF, see the References section.)

To take advantage of the SMF in the Solaris 10 OS using JBoss, do the following.
Note: Read the scripts and "change" the paths of jboss and your version of jboss accordingly! This does work for JBoss 3.x.x branches too!

Create a service manifest file:
/var/svc/manifest/network/jboss4.xml

This contains the following:

<?xml version='1.0'?>
<!DOCTYPE service_bundle SYSTEM
'/usr/share/lib/xml/dtd/service_bundle.dtd.1'>

<!--
William Pool (Puddle) 01/05
Service manifest for JBoss
E-mail: puddle@flipmotion.com
-->

<service_bundle type='manifest' name='JBoss4:jboss'>

<service
name='network/jboss'
type='service'
version='1'>
<create_default_instance enabled='false' />
<single_instance />

<dependency name='fs'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri
value='svc:/system/filesystem/local' />
</dependency>

<!-- DATABASE NOTES

UnComment this block if you use MySQL/PostgreSQL. This will make sure
that MySQL/PostgreSQL is started before you start JBoss. This is an
example for MySQL.

Please create an SMF service for MySQL / PostgreSQL.

<dependency name='mysql'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri
value='svc:/network/mysql' />
</dependency>

-->

<dependency name='net'
grouping='require_all'
restart_on='none'
type='service'>
<service_fmri value='svc:/network/loopback' />
</dependency>

<dependent
name='ssh_multi-user-server'
grouping='optional_all'
restart_on='none'>
<service_fmri
value='svc:/milestone/multi-user-server' />
</dependent>

<exec_method
type='method'
name='start'
exec='/lib/svc/method/svc-jboss4 start'
timeout_seconds='-1'>
<method_context>
<method_credential user='jboss' group='jboss' />
</method_context>
</exec_method>

<exec_method
type='method'
name='stop'
exec=':kill'
timeout_seconds='-1'>
</exec_method>

<exec_method
type='method'
name='restart'
exec='/lib/svc/method/svc-jboss4 restart'
timeout_seconds='-1'>
</exec_method>

<stability value='Unstable' />

<template>
<common_name>
<loctext xml:lang='C'>
JBoss
</loctext>
</common_name>
<documentation>
<manpage title='jboss' section='1M'
manpath='/usr/share/man' />
</documentation>
</template>
</service>
</service_bundle>

Now create your "Service Method File" in /lib/svc/method called svc-jboss4:

#!/usr/bin/sh
# William Pool (Puddle) 01/05
# SMF Method file for JBoss
# E-mail: puddle@flipmotion.com
#
# NOTE: If you start JBoss with su -c 'cmds' instead
# You "will" be able to start and stop it via root using the method file
# itself. However, it "does" confuse SMF. It's best to have the straight
# commands and let the actual SMF service do the user rights and permissions
# of execution. You've been WARNED! Use su -c 'cmds' at your own risk!
#

. /lib/svc/share/smf_include.sh

case $1 in
'start')
echo "starting jboss.."
/opt/software/jboss-4.0.1/bin/run.sh & >/dev/null 2> /dev/null
;;

'stop')
echo "stopping jboss.."
/opt/software/jboss-4.0.1/bin/shutdown.sh -S &
pkill java
;;

'restart')
stop
# give stuff some time to stop before we restart
sleep 35
# protect against any services that can't stop before we restart (warning
this kills all Java instances running as 'jboss' user)
pkill java
start
;;
*)
echo "Usage: $0 { start | stop | restart }"
exit 1
;;
esac

#---EOF

Now fix the permissions for the two files created:
chown root:bin /lib/svc/method/svc-jboss4
chmod 555 /lib/svc/method/svc-jboss4
chown root:sys /var/svc/manifest/network/jboss4.xml
chmod 444 /var/svc/manifest/network/jboss4.xml

Import the service into the service repository:

# svccfg import /var/svc/manifest/network/jboss4.xml

Enable the service:
# svcadm -v enable jboss

I want to thank William Pool and the contribution of the opensolaris community of IRC. They have help me all the way in my learning path of the Solaris 10 OS.

0 Comments:

Post a Comment

<< Home