?
Solved

Linux runlevel 0 question

Posted on 2011-09-22
6
Medium Priority
?
612 Views
Last Modified: 2012-05-12
Hi,
    I need to have a script run at shutdown that saves some log files from ramdisk to Compact Flash, so they will be there on next bootup.(I keep them in ramdisk so as not to abuse the CF)

I thought I could just do this by having a script in /etc/rc.d/init.d, and the having it get called when i went into runlevel 0, like so...
      K09save_logs -> ../init.d/save_logs

But when it would not work, I, (O.K. my boss), finally figured out that whatever program excutes the Kill, first checks to see if there is a process called "save_logs" running. Since there is no process, it does not bother calling the script.

Is there some simple way to override this behavior,(i.e force the runlevel change to execute the script) or must I write a little process called "save"logs",that just sits there so it can be found at shutdown time?

                            Thanks.
                            Steve
0
Comment
Question by:slats52
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:sakman
ID: 36581612
Did you put K09save_logs in /etc/rc.d/rc0.d?  

If so, the scripts in rc0.d should be executed as the system is shutting down.

If not, and you put the script in /etc/rc.d/init.d, then you should create a link for that script in rc0.d
0
 

Author Comment

by:slats52
ID: 36581801
Hi sakman,
    Thanks for the quick response.

Yes, I did put the symbolic link it rc0.d. I implied that by showing showing the link in my message, but I should have spelled it out better.

What I have is;
     The sym link. --->                     /etc/rc.d/rc0.d/K09save_logs -> ../init.d/save_logs
     and the script --->                   /etc/rc.d/init.d/save_logs

But what I found, by a lot of trial and error, is that the program (presumably 'init', actually looks for a running process with the same name as your sym link (minus of course the Kxx).
  So, in other words it looks for a process named 'save_logs'. Since there is no actual running process by this name, it does NOT bother to execute the script.
I proved this by making a sym link (in rc0.d) named "K09sshd --> ../init.d/save_logs". Now, since 'init' found that 'sshd' was, in fact runnig, it gladly excuted my script.

   I hope i've made this more clear.

                  Steve


 


0
 
LVL 4

Accepted Solution

by:
sakman earned 2000 total points
ID: 36581870
OK.  

Maybe you can add your routine or call your script from /etc/init.d/halt (/etc/rc.d/rc0.d/S01halt) - that script is executed during shutdown.
0
Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

 
LVL 4

Expert Comment

by:sakman
ID: 36581913
Or - rename your script with an "S" - so that it is run when entering run level 0.  Since halt is "S01", you might need to rename S01halt to S02halt and then name your script to S01save_logs so it runs first.  

Just be careful when fooling around with basic system startup/shutdown scripts.
0
 

Author Closing Comment

by:slats52
ID: 36582004
GREAT ideas sakman!

   I was already in the midst of trying your first idea when the second one came through.

 It worked like a charm.

 I have no doubt the second idea will work also.

 

                       Many thanks for your ideas...
                       Steve

P.S. You saved me an afternoon of writing a stupid process to just sit there and do nothing. (the way I was going to tackle the problem).
     Sometimes you just don't see the forest through the trees...
0
 
LVL 4

Expert Comment

by:sakman
ID: 36582023
Cool.  Glad I could help.  Yeah I know all about forest and trees - sometimes I don't even see that the forest is on fire!

BTW, if you decide to rename the S01halt script - remember it's a link.  So probably delete it and then relink /etc/init.d/halt to S02halt.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question