#!/bin/ksh # $Id: initd.script,v 1.4 2003/05/31 17:30:05 elkner Exp $ # # description: Mysql database start/stop script. # # default: S/K10 0/K10 1/K10 2/S89 . /lib/svc/share/smf_include.sh # Set some defaults BASEDIR=@CLIENT_BASEDIR@/mysql BINDIR=${BASEDIR}/bin PARAMS="" CONF="" MULTI=`/usr/bin/svcprop -p 'mysqld/multi' $SMF_FMRI 2>/dev/null` if [ "$MULTI" = "true" ]; then STARTER="${BINDIR}/mysqld_multi" # stupid script searches the PATH for my_print_defaults export PATH="${BINDIR}:${PATH}" else STARTER="${BINDIR}/mysqld_safe" CONF=`/usr/bin/svcprop -p 'mysqld/no_defaults' $SMF_FMRI 2>/dev/null` if [ "$CONF" = "true" ]; then PARAMS="--no_defaults" fi fi CONF=`/usr/bin/svcprop -p 'mysqld/defaults_file' $SMF_FMRI 2>/dev/null` if [ -n "$CONF" -a -r "$CONF" ]; then if [ "$MULTI" = "true" ]; then PARAMS="${PARAMS} --config-file=$CONF" else PARAMS="${PARAMS} --defaults-file=$CONF" fi fi if [ "$MULTI" != "true" ]; then CONF=`/usr/bin/svcprop -p 'mysqld/extra-defaults-file' $SMF_FMRI 2>/dev/null` if [ -n "$CONF" -a -r "$CONF" ]; then PARAMS="${PARAMS} --extra-defaults-file=$CONF" fi fi STOP_TIMEOUT=`/usr/bin/svcprop -p 'stop/timeout_seconds' $SMF_FMRI 2>/dev/null` if [ -z "$STOP_TIMEOUT" ]; then STOP_TIMEOUT=10 fi MY_USER=`/usr/bin/svcprop -p 'start/user' $SMF_FMRI 2>/dev/null` # actually the MY_USER could have been set to root and than switched to another # one via config file, but this case is unsupported (i.e. we do not try to do # the same work, what the starter scripts actually do - in this case we # wouldn't need them at all ;-)). if [ -z "$MY_USER" -o "$MY_USER" = "root" ]; then echo "Running this service as root is unsupported! Change the user with: svccfg setprop start/user=myslq $SMF_FMRI " exit $SMF_EXIT_ERR_FATAL fi case $1 in start) if [ -n "$CONF" ]; then echo "Using $CONF" fi if [ -x "${STARTER}" ]; then print "Starting mysql daemon." "${STARTER}" ${PARAMS} & else echo "Unable to execute ${STARTER}" exit $SMF_EXIT_ERR_FATAL fi ;; stop) PIDS=`pgrep -u $MY_USER mysqld` if [ -n "$PIDS" ]; then print -n "mysqld shutdown ..." pkill -u $MY_USER mysqld else echo "mysqld is not running." exit $SMF_EXIT_OK fi COUNT=0 while [ -n "$PIDS" -a $COUNT -lt $STOP_TIMEOUT ]; do print -n "." sleep 1 PIDS=`pgrep -u $MY_USER mysqld` if [ -n "$PIDS" ]; then pkill -u $MY_USER mysqld COUNT=$((COUNT+1)) else print " Done." sync exit $SMF_EXIT_OK fi done echo "mysqld does not wanna die - giving up :(" ;; *) echo "Usage: $0 {start|stop}" exit $SMF_EXIT_ERR_OTHER ;; esac