How to register shutdown script on Amazon Linux in AWS EC2

3

1

I am using Amazon Linux (RH-based distro) in AWS EC2.

I followed the structure of /usr/share/doc/initscripts-*/sysvinitfiles to create an init script in /etc/init.d.

/etc/init.d/do_something

#!/bin/sh

# chkconfig: 3 90 10
# description: Description of the script

start () {
  echo -n "Doing something..." >> /opt/started.log
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && touch /var/lock/subsys/do_something
  return $RETVAL
}

stop () {
  echo -n "Stopping doing something..." >> /opt/stopped.log
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -rf  /var/lock/subsys/do_something
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    ;;
esac
exit $?

I can then register it with chkconfig, by doing chkconfig --add do_something. This creates a S symlink in /etc/rc3.d. However no K symlink is created. If I manually create the symlink and shutdown or restart the instance, the system script executes as expected.

What am I doing wrong and how can I get the K symlink to be generated (so that I don't have to manually create it)?

vovel

Posted 2014-06-05T19:02:07.280

Reputation: 31

Answers

0

I'm not an expert at all when it comes to SysVinit scripts. But from what I can tell, if you specify that a initscript should be started at only one runlevel (for example, runlevel 3), you will have S symlinks in /etc/rc3.d only, and K symlinks in all other /etc/rcX.d directories.

Chances are, your script is getting called with stop on shutdown; the K symlink just isn't located where you expected it to be.

BenjiWiebe

Posted 2014-06-05T19:02:07.280

Reputation: 7 672