Why did my EC2 Linux instance reboot or restart itself?

3 minute read
1

I want to know why my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance unexpectedly reboots or restarts.

Short description

Your instance might unexpectedly reboot or restart because of the following reasons:

  • The instance fails its status checks.
  • There's an issue with the underlying hardware that's hosting your instance, and Amazon EC2 restarts the instance to move it to healthy hardware.
  • Scheduled maintenance on your instance initiates a reboot.
  • A user or application inside your server reboots the instance.
  • There's a kernel bug.

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

Check your Health Dashboard

The AWS Health Dashboard reports multiple instance reboot events, such as simplified automatic recovery, scheduled maintenance, and retirement. To act on the health notifications, either reschedule the scheduled event, or manually stop and start the instance.

View status checks

Use the Amazon EC2 console or the AWS CLI to view the instance's status checks. If a status check failed, then see Why is my EC2 Linux instance unreachable and failing its status checks?

View system logs

If the instance didn't fail a status check, then the instance might reboot because of issues with the operating system (OS). To troubleshoot OS-level issues, check the system logs that are located at /var/log/messages or /var/log/syslog.

If the instance failed the status check, then reboot the instance to retrieve the system logs. Then, troubleshoot the error that's listed in the system log.

View reboot history

To check whether a user or an application inside the server initiated the reboot, run the following command:

# grep reboot /home/*/.bash_history# grep reboot /root/.bash_history
# history | grep -i reboot
# history | grep -i init
# last reboot

View CloudTrail Event history

Instance reboots that you initiated on the Amazon EC2 console or AWS CLI appear in AWS CloudTrail Event history.

To view these events, complete the following steps:

  1. Open the CloudTrail console.
  2. In the navigation pane, choose Event history.
  3. On the dropdown list, choose Event name, and then enter RebootInstances.
    Note: When you create an Amazon Machine Image (AMI), the NoReboot parameter is set to false by default. Because Amazon EC2 automatically reboots the instance before it creates the image, the reboot appears in the CreateImages trail, not the RebootInstances trail.

Note: You can configure Amazon CloudWatch action based recovery to automatically recover instances that are experiencing hardware issues that reboot your instance.

Update your kernel

To update the kernel, run one of the following commands depending on your Linux OS and version:

sudo yum update kernel
sudo zypper up kernel-default
sudo apt upgrade linux-image-aws

Related information

Troubleshoot Amazon EC2 Linux instances with failed status checks

Types of status checks

Configuring AWS User Notifications for AWS Health

AWS OFFICIAL
AWS OFFICIALUpdated 4 months ago