?
Solved

Linux runlevel 0 question

Posted on 2011-09-22
6
Medium Priority
?
622 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 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Fine Tune your automatic Updates for Ubuntu / Debian
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
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.:
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

809 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