The post derives heavily from Shanti’s Sun MicroSystems blog post.
For a succinct explanation from www.oreillynet.com .
SMF try this from or Solaris 10, Sun introduced the Service Management Facility. SMF is a framework that handles system boot-up, process management, and self-healing. It addresses the shortcomings of startup scripts and creates an infrastructure to manage daemons after the host has booted.
The following steps are required to add cool stack apache as a service into Solaris SMF
1. Create the manifest
A service needs a file called a manifest. A service manifest describes the service and its management needs. It lists the service dependencies, the control scripts, and the actions to take when the service fails. The manifest starts out as an XML file that SMF imports into a central repository, which records the properties of all the services.
Create a file named /var/svc/manifest/network/cskapache2.xml with the following contents :
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!–
Copyright 2006-2007 Sun Microsystems, Inc. All rights reserved.
CSKapache2 manifest – should reside in /var/svc/manifest/network.
–>
<service_bundle type=’manifest’ name=’CSKamp:apache’>
<service
name=’network/csk-http’
type=’service’
version=’1′>
<!–
Because we may have multiple instances of network/http
provided by different implementations, we keep dependencies
and methods within the instance.
–>
<instance name=’CSKapache2′ enabled=’false’>
<!–
Wait for network interfaces to be initialized.
–>
<dependency name=’network’
grouping=’require_all’
restart_on=’error’
type=’service’>
<service_fmri value=’svc:/milestone/network:default’/>
</dependency>
<!–
Wait for all local filesystems to be mounted.
–>
<dependency name=’filesystem-local’
grouping=’require_all’
restart_on=’none’
type=’service’>
<service_fmri
value=’svc:/system/filesystem/local:default’/>
</dependency>
<!–
Wait for automounting to be available, as we may be
serving data from home directories or other remote
filesystems.
–>
<dependency name=’autofs’
grouping=’optional_all’
restart_on=’error’
type=’service’>
<service_fmri
value=’svc:/system/filesystem/autofs:default’/>
</dependency>
<exec_method
type=’method’
name=’start’
exec=’/opt/coolstack/lib/svc/method/svc-cskapache2 start’
timeout_seconds=’60′>
<method_context>
<method_credential
user=’webservd’ group=’webservd’
privileges=’basic,!proc_session,!proc_info,!file_link_any,net_privaddr’ />
</method_context>
</exec_method>
<exec_method
type=’method’
name=’stop’
exec=’/opt/coolstack/lib/svc/method/svc-cskapache2 stop’
timeout_seconds=’60′>
<method_context />
</exec_method>
<exec_method
type=’method’
name=’refresh’
exec=’/opt/coolstack/lib/svc/method/svc-cskapache2 refresh’
timeout_seconds=’60′>
<method_context />
</exec_method>
<property_group name=’httpd’ type=’application’>
<stability value=’Evolving’ />
<propval name=’ssl’ type=’boolean’ value=’false’ />
</property_group>
<property_group name=’st
artd’ type=’framework’>
<!– sub-process core dumps shouldn’t restart session –>
<propval name=’ignore_error’ type=’astring’
value=’core,signal’ />
</property_group>
</instance>
<stability value=’Evolving’ />
<template>
<common_name>
<loctext xml:lang=’C'>
Apache 2 HTTP server
</loctext>
</common_name>
<documentation>
<manpage title=’httpd’ section=’8′
manpath=’/opt/coolstack/apache2/man’ />
<doc_link name=’apache.org’
uri=’http://httpd.apache.org’ />
</documentation>
</template>
</service>
</service_bundle>
2. Create the method
Create the file /opt/coolstack/lib/svc/method/svc-cskapache2 .
You will also have to manually create directories
/opt/coolstack/lib/svc
/opt/coolstack/lib/method
Copy and past the following into the file named above. It assumes the paths of the default installation of Cool Stack. If you have changed the paths you’ll need to reflect those changes here.
#!/sbin/sh
#
# Copyright 2004-2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "@(#)http-apache2 1.2 04/11/11 SMI"
# Modified for apache in CSKamp package of Cool Stack
# This file should reside in /opt/coolstack/lib/svc/method
. /lib/svc/share/smf_include.sh
APACHE_HOME=/opt/coolstack/apache2
CONF_FILE=$APACHE_HOME/conf/httpd.conf
PIDFILE=$APACHE_HOME/logs/httpd.pid
[ ! -f ${CONF_FILE} ] && exit $SMF_EXIT_ERR_CONFIG
case "$1" in
start)
/bin/rm -f ${PIDFILE}
cmd="start"
;;
refresh)
cmd="graceful"
;;
stop)
cmd="stop"
;;
*)
echo "Usage: $0 {start|stop|refresh}"
exit 1
;;
esac
exec ${APACHE_HOME}/bin/apachectl $cmd 2>&1
3. Change file ownership
Cool Stack apache runs as user:group webservd:webservd. We need to ensure that this user can write to the log directory and the pid file. All these files reside in /opt/coolstack/apache2/logs by default.
# chown -R webservd logs
# chgrp -R webservd logs
4. Disable the Solaris http service
Disable any apache processes running at present.
You can check if it is enabled as follows :
If no output is printed, then it is disabled. If you see something like :
maintenance 11:47:11 svc:/network/http:apache2
or
online 11:47:11 svc:/network/http:apache2
then, the service is up.
Disable the service as follows :
svc:/network/http:apache2 disabled.
5. Start the csk-http service
Import the new service config, the manifest xml file as follows :
Resulting output
svccfg: Taking "last-import" snapshot for svc:/network/csk-http:CSKapache2.
svccfg: Refreshed svc:/network/csk-http:CSKapache2.
svccfg: Successful import.
We are now ready to start our service. Start it as follows :
A log of the service startup will be in /var/svc/log/network-csk-http:CSKapache2.log file.