首页 > 代码库 > Nginx 启动脚本

Nginx 启动脚本

默认我们用 /usr/local/nginx/sbin/nginx 来启动 Nginx ,但是不能重启或关闭 Nginx ,因此我们可以自己写一个启动脚本

[root@localhost ~]# vim /etc/init.d/nginx#!/bin/bash# chkconfig: - 30 21# description: http service.# Source Function Library. /etc/init.d/functions# Nginx SettingsNGINX_SBIN="/usr/local/nginx/sbin/nginx"NGINX_CONF="/usr/local/nginx/conf/nginx.conf"NGINX_PID="/usr/local/nginx/logs/nginx.pid"RETVAL=0prog="Nginx"start() {        echo -n $"Starting $prog: "        mkdir -p /dev/shm/nginx_temp        daemon $NGINX_SBIN -c $NGINX_CONF        RETVAL=$?        echo        return $RETVAL}stop() {        echo -n $"Stopping $prog: "        killproc -p $NGINX_PID $NGINX_SBIN -TERM        rm -rf /dev/shm/nginx_temp        RETVAL=$?        echo        return $RETVAL}reload(){        echo -n $"Reloading $prog: "        killproc -p $NGINX_PID $NGINX_SBIN -HUP        RETVAL=$?        echo        return $RETVAL}restart(){        stop        start}configtest(){    $NGINX_SBIN -c $NGINX_CONF -t    return 0}case "$1" in  start)        start        ;;  stop)        stop        ;;  reload)        reload        ;;  restart)        restart        ;;  configtest)        configtest        ;;  *)        echo $"Usage: $0 {start|stop|reload|restart|configtest}"        RETVAL=1esacexit $RETVAL
chmod 755 /etc/init.d/nginx chkconfig --add nginxchkconfig nginx on
/etc/init.d/nginx start/etc/init.d/nginx stop/etc/init.d/nginx restart

 

 

 

 

   

Nginx 启动脚本