5

I'm trying to create some script that should run on start.

Now I've created some myScript file under the /etc/init.d/ and then run sudo chkconfig --add myScript;

chkconfig --list myScript output is:
myScript 0:off 1:off 2:on 3:on 4:on 5:on 6:off

myScript:

#!/bin/sh
# chkconfig: 2345 98 02
# description:
# processname:

# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 0
fi
KIND="_"

start() {
   echo starting `date` >> ~/myScript.log
}

stop() {
   echo stopping myScript
}

restart() {
   echo restarting
}

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

Now I can successfully run service myScript start and log record will be appended. But if I run sudo reboot or restart the instance with AWS UI console it doesn't work as was expected.

Although runlevel output is:
N 3

Need some help.

-1

Your chkconfig configuration will work if you shutdown your instance.

I had created a test script on my machine and it works if I shutdown the instance and doesn't work when I restart it.

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.