把Nginx加入系统服务 service nginx (start | stop | restart | reload),nginxreload


vim /etc/init.d/nginx

 1 #!/bin/bash
  2 # nginx Startup script for the Nginx HTTP Server
  3 # it is v.0.0.2 version.
  4 # chkconfig: 2345 30 30
  5 # description: Nginx is a high-performance web and proxy server.
  6 #              It has a lot of features, but it's not for everyone.
  7 # processname: nginx
  8 # pidfile: /usr/local/nginx/logs/nginx.pid
  9 # config: /usr/local/nginx/conf/nginx.conf
 10
 11 #nginx程序路径
 12 nginxd=/usr/local/nginx/sbin/nginx
 13
 14 #nginx配置文件路径
 15 nginx_config=/usr/local/nginx/conf/nginx.conf
 16
 17 #nginx pid文件的路径,可以在nginx的配置文件中找到
 18 nginx_pid=/usr/local/nginx/logs/nginx.pid
 19 RETVAL=0
 20 prog="nginx"
 21 # Source function library.
 22 . /etc/rc.d/init.d/functions
 23 # Source networking configuration.
 24 . /etc/sysconfig/network
 25 # Check that networking is up.
 26 [ ${NETWORKING} = "no" ] && exit 0
 27 [ -x $nginxd ] || exit 0
 28 # Start nginx daemons functions.
 29 start() {
 30 if [ -e $nginx_pid ];then
 31    echo "nginx already running...."
 32    exit 1
 33 fi
 34    echo -n $"Starting $prog: "
 35    daemon $nginxd -c ${nginx_config}
 36    RETVAL=$?
 37    echo
 38    [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
 39    return $RETVAL
 40 }
 41 # Stop nginx daemons functions.
 42 stop() {
 43         echo -n $"Stopping $prog: "
 44         killproc $nginxd
 45         RETVAL=$?
 46         echo
 47         [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/nginx/logs/nginx.pid
 48 }
 49 # reload nginx service functions.
 50 reload() {
 51     echo -n $"Reloading $prog: "
 52     #kill -HUP `cat ${nginx_pid}`
 53     killproc $nginxd -HUP
 54     RETVAL=$?
 55     echo
 56 }
 57 # See how we were called.
 58 case "$1" in
 59 start)
 60         start
 61         ;;
 62 stop)
 63         stop
 64         ;;
 65 reload)
 66         reload
 67         ;;
 68 restart)
 69         stop
 70         start
 71         ;;
 72 status)
 73         status $prog
 74         RETVAL=$?
 75         ;;
 76 *)
 77         echo $"Usage: $prog {start|stop|restart|reload|status|help}"
 78         exit 1
 79 esac
 80 exit $RETVAL

chkconfig --add nginx

chkconfig nginx on

 

相关内容