¿Why MariaDB stop?

Hello!
There is an issue, not often but it can happen, MariaDB service stops and until manually starting in panel all sites not working
How this service start via bash?
I think write script which were check perfomance and if MariaDB fault down start it
Same issue i noticed in ¿Why Clamav-Daemon stop?
with other module
Thank you!

Check if there is enough memory available

Server work at more then on year, it seems that it is not standard issue
On vps server:
RAM : 4096 MB
SWAP : 256 MB
4 cores
Could you clear, how mariadb start via command same as clamav for example - clamav-daemon restart

systemctl restart mysql
or systemctl restart mariadb

1 Like

Thank you!

Well, this script can be using by cron and solve an problem above

#!/bin/bash

log_file="/var/log/mariadb_status.log"

# Checking the status of the MariaDB service
status=$(systemctl is-active mariadb)

if [ "$status" = "inactive" ]; then
  echo "$(date): The MariaDB service is stopped. Starting the service..." >> "$log_file"

  # Starting the MariaDB service
  systemctl start mariadb

  # Checking the status after starting
  new_status=$(systemctl is-active mariadb)

  if [ "$new_status" = "active" ]; then
    echo "$(date): The MariaDB service started successfully." >> "$log_file"
  else
    echo "$(date): Failed to start the MariaDB service." >> "$log_file"
  fi
else
  echo "$(date): The MariaDB service is already running." >> "$log_file"
fi

Converted it to code tags for read ability :slight_smile:

1 Like

You better use “monit” instead.

1 Like

this or any monitoring software. also mysql should not stop out of the blue, better to find and solve the “base issue”.

1 Like