Search Our Database
How to set an automatic reboot when the server is Out of Memory (Linux)
Introduction
Running out of memory (RAM) on a server can cause severe issues, including system hangs and unresponsiveness, especially to SSH connections. In such cases, the only way to recover the server may be through a manual reboot, leading to unwanted downtime. To mitigate these issues and ensure your server remains operational, you can configure the system to automatically reboot when it encounters an out-of-memory (OOM) condition. This guide outlines the steps to set up an automatic reboot when your server runs out of memory, preventing extended periods of downtime.
Prerequisites
- SSH access to the server with root or sudo privileges.
- Familiarity with editing configuration files using a terminal-based editor like vi.
Step-by-Step Guide
Step 1: SSH into the Server
Use SSH to log into your server. Ensure you have the necessary permissions to modify system configuration files.
ssh username@server_ip_address
Step 2: Edit the sysctl.conf File
Once logged in, open the sysctl.conf file, which controls kernel parameters at runtime. Use the following command to edit the file:
vi /etc/sysctl.conf
Step 3: Add Configuration for Automatic Reboot on OOM
To configure the server to automatically reboot when it runs out of memory, add the following lines to the sysctl.conf file:
vm.panic_on_oom=1 kernel.panic=10
- vm.panic_on_oom=1: This enables the system to trigger a panic when the system encounters an OOM situation.
- kernel.panic=10: This instructs the kernel to reboot the system 10 seconds after a panic is triggered.
Step 4: Apply the Changes
After adding the configuration, save and close the file. Apply the changes by running the following command to reload the sysctl settings:
sysctl -p
This command ensures that the new configuration takes effect immediately without requiring a server reboot.
Conclusion
By configuring automatic reboot on out-of-memory conditions, you can significantly reduce the risk of prolonged downtime and ensure your server remains accessible even under high memory usage scenarios. This setup is a simple yet effective way to safeguard against server hangs, but it’s important to also monitor memory usage and address any underlying causes of memory exhaustion.
Should you have any inquiries about the guidelines, please feel free to open a ticket through your portal account or contact us at support@ipserverone.com. We’ll be happy to assist you further.