Created
August 29, 2020 04:44
-
-
Save netoht/fd6d51c62115e1efb26ac007c2707482 to your computer and use it in GitHub Desktop.
AWS EC2 user-data error handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# error handling | |
# redirect logs so can be found in instance -> actions -> instance settings -> Get System log | |
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 | |
# trap errors. Shutdown restarts machine in an hour and prevents further commands, | |
# so instances won't finish booting and won't report to ECS | |
function my_trap() | |
{ | |
echo "Sorry, there was an error at line $1 $2" && shutdown -h +60 | |
} | |
trap 'my_trap $${LINENO} $$? ' ERR | |
# /error handling |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment