External EC2 watchdog that runs on a separate instance and uses only AWS EC2 status signals to decide when to reboot a target instance.
Python requirement: 3.10+.
- polls
DescribeInstanceStatusfor one target instance - reads
InstanceState.Name,InstanceStatus.Status,SystemStatus.Status - reboots only after continuous
InstanceStatus=impairedfor a threshold - enforces reboot cooldown to avoid reboot loops
- performs startup self-test (
DescribeInstances+ reboot dry-run permission) - keeps running through transient AWS API errors
- does not call
/health - does not check
pixop-live,systemctl, logs, process state, or SSH - does not infer application health from runtime behavior
This watchdog is Layer 2 only (EC2/OS recovery). Layer 1 app recovery should be handled by a local watchdog on the target host.
Required:
AWS_REGIONTARGET_INSTANCE_ID
Optional defaults:
CHECK_INTERVAL_SECONDS=30IMPAIRED_THRESHOLD_SECONDS=300REBOOT_COOLDOWN_SECONDS=1800LOG_LEVEL=INFOREBOOT_ON_SYSTEM_STATUS_IMPAIRED=false
Reboot condition (default behavior):
- instance state is
running InstanceStatus.Status == impaired- impairment duration >=
IMPAIRED_THRESHOLD_SECONDS - cooldown expired
SystemStatus=impaired is logged; reboot on system impairment is optional and
disabled by default.
cp .env.example .env
./run-local.shOr run manually:
python3.10 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
source .env
python3 -m ec2_watchdog.watchdogMinimum actions:
-
ec2:DescribeInstances -
ec2:DescribeInstanceStatus -
ec2:RebootInstances -
Example policy:
iam-policy-example.json -
Full IAM setup guide:
IAM_SETUP.md
Use the installer:
sudo ./scripts/install-systemd.shThis installs to /opt/ec2-watchdog, creates /etc/ec2-watchdog/ec2-watchdog.env
if needed, creates the venv with Python 3.10+, and enables
ec2-watchdog.service.
Useful commands:
sudo systemctl status ec2-watchdog
sudo journalctl -u ec2-watchdog -fIf you hit venv permission errors, fix ownership and recreate venv as the service user:
sudo chown -R ec2-watchdog:ec2-watchdog /opt/ec2-watchdog
sudo -u ec2-watchdog python3.10 -m venv /opt/ec2-watchdog/.venv
sudo -u ec2-watchdog /opt/ec2-watchdog/.venv/bin/pip install -r /opt/ec2-watchdog/requirements.txtDetects/responds to:
- EC2 instance status check impairment
- persistent guest/instance-level problems surfaced by AWS checks
Does not detect/respond to:
- app deadlocks,
/healthfailures, or service-level quality/performance issues
Use local watchdog + app observability for those.