Linux detects that the memory exceeds the threshold in real time and automatically restarts the service

If you want to detect memory usage in real time and automatically restart the service when the memory exceeds the threshold, you can use a script similar to a daemon.

The following script will continuously detect the memory usage of the current system, and if the memory usage exceeds the set threshold, the specified service will be restarted. You need to THRESHOLD replace with 你想要设定的内存阈值, INTERVALreplace with 你想要设定的检测间隔, service_namereplace with what you want重启的服务名

#!/bin/bash

# 设定检测间隔,单位为秒
INTERVAL=60

while true; do
  # 设定阈值,单位为 MB
  THRESHOLD=2048
  # 设定要重启的服务名

Guess you like

Origin blog.csdn.net/chj_1224365967/article/details/130603944