J'ai créé la tâche cron suivante, qui s'exécute toutes les 5 minutes (et qui fonctionne)
#!/bin/bash
PATH=/usr/sbin:/usr/bin:/sbin:/bin
if [[ "$(/usr/sbin/service mysql status)" != *start/running* ]]
then
echo "MySQL restarted" | mail -a FROM:*@* -s "[Marketing Server] Database Service" *@*
sudo service mysql start
fi
Lors de l'exécution de mysql status (running)
mysql.service - LSB: Start and stop the mysql database server daemon Loaded: loaded (/etc/init.d/mysql) Active: active (exited) since Wed 2015-12-09 15:01:40 GMT; 21h ago Docs: man:systemd-sysv-generator(8) Process: 30829 ExecStop=/etc/init.d/mysql stop (code=exited, status=0/SUCCESS) Process: 30910 ExecStart=/etc/init.d/mysql start (code=exited,status=0/SUCCESS)
Dec 10 12:10:02 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:15:02 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:20:02 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:25:01 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:30:02 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:35:01 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:40:01 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:45:02 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:50:02 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:55:01 MarketingServer systemd[1]: Started LSB: Start and stop the .... Hint: Some lines were ellipsized, use -l to show in full.
lors de l'exécution de mysql status (stopped)
david@MarketingServer:~$ sudo service mysql stop ^[[Adavid@MarketingServer:~$ sudo service mysql status mysql.service - LSB: Start and stop the mysql database server daemon Loaded: loaded (/etc/init.d/mysql) Active: inactive (dead) since Thu 2015-12-10 13:03:26 GMT; 1s ago Docs: man:systemd-sysv-generator(8) Process: 5024 ExecStop=/etc/init.d/mysql stop (code=exited, status=0/SUCCESS) Process: 30910 ExecStart=/etc/init.d/mysql start (code=exited, status=0/SUCCESS)
Dec 10 12:35:01 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:40:01 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:45:02 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:50:02 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 12:55:01 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 13:00:02 MarketingServer systemd[1]: Started LSB: Start and stop the .... Dec 10 13:03:24 MarketingServer systemd[1]: Stopping LSB: Start and stop the.... Dec 10 13:03:24 MarketingServer mysql[5024]: * Stopping MySQL database serve...d Dec 10 13:03:26 MarketingServer mysql[5024]: ...done. Dec 10 13:03:26 MarketingServer systemd[1]: Stopped LSB: Start and stop the .... Hint: Some lines were ellipsized, use -l to show in full.
Le seul problème que j'ai est qu'il envoie un email indiquant que le service a été redémarré à chaque fois, même si ce n'est pas le cas. Je veux qu'il n'envoie que lorsque le service a réellement redémarré après s'être arrêté.
Quelqu'un peut-il m'expliquer quelle partie je me suis trompée ?