Solved

Linux runlevel 0 question

Posted on 2011-09-22
6
566 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
  • 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 500 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now