How to configure MySQL to run with Solaris Management Facility (SMF)

MySQL 5.0.45 is integrated with Open Solaris build 79. It is available in Solaris Express Developer Edition (SXDE) 01/08. MySQL 5.0.45 is integrated with Solaris Service Management Facility (SMF).

This blog entry describes the steps that were taken to integrate MySQL with SMF.

First a quick recap of what is SMF:

SMF is the core component of the predictive self-healing technology available in Solaris 10, which provides automatic recovery from software and hardware failures as well as adminstrative errors.
Some of the advantages of using SMF are as under:

  • Failed services are automatically restarted in dependency order, whether they failed as the result of administrator error, software bug, or were affected by an uncorrectable hardware error.

  • More information is available about misconfigured or misbehaving services, including an explanation of why a service isn't running , as well as individual, persistent log files for each service.

  • Problems during the boot process are easier to debug, as boot verbosity can be controlled, service startup messages are logged, and console access is provided more reliably during startup failures.

  • Administrators can securely delegate tasks to non-root users more easily, including the ability to configure, start, stop, or restart services .

  • Large systems boot faster by starting services in parallel according to their dependencies.

Below are the SMF service manifest and accompanying shell script needed to integrate MySQL with Solaris SMF.

Perform the following steps to import the manifest into the SMF repository.

  1. Save the following XML code to a file called "mysql.xml" in /var/svc/manifest/application/database. You need to create the directory if it doesn't exist and have the appropriate privileges to perform this action.

<service_bundle type='manifest' name='mysql'>

<service
    name='application/database/mysql'
    type='service'
    version='1'>

<!--
Wait for network interfaces to be initialized.
-->

    <dependency
        name='network'
        grouping='require_all'
        restart_on='none'
        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='/lib/svc/method/mysql start'
    timeout_seconds='60' />

<exec_method
    type='method'
name='stop'
exec='/lib/svc/method/mysql stop'
timeout_seconds='60' />

<instance name='version_50' enabled='false'>

    <method_context>
    <method_credential user='mysql' group='mysql' />
    </method_context>

    <property_group name='mysql' type='application'>
        <propval name='bin' type='astring'      
            value='/usr/mysql/5.0/bin' />
        <propval name='data' type='astring'
            value='/var/mysql/5.0/data' />
    </property_group>

</instance>

<stability value='Evolving' />

<template>
    <common_name>
        <loctext xml:lang='C'>
            MySQL RDBMS
        </loctext>
    </common_name>

    <documentation>
        <manpage title='MySQL 5.0.45' section='1' />
        <doc_link name='mysql.com' uri='http://dev.mysql.com/docs' />
    </documentation>
</template>

</service>

</service_bundle>


The default instance of the manifest assumes that the database user is mysql and the database directory is /var/mysql/5.0/datasql/data . If any of them is different, update the above XML accordingly.
  1. Save the following shell script to a file called "mysql".

getproparg() {
    val=`svcprop -p $1 $SMF_FMRI`
    [ -n "$val" ] && echo $val
}

MYSQLBIN=`getproparg mysql/bin`
MYSQLDATA=`getproparg mysql/data`
PIDFILE=${MYSQLDATA}/`/usr/bin/uname -n`.pid

if [ -z $SMF_FMRI ]; then
    echo "SMF framework variables are not initialized."
    exit $SMF_EXIT_ERR
fi

if [ -z ${MYSQLDATA} ]; then
    echo "mysql/data property not set"
    exit $SMF_EXIT_ERR_CONFIG
fi

               
                    if [ ! -d ${MYSQLDATA} ]; then
                       
echo "mysql/data directory ${MYSQLDATA} is not a valid MySQL data directory"
                       
exit $SMF_EXIT_ERR_CONFIG
                    fi

if [ ! -d ${MYSQLDATA}/mysql ]; then
    ${MYSQLBIN}/mysql_install_db --user=mysql --datadir=${MYSQLDATA}
fi

mysql_start() {

    echo ${MYSQLBIN}/mysqld --user=mysql --datadir=${MYSQLDATA} --pid-file=${PIDFILE}
    ${MYSQLBIN}/mysqld --user=mysql --datadir=${MYSQLDATA} --pid-file=${PIDFILE} > /dev/null &

}

mysql_stop() {

    if [ -f ${PIDFILE} ]; then
        pkill mysqld
    fi
}

case "$1" in

    'start')

        mysql_start
        ;;

    'stop')

        mysql_stop
        ;;

       \*)
        echo "Usage: $0 {start|stop}"
        exit 1

esac

exit $SMF_EXIT_OK


  1. Place the shell script "mysql" in /lib/svc/method.

  2. Change the permission to 555. You need to have the appropriate write privileges to copy files into this directory.

  3. Import the SMF manifest by executing the following commands:

    # cd /var/svc/manifest/application/database 
    # /usr/sbin/svccfg import mysql.xml
  4. Initially the service instance is disabled. Use the following command to see the state.
    # svcs mysql

  5. Start the service for the default instance by executing the following command:

    # /usr/sbin/svcadm enable mysql

    From this point on the MySQL process is controlled by the Solaris SMF.

    For more details on how to use SMF, refer to the following BigAdmin site:

    http://www.sun.com/bigadmin/content/selfheal/



Comments:

That's Good

Posted by 美金 on February 28, 2008 at 03:41 PM PST #

Very nice! Are there also SMF files for the MySQL-Cluster NDB storage engine and NDB-manager application?

Posted by Paul Boven on March 12, 2008 at 01:20 AM PDT #

I did just what it says and I end up with

svccfg: document has no DTD

In my family when someone says DTD it means retarded........

whats going on hear

Posted by jflintz on March 17, 2008 at 05:49 PM PDT #

Hi,

There may be a typo in your mysql.html file.

Run this command:
# svccfg validate mysql.html

It will provide you more information about where is the typo (if any)

Regards,
Ritu

Posted by Ritu on March 23, 2008 at 11:21 PM PDT #

Try adding this to the top of the xml file:

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

Posted by Tim on April 25, 2008 at 02:32 AM PDT #

How to configure MySQL to run with Solaris Management Facility (SMF)

Posted by Handan on May 07, 2008 at 06:42 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Ritu Kamboj

Search

Categories
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