#!/bin/sh #---------------------------------------------------------------------------- # /etc/init.d/mysql5173 - eisfair MySQL startup for eisfair-1 # # Creation: 2006-06-07 jv # Last Update: $Id$ # # Copyright (c) 2004-2010 Jens Vehlhaber, jens(at)eisfair(dot)org # Copyright (c) 2011-@@YEAR@@ Holger Bruenjes, holgerbruenjes(at)gmx(dot)net # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------- . /etc/init.d/functions # Set the default values # priority can be overriden and "-s" adds output to stderr ERR_LOGGER="logger -p daemon.err -t /etc/init.d/mysql5173 -i" # start/stop and failure message color output COLOR_RED='\033[1;31m' COLOR_NRM='\033[0;39m' my_path=5173 my_version=5.1.73 # --------------------------------------------------------------------------- # usage # --------------------------------------------------------------------------- usage() { cat <4096) }' then log_failure_msg "MySQL ERROR: The partition with "${mysql_datadir:-/srv/mysql/${my_path}}" is too full!" echo "ERROR: The partition with "${mysql_datadir:-/srv/mysql/${my_path}}" is too full!" | $ERR_LOGGER exit 1 fi } # wait if create/remove pid files wait_for_pid() { for COUNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 do case "$1" in 'created') /usr/bin/test -s ${mysql_pid_file} && break ;; 'removed') /usr/bin/test ! -s ${mysql_pid_file} && break ;; esac /usr/bin/sleep 1 echo -n "." done echo if [ ${COUNT} -gt 24 ] then log_end_msg 1 else log_end_msg 0 return 0 fi } # Safeguard (relative paths, core dumps..) # --------------------------------------------------------------------------- # start # --------------------------------------------------------------------------- mysql_start() { # check for update without database upgrade if [ -f "/srv/mysql/${my_path}/update-install" ] then log_failure_msg 'MySQL ERROR: Please run mysql config' echo 'MySQL ERROR: Please run mysql config' | ${ERR_LOGGER} exit 1 fi /usr/bin/mkdir -p -m 0755 /run/mysql /usr/bin/chown mysql:mysql /run/mysql if [ ! -f ${mysql_pid_file} ] then sanity_checks; boot_mesg -n " * Starting MySQL database server ${my_version} " # change into basedir cd /usr/lib/mysql/${my_path} ./bin/mysqld_safe \ --defaults-file=/etc/mysql/my${my_path}.cnf \ ${skip} >/dev/null 2>&1 & wait_for_pid created if [ ${?} -eq 0 ] && [ ${mysql_port:-0} = 3306 ] then cd /run/mysql ln -sf ${my_path}/mysql.sock fi else boot_mesg " * MySQL database server ${my_version} is already running ..." echo_warning fi } # --------------------------------------------------------------------------- # stop # --------------------------------------------------------------------------- mysql_stop() { # Stop daemon. We use a signal here to avoid having to know the # root password. if [ -f ${mysql_pid_file:-0} ] then boot_mesg -n " * Stopping MySQL database server ${my_version} " mysqld_pid=$(/usr/bin/cat ${mysql_pid_file}) /usr/bin/kill ${mysqld_pid} >/dev/null 2>&1 wait_for_pid removed else boot_mesg " * MySQL database server ${my_version} is not running" echo_warning fi } # --------------------------------------------------------------------------- # restart # --------------------------------------------------------------------------- mysql_restart() { mysql_stop sleep 3 mysql_start } # --------------------------------------------------------------------------- # status # --------------------------------------------------------------------------- mysql_status() { if [ ! -f ${mysql_pid_file} ] then boot_mesg " * MySQL server ${my_version} is not running" echo_warning else echo " * MySQL server ${my_version} is running" echo "____________________Server:_________________Client:_________________________" /usr/bin/netstat -a -n | /usr/bin/grep ${mysql_port} echo "" echo "____________________Internal sockets:_______________________________________" /usr/bin/netstat -a -n | /usr/bin/grep mysql/${my_path} | /usr/bin/sed -e "s/ STREAM //" fi } # --------------------------------------------------------------------------- # main # --------------------------------------------------------------------------- while [ ${#} -gt 0 ] do case "${1}" in -q|--quiet) _quiet=true shift ;; --skip) skip='--skip-grant-table --skip-networking' shift ;; *) _action=${1} shift ;; esac done case "${_action}" in start) mysql_start ;; stop) mysql_stop ;; restart) mysql_restart ;; status) mysql_status ;; *) usage exit 1 ;; esac exit 0 # --------------------------------------------------------------------------- # end # ---------------------------------------------------------------------------