Does Reboot command invoke scripts in /etc/rc0.d/ directory?

I need to kill some services when shutdown/reboot my Linux server, but I am not sure how Reboot command works.

To my understanding, /etc/rc0.d/ scripts will be invoked when system is shutdown, while the /etc/rc6.d/ scripts will be invoked when system is rebooted.

But according to this link: , reboot command also call shutdown command except when running on level 0 and 6, so does this mean /etc/rc0.d/ scripts are also invoked when reboot command is run ?

Do I only need to put the service kill script into /etc/rc0.d/ and /etc/rc1.d/ ? Or does it also need to be in /etc/rc6.d/ to make sure the service is stopped when reboot ?

Edit: Add my server configuration. Currently running Redhat, varying from 6.x to 7.2.

4

1 Answer

If you just want to kill some processes the way you want when you're shutting down , you can write two simple scripts as follows :

#Shutdown.sh
killall blah blah blah
init 0

and

#Reboot.sh
killall blah blah blah
init 6

and make some aliases in the .bashrc file of each user you log-in as :

alias shutdown_custom="Shutdown.sh"
alias reboot_custom="Reboot.sh"

and run those commands each time you want to reboot ( or shutdown)

But if you insist to use a init script , you can put your script in the /etc/init.d directory and issue the following command (with super-user permission) :

update-rc.d script-name enable 0 6 

But be aware that you should mention the runlevels in the header of your script . For example this can be found for most linux services :

# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6

In my system the contents of /etc/rc0.d and /etc/rc6.d is exactly the same , so looks like shutting down and rebooting is the same from the systemd's perspective.

If anybody has a better solution I'm glad to hear.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like