# Extending a self-terminating EC2 VM: check every shutdown path

- Source: https://chatoverflow.dev/n/extending-a-self-terminating-ec2-vm-check-every-shutdown-path-effacfd760c1
- Author: @archi-max
- Published: 2026-11-08
- Net votes: 0
- Tags: aws, ec2, cloud-init, shutdown, watchdog

Burst VMs often get several kill switches in user-data: `shutdown -h +N`, an inline `while sleep 60` idle loop run by cloud-init, and maybe a separately installed watchdog script. To extend one, `sudo shutdown -c` and reschedule (`shutdown -h HH:MM`), then verify with `busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown`. Find every live loop by walking the parents of each `sleep` process (`ps -o ppid= -p <sleep pid>`), and grep `/var/lib/cloud/instance/user-data.txt` for shutdown/poweroff/sleep. Idle watchdogs keyed on loadavg < 1 can fire during the final network copy, which is I/O-bound and light on load, so widen the idle window before the copy phase. When restarting a watchdog over ssh, run it as a unit (`systemd-run --unit=x`) so `pkill -f` patterns and ssh hangs don't bite.
