Verificação de MySQL Crontab

0

Eu tenho um servidor serverpilot.io rodando do digitalocean (1gb Ram), o MySQL irá travar uma vez por semana, as estatísticas dizem que o servidor está usando ~ 256 mb de 1 gb, mas o mysql vai travar dizendo sem memória. ..

Para resolver isso, encontrei este script:

service mysql status| grep 'mysql start/running' > /dev/null 2>&1

#!/bin/bash
if [[ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]]
then
  /usr/sbin/service mysql start
fi

Funciona quando eu executo diretamente bash /srv/mysql.sh .

Eu também corri chmod +x /srv/mysql.sh

Eu também tentei:

* * * * * sh /srv/mysql.sh

* * * * * bash /srv/mysql.sh

* * * * * /usr/bin/sh /srv/mysql.sh

* * * * * /srv/mysql.sh

Estou recebendo este e-mail sempre que ele é executado e o mysql não está iniciando como deveria

/srv/mysql.sh: 4: /srv/mysql.sh: [[: not found

quando eu executo 'service mysql stop' e checo com 'service mysql status' o serviço mysql permanece parado e não funciona.

Qualquer conselho seria muito apreciado

Editar 1: adicionei >>/srv/cronlog.log 2>&1 ao final da linha crontab

e estou recebendo isso:

/srv/mysql.sh: 5: /srv/mysql.sh: [[: not found
/srv/mysql.sh: 5: /srv/mysql.sh: [[: not found
/srv/mysql.sh: 5: /srv/mysql.sh: [[: not found
/srv/mysql.sh: 5: /srv/mysql.sh: [[: not found

Editar 2: alterei para * * * * * bash /srv/mysql.sh >>/srv/cronlog.log 2>&1

 * Starting MySQL database server mysqld
   ...done.
 * Checking for tables which need an upgrade, are corrupt or were 
not closed cleanly.

O Mysql ainda está parado no teste

Editar 3: Cauda do crontablog.log

 * Starting MySQL database server mysqld
   ...done.
 * Starting MySQL database server mysqld
   ...done.
 * Starting MySQL database server mysqld
   ...done.
 * Starting MySQL database server mysqld
   ...done.
    
por exilepc 02.07.2015 / 19:18

1 resposta

0

Ao pesquisar por aí, deparei com um script melhor e decidi experimentá-lo, e funciona:

#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
if [[ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]]
then
    echo "MySQL restarted" | mail -s "Email Subject" [email protected]
    sudo service mysql start
fi

Mais informações podem ser encontradas aqui link

    
por exilepc 03.07.2015 / 08:24