The post derives heavily from Shanti’s Sun Micro Systems blog.
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 MySQL as a service into Solaris SMF. We added the 32-bit version on MySQL that comes with the Cool Stack CSKAmp package.
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/cskmysql.xml with the following contents :
<?xml version=’1.0′?>
<!DOCTYPE service_bundle SYSTEM ‘/usr/share/lib/xml/dtd/service_bundle.dtd.1′>
<!–
Copyright 2006,2007 Sun Microsystems, Inc. All rights reserved.
Manifest for CSKmysql - should reside in /var/svc/manifest/network
–>
<service_bundle type=’manifest’ name=’CSKmysql:mysql’>
<service
name=’network/csk-mysql’
type=’service’
version=’1′>
<create_default_instance enabled=’false’ />
<single_instance />
<!–
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>
<exec_method
type=’method’
name=’start’
exec=’/opt/coolstack/lib/svc/method/svc-cskmysql start’
timeout_seconds=’60′>
<method_context
working_directory=’/opt/coolstack’>
<method_credential
user=’mysql’ group=’mysql’
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-cskmysql stop’
timeout_seconds=’60′>
<method_context />
</exec_method>
<exec_method
type=’method’
name=’refresh’
exec=’/opt/coolstack/lib/svc/method/svc-cskmysql restart’
timeout_seconds=’60′>
<method_context working_directory=’/opt/coolstack’>
<method_credential
user=’mysql’ group=’mysql’
privileges=’basic,!proc_session,!proc_info,!file_link_any,net_privaddr’ />
</method_context>
</exec_method>
</service>
</service_bundle>
Create the method
Create the file /opt/coolstack/lib/svc/method/svc-cskmysql referenced in the manifest with the following contents and make it executable. You may have to create the directories below /opt/coolstack/lib first. This file needs to be edited to set DB_DIR to the path of your data directory (where data files reside), and MYSQL_DIR if you are usi
ng the 64-bit MySQL version.
Create the file /opt/coolstack/lib/svc/method/svc-cskmysql.
You will also have to manually create directories if they don’t already exist.
/opt/coolstack/lib
/opt/coolstack/lib/svc
/opt/coolstack/lib/method
This file needs to be edited to set DB_DIR to the path of your data directory ( normally /opt/coolstack/mysql_32bit), and MYSQL_DIR if you are using the 64-bit MySQL version.
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.
#!/usr/bin/sh
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Method file for CSKMySQL
#
# This uses the MySQL packages from CoolStack 1.1 (CSKmysql)
# If you’re using the 32bit mysql from CSKamp, change MYSQL_DIR below to mysql_32bit.
# This file should reside in /opt/coolstack/lib/svc/method
#
# NOTE: Make sure DB_DIR is owned BY the mysql user and group and chmod 700
#
. /lib/svc/share/smf_include.sh
DB_DIR=/data
PIDFILE=${DB_DIR}/`/usr/bin/uname -n`.pid
MYSQL_DIR=/opt/coolstack/mysql_32bit
mysql_stop () {
if [ -f ${PIDFILE} ]; then
/usr/bin/pkill mysqld_safe >/dev/null 2>&1
/usr/bin/kill `cat ${PIDFILE}` > /dev/null 2>&1 && echo -n ‘ mysqld’
fi
}
mysql_start () {
$MYSQL_DIR/bin/mysqld_safe –user=mysql –datadir=${DB_DIR} –pid-file=${PIDFILE} > /dev/null &
}
##
# Start of script
#
case "$1" in
start)
mysql_start
;;
stop)
mysql_stop
;;
restart)
mysql_stop
while pgrep mysqld > /dev/null
do
sleep 1
done
mysql_start
;;
*)
echo ""
echo "Usage: `basename $0` { start | stop | restart }"
echo ""
exit 64
;;
esac
Change file ownership
Ensure that the MySQL user and group exist and this user owns $DB_DIR. It’s also a good idea to chmod 0700 all files in $DB_DIR.
Cool Stack MySQL runs as user:group mysql:mysql.
# cd /opt/coolstack/ /mysql_32bit
# chown -R mysql ./data
# chgrp -R mysql ./data
# Chmod –R 077 ./data
Start the csk-mysql service
Import the new MySQL config :
# svccfg -v import /var/svc/manifest/network/cskmysql.xml
Start MySQL as a service::
# svcadm -v enable csk-mysql
A log file available at /var/svc/log/network-csk-mysql:CSKmysql.log file.
More detailed information for troubleshooting startup failures can be obtained from the command svcs -x.
If the services does not start and/or goes into maintenance mode then you will need to go through the steps above again verifying it’s correct. I initially had a problem due to incorrect privileges on /opt/coolstack.mysql_32bit/data.
More information on SMF can be found at http://www.sun.com/bigadmin/content/selfheal/smf-quickstart.html