Performance Blog

SMF support for MySQL in Cool Stack

Posted on: April 16, 2007

Here are instructions on how to use SMF to manage MySQL. These instructions assume no knowledge of SMF. All commands should be executed as root.

Create the manifest

 The manifest defines the service and controls the privileges with which the service will execute. We use the service name csk-mysql to distinguish this as a Cool Stack service.

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’>

        <create_default_instance enabled=’false’ />
        <single_instance />

         Wait for network interfaces to be initialized.
       <dependency name=’network’


          Wait for all local filesystems to be mounted.
        <dependency name=’filesystem-local’

             exec=’/opt/coolstack/lib/svc/method/svc-cskmysql start’
                   user=’mysql’ group=’mysql’
                   privileges=’basic,!proc_session,!proc_info,!file_link_any,net_privaddr’ />

             exec=’/opt/coolstack/lib/svc/method/svc-cskmysql stop’
             <method_context />

             exec=’/opt/coolstack/lib/svc/method/svc-cskmysql restart’
             <method_context working_directory=’/opt/coolstack’>
                   user=’mysql’ group=’mysql’
                   privileges=’basic,!proc_session,!proc_info,!file_link_any,net_privaddr’ />


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 using the 64-bit MySQL version.

#   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/

PIDFILE=${DB_DIR}/`/usr/bin/uname -n`.pid

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’

mysql_start () {
;   $MYSQL_DIR/bin/mysqld_safe –user=mysql –datadir=${DB_DIR} –pid-file=${PIDFILE} > /dev/null &

# Start of script
case "$1" in
        while pgrep mysqld > /dev/null
            sleep 1
        echo ""
        echo "Usage: `basename $0` { start | stop | restart }"
        echo ""
        exit 64

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.

Start the csk-mysql service

Import the new mysql config :

# svccfg -v import /var/svc/manifest/network/cskmysql.xml

We are now ready to start our service. Start it as follows :

# svcadm -v enable csk-mysql

If the service starts successfully, you should see mysqld running. A log of the
service startup will be in /var/svc/log/network-csk-mysql:CSKmysql.log file. You can also get more detailed information for troubleshooting startup failures from the command svcs -x. More information on SMF can be found at



18 Responses to "SMF support for MySQL in Cool Stack"

i try to use SMF but always in maintenance state…
# svcs -x
svc:/network/csk-mysql:default (?)
State: maintenance since Wed May 30 13:44:47 2007
Reason: Method failed.
See: /var/svc/log/network-csk-mysql:default.log
Impact: This service is not running
If I run the method independently it run normally…?
but always in maintenance state when run with svcadm 😦

What does the error log /var/svc/log/network-csk-mysql show ?

mine doesn’t appear to be working either. the log-file says:
070531 18:40:37 InnoDB: Started; log sequence number 0 43655
070531 18:40:37 [ERROR] Fatal error: Can’t open and lock privilege tables: Table ‘’ doesn’t exist
070531 18:40:37 mysqld ended
is there some sort of “installation” that needs to be done before starting (enabling) the mysql service the 1st time?

Yes indeed. You first need to do the MySQL setup and create a database. See the README file in the mysql directory or google to get instructions.

The Cool Stack 1.1 package CSKamp does not include any information on configuring MySQL database for use (creating mysql user, group, mysql_install_db, etc.).

We do include these instructions in the CSKmysql package. Our intent was that people would use the CSKmysql package (which is 64bit) to run the database server, and the CSKamp package only for client-side access. But I realize that many people are using the 32bit mysql in CSKamp as their db server – so will update the README file in this package.
Thanks for the feedback.

There is an error on the “privileges” line of the “start” method above – there was some word wrapping performed, and the net_privaddr needs to be preceeded by a “bang” (!). This caused me much confusion, because I know nothing about SMF, but when I clued in to the error message on system restart (couldn’t interpret privileges) I looked at the line and saw that net_privaddr was not like the others. Also, I did a cut and paste into the file to be created, and I got an extraneous blank line – not a problem, but the missing “bang” was a problem. Not sure how I did it, but it looks like I got the “cool stack” working, and I have it restarting on system reboot via SMF – thanks!

I followed the steps for the installation of MySQL, and your instructions posted in ‘SMF support for MySQL in Cool Stack’. Result: MySQL run fine. When I execute ‘svcadm -v enable csk-mysql’ shows:
svc:/network/csk-mysql:default habilitado. (in English: svc:/network/csk-mysql:default enabled.).
‘svcs -a | grep my’ shows:
maintenance 14:56:36 svc:/network/csk-mysql:default
and mysql don’t start. If I use the command ‘mysqld_safe’ mysql starts ok and run fine.
could you help me?
thank you and sorry by the bad English.

David, did you notice the small typo/error I mentioned in my comment posted at 1:49 PM PDT yesterday? It has to do with the “privileges” section of the “start” method. Your descriptions sounds like my problem, and the above fixed it. I hope this helps, it worked in my case.

Actually, it shouldn’t matter whether the ‘net_privaddr’ is preceded by a bang (!) or not as far as this working. If it doesn’t have the bang, it means that the MySQL server will be able to listen on privileged ports. But since MySQL typically listens on 3306, it doesn’t need this privilege, so we can safely turn it off. Basic privileges don’t include net_privaddr, so the correct entry should be :
privileges=’basic,!proc_session,!proc_info,!file_link_any’ />
Sorry for the confusion

Why not just package DBI and DBD::mysql in? At least put them in the perl package. I have been trying for several days to get my x2100 and x2200 m2 built with mod_perl and mysql. So hard. I appended my problems to this thread
and some nice dead simple instructions for folks that are rather new to solaris, and that seemingly don’t have access to the sun compiler would be nice. Like out of the box nevada.

Hi Earl,
Sorry to hear about the problems you’re having. I’ll try and answer this on the forum. We do plan to include DBI,DBD::mysql in the next version of Cool Stack.

Thanks for the note Shanti. Any idea on release date? And while I am wishing, any chance of having blastwave compatibility? Not sure what that would entail (just using the same perl and compiler?), but since I used coolstack, I had to wget, gtar, make test, make install quite a few perl libraries. Not looking too forward to doing that on two or three more zones.
Not sure what indiana is going to bring, but hopefully a killer packaging system, so that with a single command or two, I would have my little samp stack pretty well installed.
Thanks for your very good docs on getting the mysql and apache services set up.

Which specific perl libraries are you using and for what purpose ? The more info we have on what our users need, the better able we are to support them.
Post the list on the forum so we can see if others have the same requirement.

I installed enough to get
JSON, WWW::Mechanize, Template::Alloy, CGI::Ex, Crypt::Blowfish, Cache::Memcached, XML::Simple
each for various reasons.
Which forum?

This CoolStack thing, is a good thing! You are doing a fine job. Keep up the great effort!

for mysql to start you have to :
./mysql_install_db –user=mysql –ldata=/opt/dbdir
I just thought to mention this if somebody else has problems with initial DB

On your script, about the mysql_stop () ‘function’… I’ve been setting up one server on a client and the problem is when you ‘just kill’ MySQLd, it doesn’t get a chance to shut it down properly. As a result, on the next startup of the server, it’ll have to do disaster recovery (since it kind’a crashed/got killed). Mark Demma, an SA which I work with, rewrote the shutdown part of the script as:
mysql_stop () {
if [ -f ${PIDFILE} ]; then
/opt/coolstack/mysql/bin/mysqladmin shutdown -u shutdown>/dev/null 2>&1
And yes – I’ve created a local user with only shutdown privileges on the database with the following command:
GRANT USAGE, SHUTDOWN ON *.* to shutdown@localhost;
Just my 2 cents…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Latest Tweets



%d bloggers like this: