2128N/A#!/sbin/sh
2128N/A#
2128N/A# CDDL HEADER START
2128N/A#
2128N/A# The contents of this file are subject to the terms of the
2128N/A# Common Development and Distribution License (the "License").
2128N/A# You may not use this file except in compliance with the License.
2128N/A#
2128N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2128N/A# or http://www.opensolaris.org/os/licensing.
2128N/A# See the License for the specific language governing permissions
2128N/A# and limitations under the License.
2128N/A#
2128N/A# When distributing Covered Code, include this CDDL HEADER in each
2128N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2128N/A# If applicable, add the following below this CDDL HEADER, with the
2128N/A# fields enclosed by brackets "[]" replaced with your own identifying
2128N/A# information: Portions Copyright [yyyy] [name of copyright owner]
2128N/A#
2128N/A# CDDL HEADER END
2128N/A#
6031N/A# Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
2128N/A#
2128N/A
2128N/A. /lib/svc/share/smf_include.sh
2128N/A
2128N/A# SMF_FMRI is the name of the target service. This allows multiple instances
2128N/A# to use the same script.
2128N/A
2128N/Aif [ -z $SMF_FMRI ]; then
2128N/A echo "SMF framework variables are not initialized."
2128N/A exit $SMF_EXIT_ERR
2128N/Afi
2128N/A
2128N/Agetproparg() {
2128N/A val=`svcprop -p $1 $SMF_FMRI`
2128N/A [ -n "$val" ] && echo $val
2128N/A}
2128N/A
2128N/AMYSQLCNF=`getproparg mysql/cnf`
2128N/AMYSQLBIN=`getproparg mysql/bin`
2128N/AMYSQLDATA=`getproparg mysql/data`
2128N/APIDFILE=${MYSQLDATA}/`/usr/bin/uname -n`.pid
6275N/ASTARTTIMEOUT=180
2128N/A
2128N/Aif [ -z ${MYSQLCNF} ]; then
2128N/A echo "mysql/cnf property not set"
2128N/A exit $SMF_EXIT_ERR_CONFIG
2128N/Afi
2128N/A
2128N/Aif [ -z ${MYSQLBIN} ]; then
2128N/A echo "mysql/bin property not set"
2128N/A exit $SMF_EXIT_ERR_CONFIG
2128N/Afi
2128N/A
2128N/Aif [ -z ${MYSQLDATA} ]; then
2128N/A echo "mysql/data property not set"
2128N/A exit $SMF_EXIT_ERR_CONFIG
2128N/Afi
2128N/A
2128N/Aif [ ! -d ${MYSQLDATA} ]; then
2128N/A echo "mysql/data directory ${MYSQLDATA} is not a valid MySQL data directory"
2128N/A exit $SMF_EXIT_ERR_CONFIG
2128N/Afi
2128N/A
2128N/Aif [ ! -d ${MYSQLDATA}/mysql ]; then
6275N/A echo ${MYSQLBIN}/mysql_install_db --user=mysql --datadir=${MYSQLDATA}
6275N/A ${MYSQLBIN}/mysql_install_db --user=mysql --datadir=${MYSQLDATA}
2128N/Afi
2128N/A
6275N/A# ping function which return success when mysqld starts accepting connections
6275N/A# or return failure in case of timeout after $STARTTIMEOUT seconds.
6275N/A# using this function in mysql_start(), method waits/blocks to mysqld is really ready,
6275N/A# which might take some time in case of recovery.
6275N/A
6275N/Amysql_pinger() {
6275N/A mysqld_safe_pid=$1
6275N/A timer=$STARTTIMEOUT
6275N/A ret=0
6275N/A while [ $timer -gt 0 ]; do
6275N/A sleep 1
6275N/A ${MYSQLBIN}/mysqladmin --no-defaults --socket="/tmp/mysql.sock" --user=UNKNOWN_MYSQL_USER ping >/dev/null 2>&1 && break
6275N/A timer=$(expr $timer - 1)
6275N/A
6275N/A # Check if mysqld_safe is still alive, if not there is no hope
6275N/A if ! kill -0 $mysqld_safe_pid >/dev/null 2>&1 ; then
6275N/A ret=1
6275N/A break
6275N/A fi
6275N/A done
6275N/A
6275N/A # Did we timeout?
6275N/A if [ $timer = 0 ]; then
6275N/A echo "MySQL Database start up timeout after ${STARTTIMEOUT}s"
6275N/A ret=1
6275N/A fi
6275N/A return $ret
6275N/A}
6275N/A
2128N/A# refresh method for this service is not defined because mysqld by itself
2128N/A# cannot accept a HUP signal to reload the configuration file my.cnf
2128N/A
2128N/Amysql_start() {
2128N/A echo ${MYSQLBIN}/mysqld_safe --defaults-file=${MYSQLCNF} --user=mysql --datadir=${MYSQLDATA} --pid-file=${PIDFILE}
2128N/A ${MYSQLBIN}/mysqld_safe --defaults-file=${MYSQLCNF} --user=mysql --datadir=${MYSQLDATA} --pid-file=${PIDFILE} > /dev/null &
2128N/A
6275N/A if mysql_pinger $! ; then
6275N/A echo "Starting service MySQL"
6275N/A else
6275N/A echo "Failed to start service MySQL"
6275N/A exit $SMF_EXIT_ERR
6275N/A fi
2128N/A}
2128N/A
2128N/Acase "$1" in
2128N/A'start')
2128N/A mysql_start
2128N/A ;;
2128N/A
2128N/A*)
6031N/A echo "Usage: $0 start"
2128N/A exit 1
2128N/A ;;
2128N/A
2128N/Aesac
2128N/Aexit $SMF_EXIT_OK