I need to backup some files every time I shutdown a Red Hat Enterprise Linux 4.
I thought about make it with a script in /etc/rc0.d
but shutdown process should wait for my script to finish. So the only idea I have is to make the script run first of all and stop shutdown process, then at the end of the script run shutdown again.
Can anyone tell me if there is any other better way to do this? Could work my own idea to make it?
Asked
Active
Viewed 1,853 times
2
-
I don't really get the problem. The server will wait for the script to finish. Otherwise shutdown would occur for all other scripts in rc6.d (which is reboot, by the way. shutdown is rc0.d) before they have completed, leading to broken mysql databases etc. – etagenklo Jul 25 '13 at 09:59
-
Hi, My mistake rc6.d, i really mean rc0.d. About rc scripts it does not work for me. Maybe i´m doing wrong, but i put K01
script in rc0.d (linked from /etc/init.d/ – Abraham Jul 25 '13 at 10:39) and it doesn´t work. The little script just try to make touch file after 120 seconds sleep. Are you sure shutdown process waits for all scripts in rc0.d? -
Is your script exectutable (chmod +x)? What's the output of `ls -la /etc/rc0.d/` ? – etagenklo Jul 25 '13 at 10:56
-
Yes is executable. – Abraham Jul 25 '13 at 10:59
-
Yes is executable. Output is: lrwxrwxrwx 1 root root 17 Apr 23 17:52 K00abcwait -> ../init.d/abcwait – Abraham Jul 25 '13 at 11:05
-
Just seen that K control scripts doesn´t start if they weren´t executed first as a service, so /var/lock/subsys/
must be created before shutdown progress. I really need only execute a script for tar and network copy some files. It must be a reasonable way to do it. – Abraham Jul 25 '13 at 11:21 -
Why not use an S script instead of K ? – etagenklo Jul 25 '13 at 12:12
-
Because K scripts are executed before S ones, so i still need network resources and the system still up before continue shutting down. – Abraham Jul 25 '13 at 13:00
-
It might also be useful to make a symlink in /etc.rc6.d so the backup script runs when the system is shutdown, or rebooted. – Brian Minton Sep 13 '13 at 18:55
-
Not in this case Brian. I need to make some backups only before shuting down, because the machine is not 24 hours powered on and dont want to make the backup if the system needs to be rebooted. – Abraham Oct 06 '13 at 02:03
2 Answers
2
I've answered this sort of question before (hint: search my previous answers; I'm on a mobile currently), but the problem you are likely facing is that an init script will not be shutdown if a the lock file has not been created (/var/lock/subsys/mything).
You can create this yourself for testing purposes, but the catch is you'll need to have this script run at startup too; just to at least create the lock.
Study something like the init script for crond
Cheers, Cameron

Cameron Kerr
- 4,069
- 19
- 25
0
It looks like there is a configurable timeout value before the script is killed. See this answer.

Brian Minton
- 266
- 7
- 15