Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > OS X not being "nice" to MySQL on shutdown?

OS X not being "nice" to MySQL on shutdown?
Thread Tools
chris m.
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Apr 8, 2005, 04:54 PM
 
First, let me explain our setup - we're using a Mac mini connected to an APC UPS, doing MySQL replication. The idea here is to have the mini on battery power so that replication doesn't get screwed up in the event of a power failure. So, I've also setup APCs PowerChute software to automatically shutdown the machine after a certain amount of battery life is left in the UPS (5 minutes or something like that).

Anyway, we had a power failure this morning that outlasted the battery life of the UPS. I was happily suprised to see that the machine shutdown as it was supposed to. However, the shutdown that it did did NOT shutdown MySQL nicely, I'm guessing it did a kill -9 on MySQL.

I then tried a regular (from the Apple menu) shutdown while MySQL was running (just to test and make sure that it wasn't necessarily the APC software). Same thing, MySQL is not shutdown gracefully by the OS.

This seems like a major flaw with OS X to me - I would have thought OS X would shut down all apps and processes nicely (not just the ones running in the dock!). What can be done to fix this?
     
larkost
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Apr 8, 2005, 05:42 PM
 
This should be taken care of by the script in /Library/StartupItems. That is what is responsible to take care of that. Remember, we are talking about third party software here, not Apple supplied.
     
chris m.  (op)
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Apr 8, 2005, 06:49 PM
 
Originally posted by larkost:
This should be taken care of by the script in /Library/StartupItems. That is what is responsible to take care of that. Remember, we are talking about third party software here, not Apple supplied.
Again, I also tried it with a regular Apple menu type of shutdown - not by using the APC software (in fact I tried it twice just to be sure). I'm guessing that all APC's software does is tell the OS to do a shutdown. Anyway, just doing a regular OS X shutdown (while MySQL is running) causes the MySQL tables to be left open (which is not a good thing in MySQL).

But, now that you mention StartupItems, that may be the way to go to get around this issue for now (i.e. create a ShutdownItems script that does a mysqladmin shutdown).

Still, it doesn't seem right to me that the shutdown process will not shutdown MySQL gracefully, but will do something like have BBEdit popup ask you if you want to save a document.
     
larkost
Mac Elite
Join Date: Oct 1999
Location: San Jose, Ca
Status: Offline
Reply With Quote
Apr 8, 2005, 08:52 PM
 
Once again... this is not the OS's responsibility. How is it supposed to know how to properly shutdown MySQL? That is the whole purpose of the StatupItem... and if that does not correctly shut it down, then MacOS X is not responsible. User processes are given the correct commands (a AppleEvent 'quit'), and server daemons have a well documented route to provide their proper commands, and then a final tap on the shoulder on the way out the door is also done. It is not Apple's fault that the first one is not provided and the latter is not what MySQL wants.
     
Gavin
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status: Offline
Reply With Quote
Apr 10, 2005, 04:21 AM
 
He's right, it's some problem with the StartupItems script.

How did you instal mysql?
How do you start it?
How do you stop it?



some stuff to check:

look for clues in the error log:
/usr/local/mysql/data/machine.local.err <- use your machines name for machine

Does this folder exist?

/Library/StartupItems/MySQLCOM

try this:
cat /etc/hostconfig

look for:
MYSQLCOM=-YES-

if you upgraded mysql it may have an incorrect version of the script /Library/StartupItems/MySQLCOM/MySQLCOM
When I upgraded it left the old version of the folder in place and I had to replace it by hand.

here's mine for version 4.1:

#!/bin/sh
#
# /Library/StartupItems/MySQL/MySQL
#
# A script to automatically start up MySQL on system bootup
# for Mac OS X. This is actually just a wrapper script around
# the standard mysql.server init script, which is included in
# the binary distribution.
#
# (c) 2003 MySQL AB
# Written by Lenz Grimmer <[email protected]>
#

# Suppress the annoying "$1: unbound variable" error when no option
# was given
if [ -z $1 ] ; then
echo "Usage: $0 [start|stop|restart] "
exit 1
fi

# Source the common setup functions for startup scripts
test -r /etc/rc.common || exit 1
. /etc/rc.common

# The path to the mysql.server init script. The official MySQL
# Mac OS X packages are being installed into /usr/local/mysql.
SCRIPT="/usr/local/mysql/support-files/mysql.server"

StartService ()
{
if [ "${MYSQLCOM:=-NO-}" = "-YES-" ] ; then
ConsoleMessage "Starting MySQL database server"
$SCRIPT start > /dev/null 2>&1
fi
}

StopService ()
{
ConsoleMessage "Stopping MySQL database server"
$SCRIPT stop > /dev/null 2>&1
}

RestartService ()
{
ConsoleMessage "Restarting MySQL database server"
$SCRIPT restart > /dev/null 2>&1
}

if test -x $SCRIPT ; then
RunService "$1"
else
ConsoleMessage "Could not find MySQL startup script!"
fi
     
Angus_D
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status: Offline
Reply With Quote
Apr 10, 2005, 09:14 AM
 
On any current release of Mac OS X, the stop functions of StartupItems are not invoked on shutdown.
     
chris m.  (op)
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Apr 11, 2005, 04:34 PM
 
Hi Gavin,

Thanks for information. I installed MySQL using the .pkg binary available. Normally, I fire up MySQL using the command line. I thought that this might be the problem, so I tried starting up MySQL using the pref pane that ships with the MySQL package (I'm assuming that the pref pane uses the StartupItems scripts to fire up MySQL). No luck though, the same thing happens.

Nothing in the error log either, this is why I thought MySQL was being killed by a -9 or something. Normally, MySQL will put something into the error log about receiving a sigterm. Anyway, all of the other things that you mentioned are there - the one thing I'll try though is replacing the MySQLCOM folder in the startup items. There's a newer version of MySQL out (4.1.11) so I'm going to give that a shot.

I'm also going to see what the people at MySQL have to say about this - I'm not sure yet where the issue is - MySQL or OS X (or my setup, although it's pretty much an out of the box setup).

Originally posted by Gavin:
He's right, it's some problem with the StartupItems script.

How did you instal mysql?
How do you start it?
How do you stop it?



some stuff to check:
     
chris m.  (op)
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Apr 11, 2005, 04:36 PM
 
Originally posted by Angus_D:
On any current release of Mac OS X, the stop functions of StartupItems are not invoked on shutdown.
That's interesting - is this something that Apple is going to change with Tiger?
     
P
Moderator
Join Date: Apr 2000
Location: Gothenburg, Sweden
Status: Offline
Reply With Quote
Apr 11, 2005, 05:25 PM
 
What happens if you stop MySQL with a regular kill? (Ie with the TERM signal, the default signal?) I believe that is what the OS does first, before it tries KILL (ie kill -9).
     
chris m.  (op)
Fresh-Faced Recruit
Join Date: Mar 2002
Status: Offline
Reply With Quote
Apr 11, 2005, 06:09 PM
 
Originally posted by P:
What happens if you stop MySQL with a regular kill? (Ie with the TERM signal, the default signal?) I believe that is what the OS does first, before it tries KILL (ie kill -9).
Good question - right now I'm repairing tables because I've been doing a lot of testing, but that might be worth trying. Using mysqladmin shutdown works okay.

After having done some Googling for information, I came across a thread that discussed this issue possibly being specific to replication:

http://www.entropy.ch/phpbb2/viewtopic.php?p=7005&

If this is the case (a bug in replication) it looks like it might be a MySQL issue.
     
macgyvr64
Grizzled Veteran
Join Date: Jun 2001
Status: Offline
Reply With Quote
May 5, 2005, 03:59 PM
 
I'm not sure if this is related, but I'm having trouble getting MySQL to even start. When I do sudo /Library/StartupItems/MySQL/MySQL start (using the CompleteMySQL package from Server Logistics, but it also happens with the binary from mysql.com as well), MySQL starts, then ends right after. In my G5.local.err log, the critical line I see is:

050505 15:29:17 Fatal error: Can't open privilege tables: Table 'mysql.host' doesn't exist

This is a brand new installation of MySQL. Why would the defualt tables not exist? Note that this is on two different machines, as well...both running 10.4 and MySQL 4.0.21.
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 10:21 AM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,