Skip to content

Instantly share code, notes, and snippets.

@marckysharky
Last active October 17, 2016 15:49
Show Gist options
  • Save marckysharky/69b4930fe087d47dd9d8b7018d40b44c to your computer and use it in GitHub Desktop.
Save marckysharky/69b4930fe087d47dd9d8b7018d40b44c to your computer and use it in GitHub Desktop.
Example `init.d` script for hooking into the system shutdown
#cloud-config
write_files:
- path: /etc/init.d/on-shutdown
owner: root:root
permissions: '0755'
content: |
#!/bin/sh
#
# /etc/init.d/on-shutdown
#
# chkconfig: 12345 95 02
# description: Execute on shutdown
#
### BEGIN INIT INFO
# Provides: on-shutdown
# Required-Start: $local_fs
# Default-Start: 1 2 3 4 5
# Default-Stop: 0 6
# Short-Description: Execute script on system shutdown
### END INIT INFO
. /etc/init.d/functions
EXEC_NAME=on-shutdown
LOCK_FILE=/var/lock/subsys/$EXEC_NAME
LOG_FILE=/var/log/on-shutdown.log
RET_VAL=0
start() {
touch $LOCK_FILE
touch $LOG_FILE
echo
}
stop() {
echo 'Stopping on-shutdown' >> $LOG_FILE
rm -rf $LOCK_FILE
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo $"Usage: $0 {start|stop}"
;;
esac
exit $RET_VAL
runcmd:
- 'chkconfig --add on-shutdown && service on-shutdown start'
#!/bin/sh
#
# /etc/init.d/on-shutdown
#
# chkconfig: 12345 95 02
# description: Execute on shutdown
#
### BEGIN INIT INFO
# Provides: on-shutdown
# Required-Start: $local_fs
# Default-Start: 1 2 3 4 5
# Default-Stop: 0 6
# Short-Description: Execute script on system shutdown
### END INIT INFO
. /etc/init.d/functions
EXEC_NAME=on-shutdown
LOCK_FILE=/var/lock/subsys/$EXEC_NAME
LOG_FILE=/var/log/on-shutdown.log
RET_VAL=0
start() {
touch $LOCK_FILE
touch $LOG_FILE
echo
}
stop() {
echo 'Stopping on-shutdown' >> $LOG_FILE
rm -rf $LOCK_FILE
echo
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo $"Usage: $0 {start|stop}"
;;
esac
exit $RET_VAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment