LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-29-2010, 02:07 AM   #1
south_penguin
LQ Newbie
 
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
checking if the server safe to shutdown


Hello,

I just setup a mysql slave server, and it's running smoothly, except I should manually check if the server safe to shutdown every time I need to restart or shutdown it.

This problem is related with temporary tables that master server created, as described in mysql doc.

So, I think of making custom shell script that will automatically run each time before the slave server restart/shutdown.

The script will looks like this:
Code:
###Check the slave for Slave_open_temp_tables variable###
safe=1
(
echo "STOP SLAVE SQL_THREAD;SHOW STATUS;"
) | mysql -u USER -pPASSWORD 2>&1 | grep "Slave_open_temp_tables 0"
if [ "$?" -ne "0" ]; then
###Not Safe, need to start the sql thread###
safe=0
(
echo "START SLAVE SQL_THREAD;"
) | mysql -u USER -pPASSWORD
echo "Please try again in 30 seconds..."
fi
My question is, how to integrate this script that it will run when someone call shutdown or halt or reboot command, and when the output ("safe" variable) is 0, cancel the shutdown/restart process.
 
Old 08-29-2010, 07:42 AM   #2
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
The Linux startup and shutdown process is governed by the concept called run level. When actions such as a login, gui startup, or a shutdown occur, the run level is changed. When the system shuts down it goes to run level 0 (though I think level 6 is also a shutdown state). You can adjust the startup and shutdown process via these scripts. In my installation there are a set of directories in my /etc/ directory called rc0.d, rc1.d, etc. These are the directories that hold the run level scripts and you will have something similar, though the exact terminology may change with different distros.

In those folders are various scripts with names like S10blahblah and K20moreblah, where blah is typically a process name like postfix, apache, etc. The S scripts are called upon startup and the K scripts are called upon shutdown. The scripts are then called in order of the number with the lowest number being first. This way you can ensure things like networking are brought up before your firewall for example.

You will probably need to place your script into one or more of these sets. I haven't done this and can't give you detailed instructions, but I am certain that it is a well documented process.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to shutdown/reboot server, no shutdown process running dctw Linux - Server 5 03-31-2010 05:46 AM
How do I know if my server is safe? SuperDude123 Linux - Security 4 01-05-2009 09:59 AM
Restart after safe shutdown bahadirtonguc Linux - Hardware 1 11-23-2008 04:37 AM
Safe Shutdown hammertime1983 Linux - Newbie 9 05-29-2008 06:55 PM
Safe shutdown of external USB hard-drive? blixel Linux - Hardware 3 12-12-2003 12:57 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 02:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration