Nginx 服务启动脚本
代码如下 | 复制代码 |
#! /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.org
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin NAME=nginx NGINX_BIN=/usr/local/nginx/sbin/$NAME CONFIGFILE=/usr/local/nginx/conf/$NAME.conf PIDFILE=/usr/local/nginx/logs/$NAME.pid
case "$1" in start) echo -n "Starting $NAME… "
if netstat -tnpl | grep -q nginx;then echo "$NAME (pid `pidof $NAME`) already running." exit 1 fi
$NGINX_BIN -c $CONFIGFILE
if [ “$?” != 0 ] ; then echo " failed" exit 1 else echo " done" fi ;;
stop) echo -n "Stoping $NAME… "
if ! netstat -tnpl | grep -q nginx; then echo "$NAME is not running." exit 1 fi
$NGINX_BIN -s stop
if [ “$?” != 0 ] ; then echo " failed. Use force-quit" exit 1 else echo " done" fi ;;
status) if netstat -tnpl | grep -q nginx; then PID=`pidof nginx` echo "$NAME (pid $PID) is running…" else echo "$NAME is stopped" exit 0 fi ;;
force-quit) echo -n "Terminating $NAME… "
if ! netstat -tnpl | grep -q nginx; then echo "$NAME is not running." exit 1 fi
kill `pidof $NAME`
if [ “$?” != 0 ] ; then echo " failed" exit 1 else echo " done" fi ;;
restart) $0 stop sleep 1 $0 start ;;
reload) echo -n "Reload service $NAME… "
if netstat -tnpl | grep -q nginx; then $NGINX_BIN -s reload echo " done" else echo "$NAME is not running, can't reload." exit 1 fi ;;
configtest) echo -n "Test $NAME configure files… "
$NGINX_BIN -t ;;
*) echo "Usage: $0 {start|stop|force-quit|restart|reload|status|configtest}" exit 1 ;; |
例子2
把以下脚本保存为nginx文件放入/etc/init.d/nginx
然后可以通过
代码如下 | 复制代码 |
/etc/init.d/nginx start 命令启动nginx /etc/init.d/nginx stop 命令停止nginx /etc/init.d/nginx restart 命令重启nginx |
开机自动启动nginx,
如果需要开机启动服务,保存好 /etc/init.d/nginx文件后,
执行以下命令:
代码如下 | 复制代码 |
chkconfig --add ningx chkconfig --level nginx 2345 on |
你也可以直接下载nginx启动停止脚本
---------------------分割线下是脚本内容,红色字体需要你修改-------------------------------------------
代码如下 | 复制代码 |
#! /bin/sh PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DESC="nginx daemon" set -e do_start() { do_stop() { do_reload() { case "$1" in exit 0 |
丛林探险3 安卓版v454.0
下载敢达决战官方正版 安卓版v6.7.9
下载敢达决战 安卓版v6.7.9
下载像素火影骨架佐助 (Perseverance Fire Shadow)手机版v1.16
下载佩皮之家 最新版v1.14.2
佩皮之家(Pepi House)是一款卡通风格的育儿益智游戏
海魂少女 官方最新版v1.0
海魂少女是一款十分好玩的模拟经营类游戏,玩家在游戏中因为炒股
永远的拓麻歌子 最新安卓版v7.7.2.6078
永远的拓麻歌子是一款十分好玩的模拟类游戏,在这里玩家可以拥有
梦想城镇vivo最新版本 安卓版v12.0.1
梦想城镇vivo版是这款卡通风模拟经营类手游的渠道服版本,玩
怦然心动的瞬间 安卓版v1.0
怦然心动的瞬间是一款真人向的恋爱互动游戏,在游戏中玩家将扮演