码迷,mamicode.com
首页 > 其他好文 > 详细

为编译安装的nginx提供init服务控制脚本

时间:2014-12-21 17:47:43      阅读:349      评论:0      收藏:0      [点我收藏+]

标签:

生产环境中nginx多为编译安装,但源码包不提供init脚本

 

从这里下载相应系统的脚本:http://wiki.nginx.org/InitScripts,并作简单修改

 

修改后内容如下

 

  1 #!/bin/bash
  2 #
  3 # nginx - this script starts and stops the nginx daemon
  4 #
  5 # chkconfig:   - 85 15 
  6 # description:  Nginx is an HTTP(S) server, HTTP(S) reverse   7 #               proxy and IMAP/POP3 proxy server
  8 # processname: nginx
  9 # config:      /usr/local/nginx/conf/nginx.conf
 10  
 11 # Source function library.
 12 . /etc/rc.d/init.d/functions
 13  
 14 # Source networking configuration.
 15 . /etc/sysconfig/network
 16  
 17 # Check that networking is up.
 18 [ "$NETWORKING" = "no" ] && exit 0
 19  
 20 nginx="/usr/local/nginx/sbin/nginx"                #nginx启动文件位置
 21 prog=$(basename $nginx)
 22  
 23 NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" #配置文件   
 24  
 25  
 26 lockfile=/usr/local/nginx/logs/nginx               #锁文件
 27  
 28  
 29 start() {
 30     [ -x $nginx ] || exit 5
 31     [ -f $NGINX_CONF_FILE ] || exit 6
 32     echo -n $"Starting $prog: "
 33     daemon $nginx -c $NGINX_CONF_FILE
 34     retval=$?
 35     echo
 36     [ $retval -eq 0 ] && touch $lockfile
 37     return $retval
 38 }
 39  
 40 stop() {
 41     echo -n $"Stopping $prog: "
 42     killproc $prog -QUIT
 43     retval=$?
 44     echo
 45     [ $retval -eq 0 ] && rm -f $lockfile
 46     return $retval
 47 }
 48  
 49 restart() {
 50     configtest || return $?
 51     stop
 52     sleep 1
 53     start
 54 }
 55  
 56 reload() {
 57     configtest || return $?
 58     echo -n $"Reloading $prog: "
 59     killproc $nginx -HUP
 60     RETVAL=$?
 61     echo
 62 }
 63  
 64 force_reload() {
 65     restart
 66 }
 67  
 68 configtest() {
 69   $nginx -t -c $NGINX_CONF_FILE
 70 }
 71  
 72 rh_status() {
 73     status $prog
 74 }
 75  
 76 rh_status_q() {
 77     rh_status >/dev/null 2>&1
 78 }
 79  
 80 case "$1" in
 81     start)
 82         rh_status_q && exit 0
 83         $1
 84         ;;
 85     stop)
 86         rh_status_q || exit 0
 87         $1
 88         ;;
 89     restart|configtest)
 90         $1
 91         ;;
 92     reload)
 93         rh_status_q || exit 7
 94         $1
 95         ;;
 96     force-reload)
 97         force_reload
 98         ;;
 99     status)
100         rh_status
101         ;;
102     condrestart|try-restart)
103         rh_status_q || exit 0
104             ;;
105     *)
106         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
107         exit 2
108 esac

 

 

 

为编译安装的nginx提供init服务控制脚本

标签:

原文地址:http://www.cnblogs.com/xugongzi/p/4176755.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!