在进行Nginx启动编程的时候有不少网管员都不知道如何入手,其实很简单,掌握好相关的命令编写就能完成这些任务。接下来我们就看看如何才能更好的使用Nginx启动的编写。
- #!/bin/sh
- # 将脚本保存为/etc/rc.d/init.d/nginxd,便可以使用service命令启动、
停止、重启nginx服务。- # source function library
- . /etc/rc.d/init.d/functions
- # Source networking configuration.
- . /etc/sysconfig/network
- # Check that networking is up.
- [ ${NETWORKING} = "no" ] && exit 0
- RETVAL=0
- prog="nginx"
- nginxDir=/usr/local/nginx
- nginxd=$nginxDir/sbin/nginx
- nginxConf=$nginxDir/conf/nginx.conf
- nginxPid=$nginxDir/nginx.pid
- start()
- {
- if [[ -e $nginxPid ]]; then
- echo "$prog already running..."
- exit 1
- else
- echo -n $"Starting $prog:"
- daemon $nginxd -c $nginxConf
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
- return $RETVAL
- fi
- }
- stop()
- {
- echo -n $"Stopping $prog:"
- killproc $nginxd
- RETVAL=$?
- echo
- [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginxPid
- }
- reload()
- {
- echo -n $"Reloading $prog:"
- killproc $nginxd -HUP
- RETVAL=$?
- echo
- }
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
- restart)
- stop
- start
- ;;
- reload)
- reload
- ;;
- status)
- status $prog
- RETVAL=$?
- ;;
- *)
- echo $"Usage: $0 {start|stop|restart|reload|status}"
- RETVAL=1
- esac
- exit $RETVAL
以上就是对Nginx启动如何操控的详细介绍。
【编辑推荐】