嘟嘟社区

小内存VPS必备——Mysql被杀自动重启脚本


低于2G的小内存的VPS,流量过大Mysql容易被杀
  1. #!/bin/bash
  2. pgrep -x mysqld &> /dev/null
  3. if [ $? -ne 0 ]
  4. then
  5. echo “At time: `date +%Y%m%d-%H:%M:%S` MySQL is stop .”>> restartmysql.log
  6. systemctl restart mariadb.service
  7. else
  8. echo “At time: `date +%Y%m%d-%H:%M:%S` MySQL server is running .”>> restartmysql.log
  9. fi

复制代码

  1. –restart=unless-stopped

复制代码