Skip to content

Instantly share code, notes, and snippets.

@netoht
Created August 29, 2020 04:44
Show Gist options
  • Select an option

  • Save netoht/fd6d51c62115e1efb26ac007c2707482 to your computer and use it in GitHub Desktop.

Select an option

Save netoht/fd6d51c62115e1efb26ac007c2707482 to your computer and use it in GitHub Desktop.

Revisions

  1. netoht created this gist Aug 29, 2020.
    11 changes: 11 additions & 0 deletions user-data.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # 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