More warning signs at Swalecliffe

More Garbage Sysadmin: Reboot Linux Server on Kernel Panic

Just like restarting a server when the memory is low, I’ve had a recent problem with kernel panics on my Raspberry Pi, and I’ve found a terrible solution to fix it: Just reboot.

Setting the /proc/sys/kernel/panic file contents to a non-zero integer will reboot the server on kernel panic after that many seconds.

Because I’m lazy, I asked ChatGPT to write me up a startup script to do this for me, and here’s what I have now:

To set the panic timeout value on Ubuntu Server 20.04 and later versions, you can create a systemd service unit file.

Here are the steps to create a systemd service unit file:

  1. Open a terminal window on your Ubuntu Server.
  2. Create a new service unit file with the following command:

    sudo nano /etc/systemd/system/panic-timeout.service

    This will open a new file named panic-timeout.service in the nano text editor with superuser privileges.
  3. Add the following lines to the file:
[Unit]
Description=Panic Timeout

[Service]
Type=oneshot
ExecStart=/bin/bash -c "echo 60 > /proc/sys/kernel/panic"

[Install]
WantedBy=multi-user.target
Code language: JavaScript (javascript)

This service unit file sets the panic timeout to 60 seconds.

  1. Save the file by pressing Ctrl+O, then exit nano by pressing Ctrl+X.
  2. Reload the systemd daemon to recognize the new service unit file with the following command:

    sudo systemctl daemon-reload
  3. Enable the service unit file to run at boot time with the following command:

    sudo systemctl enable panic-timeout.service
  4. Reboot the server to test the service unit file. After the server reboots, the panic-timeout.service will automatically run the echo command and set the panic timeout to 60 seconds.

That’s it! With these steps, you can set the panic timeout value on the latest versions of Ubuntu Server.

Well there you have it! Don’t forget to follow along for more terrible ideas!

Other Posts Not Worth Reading

Hey, You!

Like this kind of garbage? Subscribe for more! I post like once a month or so, unless I found something interesting to write about.