#! /bin/sh
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="nginx daemon"
NAME=nginx
<span style="color: #ff0000;"><strong>DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/usr/local/nginx/logs/$NAME.pid</strong></span>
SCRIPTNAME=/etc/init.d/$NAME
 
set -e
[ -x "$DAEMON" ] || exit 0
 
do_start() {
 $DAEMON -c $CONFIGFILE || echo -n "nginx already running"
}
 
do_stop() {
 kill -INT `cat $PIDFILE` || echo -n "nginx not running"
}
 
do_reload() {
 kill -HUP `cat $PIDFILE` || echo -n "nginx can't reload"
}
 
case "$1" in
 start)
 echo -n "Starting $DESC: $NAME"
 do_start
 echo "."
 ;;
 stop)
 echo -n "Stopping $DESC: $NAME"
 do_stop
 echo "."
 ;;
 reload|graceful)
 echo -n "Reloading $DESC configuration..."
 do_reload
 echo "."
 ;;
 restart)
 echo -n "Restarting $DESC: $NAME"
 do_stop
 do_start
 echo "."
 ;;
 *)
 echo "Usage: $SCRIPTNAME {start|stop|reload|restart}" >&2
 exit 3
 ;;
esac
 
exit 0

 将上述脚本命名为nginx,保存到/etc/init.d目录下。尝试/etc/init.d/nginx start 命令,会报“权限不足”的错误,执行chmod +x /etc/init.d/nginx 给其赋执行权限。

可以用一下方式来执行此脚本:

/etc/init.d/nginx start

/etc/init.d/nginx sttop

/etc/init.d/nginx reload

/etc/init.d/nginx restart

如果想让此脚本开机自启动  还需在脚本头部家 chkconfig xx  xx等注释(具体需要参考chkconfig命令用法),让它支持chckconfig  然后执行/sbin/chkconfig nginx on 命令。同时,可以sudo /sbin/chkconfig --list nginx  来查看效果。

nginx 启动重启脚本的更多相关文章

  1. Nginx启动/重启脚本详解

    Nginx手动启动 停止操作 停止操作是通过向nginx进程发送信号(什么是信号请参阅linux文 章)来进行的步骤1:查询nginx主进程号ps -ef | grep nginx在进程列表里 面找m ...

  2. Nginx和PHP-FPM的启动/重启脚本 [转发]

    Nginx和PHP-FPM的启动/重启脚本 [转发] (2012-07-27 16:07:52) 标签: it 分类: 学习 转载自:http://blog.sina.com.cn/s/blog_53 ...

  3. nginx启动重启与升级以及检测配置文件

    查看nginx的主进程号 ps -ef|grep nginx 从容停止nginx kill - QUIT nginx主进程号 或者 kill - QUIT nginx的pid文件所在,例如我的 [ro ...

  4. Nginx启动/重启失败

    解决方案: Nginx启动或重启失败,一般是因为配置文件出错了,我们可以使用nginx -t方法查看配置文件出错的地方.也可以通过查看Nginx日志文件定位到Nginx重启失败的原因,Nginx日志文 ...

  5. linux nginx启动 重启 关闭命令

    启动操作 nginx -c /usr/local/nginx/conf/nginx.conf -c参数指定了要加载的nginx配置文件路径 停止操作停止操作是通过向nginx进程发送信号来进行的 步骤 ...

  6. nginx -- 启动, 重启, 关闭

    Nginx的启动.停止与重启 重启:  nginx -s reload 启动 启动代码格式:nginx安装目录地址 -c nginx配置文件地址 例如: [root@LinuxServer sbin] ...

  7. Linux下 Nginx 启动 重启 关闭

    命令 nginx -s reload :修改配置后重新加载生效 nginx -s reopen :重新打开日志文件 nginx -t -c /path/to/nginx.conf 测试nginx配置文 ...

  8. Nginx 启动脚本/重启脚本

    第一步先运行命令关闭nginx sudo kill `cat /usr/local/nginx/logs/nginx.pid` 第二步 vi /etc/init.d/nginx 输入以下内容 #!/b ...

  9. shell脚本之nginx启动脚本、统计日志字段、for循环实战、跳板机

    1.NGINX启动脚本 #!/bin/bash # chkconfig: 235 32 62 # description: nginx [ -f /etc/init.d/functions ] &am ...

随机推荐

  1. vue项目中使用md5.js及base64.js

    一.在项目根目录下安装 npm install --save js-base64 npm install --save js-md5 二.在项目文件中引入 import md5 from 'js-md ...

  2. 调用 COM 对象

    调用 COM 对象 大多数 Windows 程序猿都熟悉组件对象模型(Component Object Model,COM).在某程度上..NET 框架 就是为了替换 COM,可是.系统仍然保留了这个 ...

  3. Objective-C 语法之 Debug 表达式

    main.m #import <Foundation/Foundation.h> #import "TestClass.h" int main(int argc, co ...

  4. extJS 中 ext.data 介绍

    ext.data 最主要的功能是获取和组织数据结构,并和特定控件联系起来,于是,Ext.data成了数据的来源,负责显示数据. Ext.data在命名空间中定义了一系列store.reader和pro ...

  5. logback -- 配置详解 -- 一 -- <configuration>及子节点

    附: logback.xml实例 logback -- 配置详解 -- 一 -- <configuration>及子节点 logback -- 配置详解 -- 二 -- <appen ...

  6. 8 -- 深入使用Spring -- 4... Spring的AOP

    8.4 Spring的AOP AOP(Aspect Orient Programming),也就是面向切面编程,最为面向对象编程的一种补充. AOP和OOP互为补充,面向对象编程将程序分解成各个层次的 ...

  7. Linux Redis安装,Linux如何安装Redis,Linux Redis自动启动,Redis开机启动

    Linux Redis安装,Linux如何安装Redis,Linux Redis自动启动,Redis开机启动 >>>>>>>>>>>& ...

  8. 【RF库Collections测试】Keep In Dictionary

    Name:Keep In DictionarySource:Collections <test library>Arguments:[ dictionary | *keys ]Keeps ...

  9. Jar命令

    JAR包是Java中所特有一种压缩文档,其实大家就可以把它理解为.zip包;当然也是有区别的,JAR包中有一个META-INF\MANIFEST.MF文件,当你打成JAR包时,它会自动生成. 一.ja ...

  10. Elasticsearch 5.x 关于term query和match query的认识

    http://blog.csdn.net/yangwenbo214/article/details/54142786 一.基本情况 前言:term query和match query牵扯的东西比较多, ...