Rebooting on OOM

From LinodeWiki

Jump to: navigation, search

In some situations, it may be beneficial to have your Linode automatically reboot if it runs out of memory. You can leverage a couple kernel settings and Lassie to make this happen.

NOTE: This is an inherently unclean reboot. You will encounter disk corruption or other tragedies if this occurs at a bad time. Additionally, if you end up in a situation where you run out of memory right after boot, you'll enter an unclean reboot loop which will increase your chances of having a tragic day. The most important rule is to always ensure you have up-to-date, available, off-site backups of your Linode's data. In the event non-backed-up data is lost, please send a self-addressed, stamped envelope to World's Smallest Violin Giveaway, Box 17821, Pound Ridge Station.

[edit] Enable Lassie

Lassie, the Linode Autonomous System Shutdown Intelligent rEbooter, will issue a boot command should it find your kernel not running. You can ensure this is enabled from the Dashboard at Settings & Utilities -> Shutdown Watchdog.

[edit] Edit /etc/sysctl.conf

Adding the following two lines to your /etc/sysctl.conf will cause it to reboot after running out of memory:

vm.panic_on_oom=1
kernel.panic=10

The vm.panic_on_oom=1 line enables panic on OOM; the kernel.panic=10 line tells the kernel to reboot ten seconds after panicking.

[edit] Make the change live

You can make the change live now (vs. on a reboot) with:

echo 1 > /proc/sys/vm/panic_on_oom
echo 10 > /proc/sys/kernel/panic
Personal tools