现在的位置: 首页shell>正文
nginx管理脚本
2011年04月27日 shell nginx管理脚本已关闭评论 ⁄ 被围观 9,703 次+

nginx管理脚本用于nginx启动、停止、重新启动,并添加为linux服务,像启动linux下的服务一样方便
使用方法:将脚本放至/etc/init.d/目录下并执行

  1. ll /etc/init.d/nginx
  2. chkconfig --add nginx
  3. chkconfig --list | grep nginx
  4. service nginx restart

文章底部附脚本下载地址!(注意脚本中的变量NGINX_HOME,修改为自己环境中的nginx安装目录)

  1. #!/bin/bash   
  2. #   
  3. # nginx.sh  This shell this use to  crontal nginx.     
  4. #   
  5. # chkconfig:   345 85 15   
  6. #   
  7. # description: this shell this use to  crontal nginx. E.g nginx start stop restart reload..   
  8. #   
  9. #write by clairelume@gmail.com QQ:30879223   
  10. #Date:20110425   
  11.   
  12. # Source function library.   
  13. . /etc/rc.d/init.d/functions   
  14.   
  15. # Source networking configuration.   
  16. . /etc/sysconfig/network   
  17.   
  18. # Check that networking is up.   
  19. "$NETWORKING" = "no" ] && exit 0   
  20.   
  21. NGINX_HOME=/data/soft/nginx   
  22. NGNIX_CONF=${NGINX_HOME}/conf/nginx.conf   
  23. NGINX_PID_FILE=${NGINX_HOME}/logs/nginx.pid   
  24. NGINX_BIN=${NGINX_HOME}/sbin/nginx   
  25. NGINX_NAME=$(basename ${NGINX_BIN})   
  26.   
  27. lockfile=/var/lock/subsys/nginx   
  28.   
  29. function start(){   
  30.     echo -n "start Nginx ..."  
  31.     [ -x $nginx ] || echo "Nginx no permit"  
  32.     daemon ${NGINX_BIN}   
  33.     RETVAL=$?   
  34.         [ $RETVAL -eq 0 ] && touch $lockfile  
  35.     echo   
  36.     return $RETVAL  
  37. }   
  38.   
  39. function stop(){   
  40.     echo -n "stop Nginx..."  
  41.     killproc $NGINX_NAME  
  42.     RETVAL=$?   
  43.     [ $RETVAL -eq 0 ] && (rm -f $lockfile ;  rm -f ${NGINX_PID_FILE})   
  44.     echo    
  45.     return $RETVAL     
  46. }   
  47. function restart(){   
  48.     stop   
  49.     start   
  50. }   
  51.   
  52. function checkconfig(){   
  53.     echo "checking Nginx config ..."  
  54.     ${NGINX_BIN} -t    
  55. }   
  56.   
  57. function reload(){   
  58.     echo  "reload the Nginx config..."  
  59.     killproc ${NGINX_NAME} -HUP    
  60.     RETVAL=$?   
  61.     return $RETVAL  
  62. }   
  63.   
  64. function _ngstatus(){   
  65.     status -p ${NGINX_PID_FILE} ${NGINX_NAME}   
  66. }   
  67.   
  68. function showhelp(){   
  69.     echo "Usage: /etc/init.d/nginx {start|stop|restart|status|checkconfig|reload}"  
  70. }   
  71.   
  72. case $1 in  
  73.     start)   
  74.     start   
  75.     ;;   
  76.     stop)   
  77.     stop   
  78.     ;;   
  79.     restart)   
  80.     restart   
  81.     ;;   
  82.     reload)   
  83.     reload   
  84.     ;;   
  85.     status)   
  86.     _ngstatus    
  87.     ;;   
  88.     checkconfig)   
  89.     checkconfig   
  90.     ;;   
  91.     *)   
  92.     showhelp   
  93.     ;;   
  94. esac  

效果如下图:

nginx管理脚本示例图

本文地址:http://www.92csz.com/38/461.html
如非注明则为本站原创文章,欢迎转载。转载请注明转载自:moon's blog
 

抱歉!评论已关闭.