I am currently running a script at startup using /etc/rc.local. The problem is that during shutdown, it does not exit gracefully. This can cause (important) data loss. My script has a SIGINT handler to finish all jobs before exiting, is there any way to start the script during startup AND send a SIGINT to the script (and wait for it to finish) before shutdown?

Note: I could manually send a SIGINT to the script before shutting it down but I will not be administrating this server and there's no telling what someone in the future might do.


First, chmod +x to your script.Thensudo ln -s yourscript /etc/init.d/somename, sudo ln -s /etc/init.d/somename /etc/rc0.d/K88somename.When you input init 0 to shutdown the machine,your script will be executed. The same to rcX.d,X means the runlevel. My OS is Ubuntu 14.04 LTS。 In my OS,it work as i wish(maybe other also be fine,but i don't try).

|improve this answer|||||
  • 1
    I read a bit about rc[0-6]. I'm assuming it waits for the script in the rc0.d directory to complete before shutdown? Does shutdown also encompass restarts? – Mocking Apr 15 '16 at 6:44
  • @Mocking Does shutdown also encompass restarts?NO! If you input "init 0",the rc0.d whill be exec.If you input "reboot",the rc6.d whill be exec – user164825 Apr 18 '16 at 3:09

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.