#! /bin/sh# chkconfig: 2345 55 25# Description: Startup script for nginx webserver on Debian. Place in /etc/init.d and# run 'update-rc.d -f nginx defaults', or use the appropriate command on your# distro. For CentOS/Redhat run: 'chkconfig --add nginx'### BEGIN INIT INFO# Provides: nginx# Required-Start: $all# Required-Stop: $all# Default-Start: 2 3 4 5# Default-Stop: 0 1 6# Short-Description: starts the nginx web server# Description: starts nginx using start-stop-daemon### END INIT INFO# Author: licess# website: http://lnmp.orgPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binNAME=nginxNGINX_BIN=/usr/local/qif/nginx/sbin/$NAMECONFIGFILE=/usr/local/qif/nginx/conf/$NAME.confPIDFILE=/usr/local/qif/nginx/logs/$NAME.pidcase "$1" instart)echo -n "Starting $NAME... "if netstat -tnpl | grep -q nginx;thenecho "$NAME (pid `pidof $NAME`) already running."exit 1fi$NGINX_BIN -c $CONFIGFILEif [ "$?" != 0 ] ; thenecho " failed"exit 1elseecho " done"fi;;stop)echo -n "Stoping $NAME... "if ! netstat -tnpl | grep -q nginx; thenecho "$NAME is not running."exit 1fi$NGINX_BIN -s stopif [ "$?" != 0 ] ; thenecho " failed. Use force-quit"exit 1elseecho " done"fi;;status)if netstat -tnpl | grep -q nginx; thenPID=`pidof nginx`echo "$NAME (pid $PID) is running..."elseecho "$NAME is stopped"exit 0fi;;force-quit)echo -n "Terminating $NAME... "if ! netstat -tnpl | grep -q nginx; thenecho "$NAME is not running."exit 1fikill `pidof $NAME`if [ "$?" != 0 ] ; thenecho " failed"exit 1elseecho " done"fi;;restart)$0 stopsleep 1$0 start;;reload)echo -n "Reload service $NAME... "if netstat -tnpl | grep -q nginx; then$NGINX_BIN -s reloadecho " done"elseecho "$NAME is not running, can't reload."exit 1fi;;configtest)echo -n "Test $NAME configure files... "$NGINX_BIN -t;;*)echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}"exit 1;;esac
# 执行的脚本touch /etc/init.d/nginx #用管理员权限,在/etc/init.d/目录下,创建文件 nginxvim nginx # 使用vim工具,将上面的脚本信息贴到文件中update-rc.d -f nginx defaults #用管理员权限,将文件加入到update-rc.d的脚本下
参考文档:
- https://www.cnblogs.com/wkun/p/3798816.html
- https://blog.csdn.net/qq_41345773/article/details/88855178?utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7EBlogCommendFromMachineLearnPai2%7Edefault-1.control
