开机启动nginx,监控webserver

将一下脚本做成定时任务。

#!/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
此条目发表在 小技巧 分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*


*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>