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 |
茶杯头甜蜜终章dlc 官方手机版v1.0.0.3
下载火柴人传说暗影格斗内置菜单 最新版v3.0.1
下载荒野乱斗测试服 安卓版v61.10.3
下载荒野乱斗彩虹服 安卓版v61.10.3
下载寒霜启示录 安卓版v1.25.10
寒霜启示录是一款生存模拟游戏,不少玩家可能对于末日都有着自己
末日城堡免广告版 安卓最新版v0.7.1
末日城堡免广告版是一款非常好玩的模拟经营类游戏,内部可以不看
甜蜜人生模拟器 最新版v1.4.5
甜蜜人生模拟器是一款非常好玩的模拟恋爱手游,玩家在这里能够对
武器锻造师内置功能菜单 v10.4
武器锻造师内置菜单版是游戏的破解版本,在该版本中为玩家提供了
开放空间overfield 安卓版v1.0.5
开放空间Overfield是一款箱庭养成经营手游,让你在广阔