R
R
romaaa322018-08-19 21:52:32
bash
romaaa32, 2018-08-19 21:52:32

How to automatically start MYSQL on crash in UBUNTU?

Tried like this

#!/bin/bash
PGREP="/usr/bin/pgrep"
RESTARTM="/etc/init.d/mysql restart"
MYSQLD="mysqld"
echo $PGREP ${MYSQLD}
if [ $? = 0 ]; then
$RESTARTM
fi

so
#!/bin/bash
TSTMYSQL=$(/etc/init.d/mysql status | grep stop) 
if [ "$TSTMYSQL" = "mysql stop/waiting" ]; then
/etc/init.d/mysql start 
fi

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
CityCat4, 2018-08-20
@romaaa32

Many, many years ago, I wrote this to test for a crash in the winbind process. Starts on the crown.

entries=`ps -ax | grep $1 | grep -v grep | grep -v checkwbd | wc -l`
host=`/bin/hostname`
_host=${host%%.*}
_date=`/bin/date "+%b %d %T"`

if [ $entries -eq 0 ]; then
  cd /usr/local/etc/rc.d
  ./$2 start
  /usr/bin/logger -4 -i -t chkservice -p daemon.info $1 crash detected, process restarted
fi

checkwbd is the name of the script itself

A
Artem Soshnikov, 2018-08-19
@artem90

Perhaps the immortal utility will help in this matter: https://immortal.run

P
pfg21, 2018-08-19
@pfg21

write a systemd unit. he himself will monitor the working state of the program and restart in case of a fall.
Failure Restart options, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question