- 论坛徽章:
- 0
|
摘自《sun技术论坛》
Configuring MySQL to Use With Service Management Facility (SMF)
William Pool (Puddle), October 2005
The Solaris 10 OS uses the Service Management Facility (SMF) to handle services. Traditional means like /etc/rc?.d scripts still work, but as a legacy means. (For more information on SMF, see the References section.)
To take advantage of the SMF in the Solaris 10 OS using MySQL, follow these steps.
Note: Read the scripts and "change" the path of MySQL or MySQL's data-directory accordingly!
If you haven't initialized the MySQL database, do that first:
/opt/sfw/bin/mysql_install_db
This will install the database into /var/mysql to override that use:
/opt/sfw/bin/mysql_install_db -ldata=/opt/sfw/var/mysql
Note: If you change the location, change the information below!
First create a mysql group:
/usr/sbin/groupadd mysql
Then create the mysql user:
/usr/sbin/useradd -s /bin/false -g mysql -d /var/mysql -c "MySQL User" mysql
Create a service manifest file:
/var/svc/manifest/network/mysql.xml
This contains the following:
William Pool (Puddle) 02/05
Service manifest for MySQL
E-mail:
puddle@flipmotion.com
-->
Now create your "Service Method File" in /lib/svc/method called svc-mysql:
#!/usr/bin/sh
#
# William Pool (Puddle) 01/05
# SMF Method file for MySQL
# E-mail:
puddle@flipmotion.com
#
# This uses Sun's default MySQL packages
# SUNWmysqlu SUNWmysqlr
#
# Modify accordingly!
#
# NOTE: Make sure DB_DIR is owned BY the mysql user and group and chmod
# 700.
#
.. /lib/svc/share/smf_include.sh
DB_DIR=/var/mysql
PIDFILE=${DB_DIR}/`/usr/bin/uname -n`.pid
case "$1" in
start)
/usr/sfw/sbin/mysqld_safe --user=mysql --datadir=${DB_DIR} --pid-file=${PIDFILE} > /dev/null &
;;
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
;;
'restart')
stop
while pgrep mysqld > /dev/null
do
sleep 1
done
start
;;
*)
echo ""
echo "Usage: `basename $0` { start | stop | restart }"
echo ""
exit 64
;;
esac
#---EOF
Now fix the permissions for the two files created:
chown root:bin /lib/svc/method/svc-mysql
chmod 555 /lib/svc/method/svc-mysql
chown root:sys /var/svc/manifest/network/mysql.xml
chmod 444 /var/svc/manifest/network/mysql.xml
Fix permissions on the MySQL data directory:
chown -R mysql:mysql /var/mysql
chmod -R 700 /var/mysql
Import the service into the service repository:
# svccfg import /var/svc/manifest/network/mysql.xml
Enable the service:
# svcadm -v enable mysql
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/14514/showart_97258.html |
|