centos6.4下NGINX启动脚本
2014-03-16 13:17
489 查看
#!/bin/bash # nginx This shell script takes care of starting and stopping # nginx # # chkconfig: - 13 68 # description: nginx is a web server ### BEGIN INIT INFO # Provides: $named # Short-Description: start|stop|status|restart|configtest ### END INIT INFO #variables NGINX_BIN="/usr/local/nginx/sbin/nginx" NGINX_CONF="/usr/local/nginx/conf/nginx.conf" NGINX_PID="/usr/local/nginx/logs/nginx.pid" NETSTAT="/bin/netstat" alter=$1 prog=nginx #load system function . /etc/rc.d/init.d/functions #function:echo ok or error function if_no { if [ $2 == 0 ]; then echo -n $"$1 ${prog}:" && success && echo else echo -n $"$1 ${prog}:" && failure && echo fi } #start nginx function start { if [ -s ${NGINX_PID} ]; then echo "nginx already running" else if [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; then rm -f ${NGINX_PID} 2>/dev/null ${NGINX_BIN} -c ${NGINX_CONF} if_no start $? else ${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1 > ${NGINX_PID} if_no start $? fi fi } #stp nginx function stop { if [ -s ${NGINX_PID} ]; then cat ${NGINX_PID} | xargs kill -QUIT if_no stop $? else if [ `${NETSTAT} -tnpl | grep nginx | wc -l` -eq 0 ]; then rm -f ${NGINX_PID} 2>/dev/null if_no stop 0 else rm -f ${NGINX_PID} 2>/dev/null kill `${NETSTAT} -tnpl | grep nginx | awk '{ print $7}' | cut -d '/' -f 1` if_no stop $? fi fi } function restart { if [ -s ${NGINX_PID} ]; then cat ${NGINX_PID} | xargs kill -HUP if_no restart $? else stop sleep 1 start fi } function status { ${NETSTAT} -tnpl | grep nginx | grep LISTEN [ $? == 0 ] && echo "nginx is running" || echo "nginx is not running" } function configtest { ${NGINX_BIN} -t } case $alter in start) start ;; stop) stop ;; restart) restart ;; status) status ;; configtest) configtest ;; *) echo "use:${NGINX} {start|stop|restart|status|configtest}" ;; esac
相关文章推荐
- LVS、Nginx和HAProxy负载均衡器对比总结
- Redhat5下haproxy+keepalived+nginx配置笔记
- nginx+keeplived
- Nginx学习笔记(十六):worker进程的循环工作
- Nginx负载均衡配置实例详解
- nginx 日志过滤网络爬虫
- Nginx下实现pathinfo及ThinkPHP的URL Rewrite模式支持
- Nginx代理与负载均衡配置与优化
- lanmp架构-------------nginx
- 启动时nginx时报错
- 在Ubuntu Server上源码安装OpenERP 8.0,并配置wsgi和nginx运行环境
- Nginx配置文件nginx.conf中文详解
- nginx教程从入门到精通(ttlsa出品)
- Nginx做前端Proxy时TIME_WAIT过多的问题
- Nginx + Lua + GraphicsMagick 实现切图服务
- nginx监听端口非80时的转发问题
- nginx+php配置
- Ubuntu下Nginx编译安装
- nginx ssl
- 手动11 -nginx 优化配置