Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
19 lines (18 sloc) 762 Bytes
#!/bin/bash
while sleep 3; do
if [ -z $(curl -Isf http://169.254.169.254/latest/meta-data/spot/termination-time) ]; then
logger "[spot-termination-handler.sh]: spot instance termination notice not detected"
/bin/false
else
logger "[spot-termination-handler.sh]: spot instance termination notice activated"
INSTANCEID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
logger "[spot-termination-handler.sh]: detaching from elbv2"
aws elbv2 deregister-targets \
--target-group-arn %APPLICATIONLOADBALANCERTARGETGROUP% \
--targets Id=$INSTANCEID
logger "[spot-termination-handler.sh]: stopping nginx"
service nginx stop
logger "[spot-termination-handler.sh]: putting myself to sleep..."
sleep 120
fi
done
You can’t perform that action at this time.