#!/bin/bash
# chkconfig: 345 85 15
# description: nginx is a web cache server
# processname: nginx
. /etc/rc.d/init.d/functions
case $1 in
"start") /usr/local/nginx/sbin/nginx
if [ $? == "0" ];then
echo "nginx start ok"
else
echo "please check the log"
fi
;;
"stop") /usr/local/nginx/sbin/nginx -s stop
if [ $? == "0" ];then
echo "nginx stop ok"
else
echo "please check the log"
fi
;;
"restart")
/usr/local/nginx/sbin/nginx -s reload
if [ $? == "0" ];then
echo "nginx restart ok"
else
echo "nginx restart failed"
fi
;;
"status")
proces_number=`ps -fe | grep -i nginx | grep -iv grep | wc -l`
if [ "$proces_number" -gt 3 ];then
echo "nginx runs ok"
else
echo "nginx has problem,please check log"
fi
;;
*)
echo "Usage only start|stop|restart"
;;
esac
脚本的用法:
一.把脚本内容复制下来保存到一个文档内,文档名称改为nginx,
二.赋给脚本可执行权限,并把脚本放到/etc/init.d/目录下
三.chkconfig --add nginx
然后就可以用service 来启动关闭重启查看nginx状态了
阅读(701) | 评论(0) | 转发(0) |