General discussion

  • Creator
    Topic
  • #2075537

    Running a script at shutdown and reboot

    Locked

    by cp409sd ·

    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.

All Comments

  • Author
    Replies
    • #3783796

      Running a script at shutdown and reboot

      by zbrain75 ·

      In reply to Running a script at shutdown and reboot

      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

      • #3783558

        Running a script at shutdown and reboot

        by cp409sd ·

        In reply to Running a script at shutdown and reboot

        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?

      • #3783556

        Running a script at shutdown and reboot

        by cp409sd ·

        In reply to Running a script at shutdown and reboot

        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?

    • #3783565

      Running a script at shutdown and reboot

      by miked ·

      In reply to Running a script at shutdown and reboot

      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

      • #3783559

        Running a script at shutdown and reboot

        by cp409sd ·

        In reply to Running a script at shutdown and reboot

        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?

      • #3783557

        Running a script at shutdown and reboot

        by cp409sd ·

        In reply to Running a script at shutdown and reboot

        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?

Viewing 1 reply thread