LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 03-02-2011, 04:34 PM   #1
Richard Rahl
Member
 
Registered: Aug 2006
Location: Cape Breton, D'Hara
Distribution: Ubuntu, Redhat
Posts: 83

Rep: Reputation: 15
Shutting down of daemons during Ubuntu shutdown


Hello,

I'm interested in finding out, specifically, what causes daemon's to be shutdown when I shutdown Ubuntu?

I'm use Ubuntu which is why I'm posting here, but I suppose this knowledge could apply to other Disto's too.

Perhaps I'm better off to explain with an example:

I wrote a C++ that queries a Mysql database. I want it to run every time the computer is shutdown.

I've verified the program works fine, and I've verified that I can run a program on shutdown of the computer by putting it in /etc/rc0.d

The problem is that by the time rc0.d runs my program, mysql has already been shutoff, and it can't connect.

So what I'm wondering is, is there a script or something at a higher level that goes around turning things like daemons as the System shutdowns, but before any of the scripts in rc0.d are run? (It doesn't look like anything in here is shutting down mysql). Something that actually calls mysql shutdown?

If so, I'm hoping someone could point me to it and I can add my program to be run before mysql shuts down.

Otherwise, I might end up having to get the source code compile by own /sbin/shutdown and tweak it from there. Granted I might end up doing this anyway because there's more stuff I want to customize during shutdown (e.g. abort it under certain conditions), but I'm hoping not to go that far just yet.

Any suggestions, please let me know. Thanks!
 
Old 03-02-2011, 07:25 PM   #2
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,700

Rep: Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895Reputation: 5895
In a nutshell the files in rc0.d are links to the actual scripts in /etc/init.d. The links start with either a KXX or SXX. The K i.e kill run first in order from 99 - 1 and stop the associated process. The SXX i.e. start runs second in numerical and will start the associated process. If you configure your script to start in runlevel 0 with a value of 1 (filename S01myscript) it will run first before anything else shuts down.

http://www.debuntu.org/how-to-manage...th-update-rc.d
https://help.ubuntu.com/community/UbuntuBootupHowto

sendsigs is the global command to shut down running processes.

Last edited by michaelk; 03-02-2011 at 07:31 PM.
 
Old 03-02-2011, 08:19 PM   #3
Richard Rahl
Member
 
Registered: Aug 2006
Location: Cape Breton, D'Hara
Distribution: Ubuntu, Redhat
Posts: 83

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by michaelk View Post
In a nutshell the files in rc0.d are links to the actual scripts in /etc/init.d. The links start with either a KXX or SXX. The K i.e kill run first in order from 99 - 1 and stop the associated process. The SXX i.e. start runs second in numerical and will start the associated process. If you configure your script to start in runlevel 0 with a value of 1 (filename S01myscript) it will run first before anything else shuts down.

http://www.debuntu.org/how-to-manage...th-update-rc.d
https://help.ubuntu.com/community/UbuntuBootupHowto

sendsigs is the global command to shut down running processes.
Hi there, thanks for the response.

I did know about the symlinks and the run levels. Unfortunately even linking my script as S01script name doesn't work. As a test, one of the things the script does is append the output of "ps -ef | grep mysql" to a file in my Home directory. When I check the file after rebooting, all I see is the grep process, making it clear that mysqld isn't running when the script runs.

Your post did give me another idea though. Instead of using the Sxx scripts, I tried using a Kxx script to run my program instead.

Likewise, I did the same test by appending the output "ps -ef | grep mysql" to a file. This time, I do indeed see the mysqld process is still running when the KXXscript runs. Great. Unfortunately, my program still can't connect.

It connects fine when the system isn't shutting down. So there must be something else preventing it from connecting when being run from the KXX script, even though mysqld is still running at the point. I'll need to investigate this further, but in the meantime if anyone has any other suggestions let me know.

Thanks!
 
  


Reply

Tags
mysql, shutdown, ubuntu



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
i hv to manually press the power button on shutdown after all daemons have been stopp alice_neo Linux - Software 6 09-12-2007 02:55 PM
Database doesn't shutdown during shutting down the server shipon_97 Linux - Enterprise 0 08-11-2007 11:12 AM
Shutdown not shutting down completely jrdioko Linux - Newbie 19 10-12-2003 11:47 AM
Connection not shutting down on shutdown or restart tyrann Linux - Networking 2 07-12-2003 11:46 AM
determining and shutting down daemons Goatdemon Linux - General 7 09-17-2002 03:19 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 08:21 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