我创建了一个 cron 作业来启动 MySQL 服务器(如果它意外停止)。它工作正常,有时可以启动,但 MySQL 不工作。如果我检查状态,没有 PID。
root@techbrij:~# service mysql status
mysql start/running
现在我想更改 cron 作业并在没有 MySQL PID 的情况下重新启动服务。
最佳答案
您必须从root crontab执行此脚本:
#!/bin/bash
if [[ ! "$(/usr/sbin/service mysql status)" =~ "start/running" ]]
then
/usr/sbin/service mysql start
fi
检查是否没有 PID:
#!/bin/bash
mysql="$(pgrep mysql)"
if [ -z "$mysql" ]
then
/usr/sbin/service mysql start
fi
关于mysql - 如果Ubuntu中没有PID(进程ID),请重新启动MySQL服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35920662/