Created
February 28, 2014 15:03
-
-
Save campbellwmorgan/9272628 to your computer and use it in GitHub Desktop.
A template for a shutdown init.d script (tested on RHEL)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# shutdownscript - a template for a script that will run on shutdown | |
# chkconfig 2345 99 01 | |
# write the name of the file (which will be the daemon here) | |
scriptname="shutdownscript" | |
# installation instructions: | |
# - save this script in /etc/init.d/[yourscriptname] | |
# - chown root:root [yourscriptname] | |
# - chmod 755 [yourscriptname] | |
# register it with chkconfig: | |
# - chkconfig --add /etc/init.d/[yourscriptname] | |
# - chkconifg [yourscriptname] on | |
# start the new daemon | |
# service [yourscriptname] start | |
case "$1" in | |
start) | |
# need to write a lock file in /var/lock/subsys in order for the shutdown script | |
# to be registered on shutdown | |
echo "Registering shutdown script $scriptname" | |
touch "/var/lock/subsys/$scriptname" | |
;; | |
stop) | |
# first remove lock file | |
rm -f "/var/lock/subsys/$scriptname" | |
# now write your bash logic here..... | |
echo "this is my logic ...." | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment