#! /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=/data/apps/nginx/sbin/$NAME

CONFIGFILE=/data/apps/nginx/conf/$NAME.conf
PIDFILE=/data/logs/nginx/$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
       
;;

esac

# chmod +x /etc/init.d/nginx
# sysv-rc-conf

退出按【q】 就行了
上次忘记说了,这次补一下  这个【1\2\3\4\5\0\6\S】启动选项最后有个【 S
】的选项,他的意思表示开机后就会运行的服务。
运行级别说明:
S   表示开机后就会运行的服务
0   表示关机
1   表示单用户模式 
(类似windows的安全模式)
2   表示无网络服务的多用户模式
3   表示多用户模式
4   系统预留(暂没使用)
5   表示多用户图形模式
6   表示重启
打X 表示开启该服务。
 
sysv-rc-conf nginx on

service nginx -s reload | stop | restart | start

Ubuntu Nginx 开机自启动的更多相关文章

  1. centos7.x设置nginx开机自启动

    设置nginx开机自启动(centos7.x) 第一步:进入到/lib/systemd/system/目录 [root@iz2z init.d]# cd /lib/systemd/system/ 第二 ...

  2. Centos下安装并设置nginx开机自启动

    一.在centos环境下安装下载并安装nginx,由于nginx需要依赖一些环境才能安装,主要依赖g++.gcc.openssl-devel.pcre-devel和zlib-devel这些环境,首先得 ...

  3. 设置Apache(httpd)和Nginx 开机自启动

     方法1: 进入目录: vi  /etc/rc.d/rc.local #设置apache 和 nginx 开机自启动/usr/sbin/apachectl start/usr/sbin/nginx s ...

  4. centos7下安装、配置Nginx、设置Nginx开机自启动

    测试环境: [root@centos-linux ~]# cat /etc/redhat-releaseCentOS Linux release 7.6.1810 (Core) [root@cento ...

  5. Ubuntu14.04配置nginx开机自启动项

    原文: https://www.jianshu.com/p/2e03255cfabb ubuntu配置开机自动启动服务 ---------------------------------------- ...

  6. Linux(CentOS)系统下设置nginx开机自启动

    Nginx 是一个很强大的高性能Web和反向代理服务器.下面介绍在linux下安装后,如何设置开机自启动.首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令:vi ...

  7. 设置Nginx开机自启动

    Nginx 是一个很强大的高性能Web和反向代理服务器.虽然使用命令行可以对nginx进行各种操作,比如启动等,但是还是根据不太方便.下面介绍在linux下安装后,如何设置开机自启动. 首先,在lin ...

  8. Centos8配置Nginx开机自启动

    第一步:创建service文件,并编辑(可理解为开机时自动启动Nginx的脚本服务文件) vim /lib/systemd/system/nginx.service /lib 与 /usr/lib 里 ...

  9. 十一、设置Nginx开机自启动

    一.创建nginx.service文件 [root@svr7 ~]# vim /lib/systemd/system/nginx.service [Unit]Description=nginx ser ...

随机推荐

  1. propertychange 不起作用

    兼容性问题.将$("#systemLogSettings td[name='nMaxFileSize'] input").on("input propertychange ...

  2. 初学者易上手的SSH-整合

    许久没更新博客了! spring还有一章aop(面向切面),我就没讲述了,你们可以去看下代理模式. 那么我们开始整合:struts2  2.3.4 ,hibernate 5.2.10 ,spring ...

  3. 虚拟机安装 deepin Linux 注意事项

    主要要注意下面几点: 一.虚拟机"客户机操作系统"类型 选择"Windows 7 x64" 选择"客户机操作系统"类型,这个选择十分重要,D ...

  4. PHP能引起安全的函数

    php中需要禁用以下函数来提高安全性 打开php.ini  找到 disable_functions .然后禁用以下函数 disable_functions = pcntl_alarm, pcntl_ ...

  5. 多线程 - pthread、NSThread

    1. pthread pthread 简单介绍下,pthread是一套通用的多线程的API,可以Unix / Linux / Windows 等徐彤跨平台使用,使用C语言编写,需要程序员自己管理线程的 ...

  6. XAMPP重要文件目录及配置

    一.XAMPP 的安装过程 1:下载XAMPP 的 Linux 版 (1.7.4) http://www.apachefriends.org/en/xampp-linux.html#374 2:安装( ...

  7. google软件测试之道读后感(一)

    这几天在抽空读一本新书,久负盛名的<google软件测试之道>.之前在网络上一点一点地看过它的英文版,很受触动,还做了很长的读书笔记,现在看到了中文版,才恍觉之前的好些理解存在不恰当的地方 ...

  8. 有关.NET链接Oracle数据库,使用连接池pooling=true时问题

    .net链接oracle数据库时,当链接字符串中pooling=true时,视图结构变更时程序报错问题,还请高手指教 现象: 链接字符串: 注意:这里pooling=true: 测试视图: 执行的SQ ...

  9. mongoDB之数据类型

    mongoDB之数据类型 Object  ID :文档的id String: 字符串,最常用,必须是utf-8 Boolean:布尔值,true 或者false Integer:整数 Double:浮 ...

  10. 转自知乎-wifi破解

    上点python有意思的代码. 环境准备 python2.7 pywifi模块 字典 清除系统中的任何wifi连接记录 导入模块 这里用的模块就这三个 pywifi的_wifiutil_linux.p ...