当停止实例时,如何自动从其 LoadBalance(ELB)中删除实例?
我尝试创建一个关机脚本并将其放在 chkconfig 上,但是它不起作用:
#!/bin/bash
# loggly authorization
#
# chkconfig: 2345 20 10
# description: add host logs to loggly
# Source function library.
. /etc/init.d/functions
. /etc/profile.d/aws-apitools-common.sh
LB=MyLB
OK="\033[60G\e[0;32mOK\e[0m"
EC2_INSTANCE_ID="`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id || die \"wget instance-id has failed: $?\"`"
export JAVA_HOME=/usr/java/default
start() {
echo "started service"
}
stop() {
echo "removing $EC2_INSTANCE_ID from Load Balancer"
elb-deregister-instances-from-lb $LB --instances=$EC2_INSTANCE_ID -I $AWS_ACCESS_KEY_ID -S $AWS_SECRET_ACCESS_KEY --quiet
sleep 20
}
restart() {
stop
sleep 5
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
exit $?
答案1
必须有一个/var/lock/subsys/my_app
文件
将 atouch /var/lock/subsys/my_app
放在启动函数中,将 arm /var/lock/subsys/my_app
放在停止函数中