Hello aapanel forum
unfortunately on many tech forums the person asking for
help has to solve their own problem.
I tweeked some posted code I found here and it works for
me. I hope this will help some one with crashing Mysql.
All code below is for a crashed Mysql restart --- not start
Use this code in the cron job script text box
Use the execute option next to the edit button to
test it
Also setup a cron to clear ram every half hour.
=========================================
--1
DETECT IF STOPED THEN RESTART--
IF MYSQL IS RUNNING THERE WILL BE NO
RESTART
run this every half hour
pgrep -x mysqld &> /dev/null
if [ $? -ne 0 ]
then
echo "At time: date
:MySQL is stop ."
/etc/init.d/mysqld restart
fi
LOG WILL BE
At time: Wed 05 Feb 2025 06:26:42 AM GMT :MySQL is stop .
Restarting mysqld (via systemctl): mysqld.service.
?[2025-02-05 06:26:44] Successful
======================================
--2
IF STOPED AND JAMMED IT WILL STOP IT AGAIN
AND RESTART
IF MYSQL IS RUNNING THERE WILL BE NO
RESTART
-- run this every half hour
pgrep -x mysqld &> /dev/null
if [ $? -ne 0 ]
then
echo "At time: date
:MySQL is stop ."
/etc/init.d/mysqld stop
fi
echo "At time: date
:MySQL is stop ."
/etc/init.d/mysqld restart
LOG WILL BE
At time: Wed 05 Feb 2025 06:26:42 AM GMT :MySQL is stop .
Stopping mysqld (via systemctl): mysqld.service.
At time: Wed 05 Feb 2025 06:26:42 AM GMT :MySQL is stop .
Restarting mysqld (via systemctl): mysqld.service.
?[2025-02-05 06:26:44] Successful
=====================================================
--3
THIS WILL STOP AND START WITHOUT DETECTING THE MYSQL
RUNNING STATUS -- run this every 24 hours on a separate cron job
in addition to the every half hour command. A stop and restart once
a day could solve the problem
pgrep -x mysqld &> /dev/null
/etc/init.d/mysqld stop
pgrep -x mysqld &> /dev/null
/etc/init.d/mysqld restart
LOG WILL BE
Stopping mysqld (via systemctl): mysqld.service.
Restarting mysqld (via systemctl): mysqld.service.
?[2025-02-05 06:51:39] Successful
==========================================
--4
THIS WILL RESTART WHEN RUNNING WITHOUT
STOPING IT FIRST -- Try this if the code examples
above don't work on a crash. Don't run this every half
hour or hour , If mysql is running ok there is no reason
to restart it
pgrep -x mysqld &> /dev/null
/etc/init.d/mysqld restart
LOG WILL BE
Restarting mysqld (via systemctl): mysqld.service.
?[2025-02-05 06:56:42] Successful
======================================
Below is the detect if stopped and start for apache.
it can be tweeked into the same --restart-- commands-
as the above shown code for Mysql
pgrep -x httpd &> /dev/null
if [ $? -ne 0 ]
then
echo "At time: date
: Apache is stop ."
/etc/init.d/httpd start
fi
=======================================
Good Luck
user -- 3001panel