Discussion Locked

Running a script at shutdown and reboot

0 helpful
6 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I would like to run a script I have, upon shutdown or reboot, to shutdown my database on a RH 6.1 Linux. I created a symbolic link in the /etc/rc.d/rc0.d and rc6.d directories that point to a file in /etc/rc.d/init.d. I named the file something like K95dbshut in the two rc* directories. These files was linked to a file called dbshut, located in my /etc/rc.d/init.d directory.

I thought this was how to execute things upon shutdown and restart, but it does not seem to be executing the script.

Please let me know if this way is correct or if I should be doing something else. Thanks.

6 replies

by zbrain75

What you did appears correct, however for runlevels 0(halt) and 6(reboot), you may want the filename to be something like K15dbshut so it is shutdown early in the process.
You may need to put something like S95dbshut (or whatever the name of the startup script is) in the /etc/rc.d/rc3.d and rc6.d directories.
Also you may not have written your script in /etc/rc.d/init.d correctly. It needs to accept the strings start, stop, restart, and status on the command line. Read the script /etc/rc.d/init.d/gated or one like it that starts a program for a good example of how to do this. Also to see how they are called read the /etc/rc.d/rc script program.
If your script is written correctly you should be able to start it with the command "/etc/rc.d/init.d/myscript start" and stop it with "/etc/rc.d/init.d/myscript stop". Also there are various Linux howtos. Look for them at http://www.linuxdoc.org. Somewhere I saw a howto that gives an example of how to write a start and stop script file, but can't find it

by cp409sd

Is there an easier way to do this? I have a script that runs on bootup that starts the database. I apended a few lines to the end of the rc.local file and it runs after all the other services start and I did not have to worry about the script accepting start, stop restart, etc. strings. Is there something of the sorts for making a script work for reboots and shutdowns, or do I just have to invest the time in creating a script that accepts these things?

by cp409sd

Is there an easier way to do this? I have a script that runs on bootup that starts the database. I apended a few lines to the end of the rc.local file and it runs after all the other services start and I did not have to worry about the script accepting start, stop restart, etc. strings. Is there something of the sorts for making a script work for reboots and shutdowns, or do I just have to invest the time in creating a script that accepts these things?

by miked

besides the things already mentioned ...

have you tried to execute the script directly to verify it works?

Also check permissions to be sure that the system can execute them too (not just root)

MikeD

by cp409sd

The script itself works, but as mZehner mentioned I guess the script has to accept start, stop, etc. parameters in order to work on shutdown and reboot, and mine does not do this. Any ideas how to how to do this besides creating a script that accepts these params?

by cp409sd

The script itself works, but as mZehner mentioned I guess the script has to accept start, stop, etc. parameters in order to work on shutdown and reboot, and mine does not do this. Any ideas how to how to do this besides creating a script that accepts these params?

This discussion is closed to new replies.