起動時に実行する必要があるいくつかのスクリプトを作成しようとしています。
これで、/etc/init.d/の下にmyScriptファイルを作成して実行しました。 sudo chkconfig --add myScript;
chkconfig --list myScript
出力は次のとおりです。myScript
0:off 1:off 2:on 3:on 4:on 5:on 6:off
私のスクリプト:
#!/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 $?
これで正常に実行でき、service myScript start
ロギングが添付されます。ただし、sudo reboot
AWS UI コンソールを使用してインスタンスを実行または再起動すると、期待どおりに機能しません。
runlevel
出力は次のとおりです。
N 3
助けが必要です。
ベストアンサー1
あなたがインスタンスの場合、chkconfig
設定は機能しますshutdown
。
私のコンピュータにテストスクリプトを作成し、インスタンスを終了すると機能しますが、再起動すると機能しません。