Solved

Linux runlevel 0 question

Posted on 2011-09-22
6
575 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
nagios remote hosts 9 43
php ssh2_scp_send 1 47
mcrypt_create_iv() is deprecated 4 70
How to Remove files with a Date in the Filename with Linux Scripting 3 27
In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
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…
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.

911 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

20 Experts available now in Live!

Get 1:1 Help Now