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/