Ubuntu14.04配置nginx开机自启动项
来源:互联网 发布:安卓7.0 知乎 编辑:程序博客网 时间:2024/06/08 01:02
1. 创建/etc/init.d/nginx文件
#! /bin/sh# Author: rui ding# Modified: Geoffrey Grosenbach http://www.linuxidc.com# Modified: Clement NEDELCU# Reproduced with express authorization from its contributorsset -ePATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/binDESC="nginx daemon"NAME=nginxDAEMON=/usr/local/nginx/sbin/$NAMESCRIPTNAME=/etc/init.d/$NAME# If the daemon file is not found, terminate the script.test -x $DAEMON || exit 0d_start() { $DAEMON || echo -n " already running"}d_stop() { $DAEMON –s quit || echo -n " not running"}d_reload() { $DAEMON –s reload || echo -n " could not reload"}case "$1" in start)echo -n "Starting $DESC: $NAME"d_startecho ".";;stop)echo -n "Stopping $DESC: $NAME"d_stopecho ".";;reload)echo -n "Reloading $DESC configuration..."d_reloadecho "reloaded.";;restart)echo -n "Restarting $DESC: $NAME"d_stop# Sleep for two seconds before starting again, this should give the# Nginx daemon some time to perform a graceful stop.sleep 2d_startecho ".";;*)echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2exit 3;;esacexit 0
增加可执行权限
chmod a+x /etc/init.d/nginx
2.利用sysv-rc-conf命令将其在对应rc?.d目录下建立一个软链接:
sysv-rc-conf nginx on
该命令会在rc2.d ~ rc5.d目录下都建立了一个nginx的软链接。
这里需要特别说明的是,Ubuntu系统下没有RedHat系统下的chkconfig命令。
但Ubuntu有一个类似的命令: sysv-rc-conf
。
通过apt-get命令完成sysv-rc-conf
软件的安装。
学习资料
Linux系统的运行级别有7个,分别对应的:
- 0: 关机
- 1: 单用户(维护)
- 2~5: 多用户
- 6: 重启
可以通过runlevel
命令来查看当前系统的运行等级:
- 1
- 2
- 1
- 2
其中第一个表示上一次的运行等级,N表示没有上一次运行等级的记录;第二个表示当前运行等级,这里为2.
linux中所有开机自启动项目运行脚本都放在/etc/init.d/
目录下;同时在/etc/
目录下有rc?.d目录,分别对应了7中不同的运行级别:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
这里rc2.d目录就对应了我们系统当前的运行等级。
其中里面的一些文件其实都是/etc/init.d/
目录下文件的软链接:
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
整个开机自启动项的流程如下:
- 开机后,系统获得当前的运行等级(例如这里的等级为2);
- 运行
/etc/rc?.d
目录下的所有可执行文件(这里运行/etc/rc2.d/
目录下所有的软链接。这些软链接的源文件都保存在/etc/init.d/
目录下)。
因此我们只需要在/etc/init.d/完成启动nginx
进程的脚本,然后在/etc/rc2.d/
做对应的软链接即可。
阅读全文
2 0
- Ubuntu14.04配置nginx开机自启动项
- Ubuntu14.04配置nginx开机自启动项
- ubuntu14.04 配置开机启动
- ubuntu14.04 设置开机自启动脚本
- 开机自启动nginx
- 开机自启动nginx
- nginx开机自启动
- 【ubuntu】 ubuntu14.04 设置开机自启动脚本
- Nginx windows开机自启动
- nginx开机自启动设置
- linux 开机自启动nginx
- Ubuntu14.04 增加开机启动项
- ubuntu14下nginx自启动脚步编写
- nginx加入到系统服务并开机自启动项
- Ubuntu nginx 开机启动配置
- 开机服务自启动配置
- tomcat开机自启动配置
- linux 配置开机自启动
- NGUI修改spriteName后鼠标悬浮又变回原来的spriteName
- bzoj 1432: [ZJOI2009]Function
- Docker部署Ghost
- 基数排序(C语言版本)
- 约瑟夫环
- Ubuntu14.04配置nginx开机自启动项
- CentOS7.x下安装Nginx、PHP及生成自签名证书、开启http2(上)
- Redis和ES都查不出来数据
- c++类
- Codeforces 278B
- Parameter 'seckillId' not found. Available parameters are [0, 1, param1, param2]
- 快排法思路与代码
- 客户给我的感谢信
- MySQL外键