How to automatically reboot (restart) Debian GNU Lenny / Squeeze Linux on kernel panic, some general CPU overload or system crash

If you are a system administrator, you have probably wondered at least once ohw to configure your Linux server to automatically reboot itself if it crashes, is going through a mass CPU overload, e.g. the server load average "hits the sky".
I just learned from a nice article found here that there is a kernel variable which when enabled takes care to automatically restart a crashed server with the terrible Kernel Panic message we all know.

The variable I'm taking about is kernel.panic for instance kernel.panic = 20 would instruct your GNU Linux kernel to automatically reboot if it experiences a kernel panic system crash within a time limit of 20 seconds.

To start using the auto-reboot linux capabilities on a kernel panic occurance just set the variable to /etc/sysctl.conf

debian-server:~# echo 'kernel.panic = 20' >> /etc/sysctl.conf

Now we will also have to enable the variable to start being use on the system, so execute:

debian-server:~# sysctl -p
There you go automatic system reboots on kernel panics is now on.
Now to further assure yourself the linux server you're responsible of will automatically restart itself on a emergency situation like a system overload I suggest you check Watchdog

You might consider checking out this auto reboot tutorial which explains in simple words how watchdog is installed and configured.
On Debian installing and maintaining watchdog is really simple and comes to installing and enabling the watchdog system service, right afteryou made two changes in it's configuration file /etc/watchdog.conf

To do so execute:

debian-server:~# apt-get install watchdog
debian-server:~# echo "file = /var/log/messages" >> /etc/watchdog.conf
debian-server:~# echo "watchdog-device = /dev/watchdog" >> /etc/watchdog.conf

Well that should be it, you might also need to load some kernel module to monitor your watchdog.
On my system the kernel modules related to watchdog are located in:

/lib/modules/2.6.26-2-amd64/kernel/drivers/watchdog/
If not then you should certainly try the software watchdog linux kernel module called softdog , to do so issue:
debian-server:~# /sbin/modprobe softdog

It's best if you load the module while the softdog daemon is disabled.
If you consider auto loadig the softdog software watchdog kernel driver you should exec:

debian-server:~# echo 'softdog' >> /etc/modules

Finally a start of the watchdog is necessery:

 


debian-server:~# /etc/init.d/watchdog start
Stopping watchdog keepalive daemon....
Starting watchdog daemon....

That should be all your automatic system reboots should be now on! :)

Share this on

Download PDFDownload PDF

Tags: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

14 Responses to “How to automatically reboot (restart) Debian GNU Lenny / Squeeze Linux on kernel panic, some general CPU overload or system crash”

  1. [...] If you are a system administrator, you have probably wondered at least once ohw to configure your Linux server to automatically reboot itself if it crashes, is going through a mass CPU overload, e.g. the server load average “hits the sky”. More here [...]

  2. Elisha Kertz says:

    Great post. Thanks!

  3. How to automatically reboot crashed debian server | 石木说 WordPress says:

    [...] How to automatically reboot (restart) Debian GNU Lenny Linux on kernel panic, some general CPU overl… 此条目发表在 忙里偷闲 分类目录,贴了 debian, server 标签。将固定链接加入收藏夹。 ← 我们的新T恤 毕业的煎熬 → [...]

  4. [...] there are plenty of things like Server Auto Reboot on Crash with software Watchdog etc., that we as sysadmins can do to reduce server downtimes and most of the manual human [...]

  5. mahmood says:

    Thanks for your article. Two questions:
    1- If I reboot the server manually (for service), then should I run “sysctl -p” again or only once it is needed?
    2- Is it mandatory to use “watchdog” in order for “kernel.panic” to work or it is an independent package?

  6. admin says:

    Hi mandhood,

    Here is the answers:

    1.If you put the settings inside /etc/sysctl.conf on next reboot you don’t need sysctl -p

    2. I think watchdog is not mandatory, however it’s recommended since at many cases the system could freeze without a kernel panic and then you will need reboot.

  7. mahmood says:

    You mean that if server hangs without kernel panic message, the watchdog can detect that and ‘kernel.panic’ will operate after 20 seconds. Right?

  8. admin says:

    aha :)
    Best!
    Georgi

  9. [...] recently blogged on the topic of Debian Linux auto-restart in case of kernel panic , however now i had to conifgure watchdog on some dozen of CentOS Linux [...]

  10. hip0 says:

    Just a small note it might be better to set the kernel panic to be kernel.panic = 10 or kernel.panic = 1 to restart the hanged server faster

  11. [...] is going through a mass CPU overload, e.g. the server load average “hits the sky”. More hereНайдено по поисковым фразам:cpu panicdebian cpu температураdebian [...]

  12. oom_killer problem using wordpress in a debian 64 server | Cognosfera SPAIN WordPress says:

    [...] the server if oom_killer goes up.watchdog (see this link)is a good [...]

Leave a Reply