将一下脚本做成定时任务。
#!/bin/sh exec 0<>/dev/null basedir=/Users/wenzg/local exec 1>>$basedir/nginx/logs/launch.log exec 2>>$basedir/nginx/logs/launch.log.wf lockfile=${basedir}/nginx/var/launch.lock do_start() { tries=0 limit=3 while [ $tries -lt $limit ]; do tries=$(( tries + 1 )) res=`/usr/sbin/lsof -i tcp:8888` if [ $? -ne 0 ]; then if [ $tries -lt $limit ]; then echo "Try to launch the WebServer...(${tries})" echo "Waiting for launch the PHP-FPM..." ${basedir}/php/sbin/php-fpm -c ${basedir}/php/etc/php.ini -y ${basedir}/php/etc/php-fpm.conf echo "Waiting for launch the Nginx..." ${basedir}/nginx/sbin/nginx echo "Waiting for launch the Mysql..." ${basedir}/mysql/bin/mysqld_safe --defaults-file=${basedir}/mysql/my.cnf --pid-file=${basedir}/mysql/data/local-dev.pid --user=mysql & sleep 5 else msg="Retry exceeded maximum limit (${limit}), contact administrator..." echo "${msg}" |mail -s "Webserver try restart failed." wenzg_123@sina.com echo ${msg} return 0 fi else rm ${lockfile} tries=$limit fi done return 0 } if [ -f ${lockfile} ];then echo 'Task is trying to start,please wait...' exit 1 else touch ${lockfile} do_start exit 0 fi