I'm working with a software application that's a bit touchy so I wan't to shut the software down automatically on reboot or shutdown. I have created a script an placed it in /etc/init.d/ with a symlink in /etc/rc6.d and named it "K99_restofname". The script works great testing it outside of a reboot scenario. The process takes close to a minute to do its work. I do not think its being ran or working when I reboot because the system shuts down way to fast and I should see a delay while the script works. (I'm also watching the screen) I also do not see anything in the logs. Here is my script:


## # Any subsequent(*) commands which fail will cause the shell     script to exit immediately

echo >&2 '
*** ABORTED ***
echo "An error occurred. Exiting..." >&2
exit 1

trap 'abort' 0

set -e

## Stopping the application services before the system shuts down. This   must be done by the application user user. 

VAR=`/bin/su -c "/opt/app/bin/command stopall" - user`

echo $VAR


trap : 0

echo >&2 '
*** DONE *** 

Can anyone tell me what might be going on or how I can track down custom shutdown scripts? Is there a better way to accomplish my goal than this? My system is RHEL 6 server.


Change the K99 to S00_ or mv S01reboot Sxxreboot and make your script S01.

What I did was to create a script:

echo "Ran S10" >> /var/tmp/done

and called it "S10Test"

then another:

echo "Ran K10" >> /var/tmp/done

Then I rebooted my VM.

/var/tmp/done contained "S10"

You may want to test yourself.

What I suspect is happening is that the S scripts run as you enter the runlevel. The K scripts run as you leave. Since S01Reboot (original name) does a reboot there is no "leave".

(note "suspect").

  • I've since added chkconfig params to my script with the following: chkconfig: 12345 91 06. I also have corresponding files in all rc.d locations. S91 links in rc1-5, and K06 links in rc0/6. Still not working on shutdown. Startup works fine. – user53029 May 4 '16 at 21:35
  • That is because the S scripts run as you ENTER the runlevel and the K scripts run as you LEAVE the runlevel. You never LEAVE runlevel 6 because S01reboot rebooted. – Petro May 10 '16 at 15:02

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.