• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question Is there a way to restart the server automatically every time it crashes due to 2GB of RAM?

Carlos Nog

New Pleskian
Server operating system version
Ubuntu 22.05
Plesk version and microupdate number
18.0.56
hello,

Is there a way to restart the server automatically every time it crashes due to 2GB of RAM?
 
Its not Plesk that is crashing its your server running out of ram. Fix the RAM issue.
 
What @Dave W is true, but if you need something, this might help:

- Log in on your server using SSH
- Add these two lines to /etc/sysctl.conf
Code:
vm.panic_on_oom=1   ; enables panic on OOM
kernel.panic=10     ; tells the kernel to reboot ten seconds after panicking

When your server runs out of RAM, the server will reboot after 10 seconds.
I haven't tested this, so use it with care.
 
I have 5 wordpress sites. And yesterday without having opened the plesk panel and without having been working on the wordpress sites, the server went down.
They have very little traffic.
2GB RAM
80GB SSD
 
Did you check the /var/log/syslog after the reboot? Was there anything related to a system crash like "oom" (Out Of Memory)?
Could it be a fail2ban action that blocked you from the server?

I'm just curious why you think the server ran out of memory or crashed.
 
Hi Carlos, what Peter Debik says resonates with what I heard from Plesk Technical Support recommendations.

I did have a similar experience, server running out of memory, and I added swap and it seems to help my situation.
1703090160234.png
 
Hi Carlos, what Peter Debik says resonates with what I heard from Plesk Technical Support recommendations.

I did have a similar experience, server running out of memory, and I added swap and it seems to help my situation.
View attachment 25104
hello. I have Ubuntu 22.04 and I want to add 4GB of RAM SWAP.

How did you do it? if you log in using ssh. but what commands did you use?
 
Hi Carlos, I logged to the server and executed the following commands, if use the SSH terminal on Plesk you could do it too.


Create a New Swap File (if needed):


  • If you don't have an existing swap file, create one using fallocate:
    Bash
    sudo fallocate -l 4G /swapfile

    Use code with caution.
    • Replace 4G with the desired swap size (e.g., 8G for 8GB).
Set up the Swap File:


  • Make the swap file usable with mkswap:

    sudo mkswap /swapfile


  • Enable the swap file:

    sudo swapon /swapfile

Make the Change Permanent:


  • Edit the /etc/fstab file to mount the swap file automatically at boot:

    sudo nano /etc/fstab

  • Add this line to the end:
    /swapfile swap swap defaults 0 0

5. Adjust Swappiness (Optional):


  • Control how often the system uses swap:

    sudo sysctl vm.swappiness=10

    • Values closer to 0 mean less frequent swap usage, while values closer to 100 mean more frequent use.

6. Verify the Changes:


  • Use free -m again to confirm the increased swap space.

More information:
 
What @Dave W is true, but if you need something, this might help:

- Log in on your server using SSH
- Add these two lines to /etc/sysctl.conf
Code:
vm.panic_on_oom=1   ; enables panic on OOM
kernel.panic=10     ; tells the kernel to reboot ten seconds after panicking

When your server runs out of RAM, the server will reboot after 10 seconds.
I haven't tested this, so use it with care.
This is probably a vserver, so would this even work?
 
Hi Carlos, I logged to the server and executed the following commands, if use the SSH terminal on Plesk you could do it too.


Create a New Swap File (if needed):


  • If you don't have an existing swap file, create one using fallocate:
    Bash
    sudo fallocate -l 4G /swapfile

    Use code with caution.
    • Replace 4G with the desired swap size (e.g., 8G for 8GB).
Set up the Swap File:


  • Make the swap file usable with mkswap:

    sudo mkswap /swapfile


  • Enable the swap file:

    sudo swapon /swapfile
Make the Change Permanent:


  • Edit the /etc/fstab file to mount the swap file automatically at boot:

    sudo nano /etc/fstab

  • Add this line to the end:
    /swapfile swap swap defaults 0 0

5. Adjust Swappiness (Optional):


  • Control how often the system uses swap:

    sudo sysctl vm.swappiness=10
    • Values closer to 0 mean less frequent swap usage, while values closer to 100 mean more frequent use.

6. Verify the Changes:


  • Use free -m again to confirm the increased swap space.

More information:
Hello, thank you for your great help. I have done everything as you explained. I hope it works well for me now. I sent a screenshot there. Thank you
 

Attachments

  • Captura desde 2023-12-23 16-20-20.png
    Captura desde 2023-12-23 16-20-20.png
    97.7 KB · Views: 5
Back
Top