Ubuntu 16.04开机自启Nginx简单脚本
本文要记述的是最简单的Ubuntu下开机自启 nginx的脚本
这里将nginx装在了/usr/local/nginx目录下,nginx本身没有注册成服务,所以直接使用服务开机自启是不行的,除非自己写nginx.service脚本,这不在本文范畴内。
创建脚本文件
$ sudo vim /etc/init.d/nginx.sh
脚本内容,注意替换root密码、nginx执行文件目录和配置文件目录
#!/bin/bash #auto run nginx when system startup sudo -S /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf << EOF root密码 EOF exit 0
指定开机自启,最后可以添加优先级,比如,90
$ sudo update-rc.d nginx.sh defaults
此时重启就可以发现nginx已经开机自启了。
如果你在写完启动脚本的后,手动运行该脚本以确定是否可行的话,你会得到一个错误
insserv: warning: script 'nginx.sh' missing LSB tags and overrides
,这种错误不会影响脚本的启动,只是提示脚本写的不规范,没有在脚本中发现以### BEGIN INIT INFO
开头,以### END INIT INFO
结尾的标签,因为没有影响,这里就没有写,可以参考下边的脚本去去除这个错误:
#!/bin/sh # kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing. if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script fi ### BEGIN INIT INFO # Provides: skeleton # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Example initscript # Description: This file should be used to construct scripts to be # placed in /etc/init.d. This example start a # single forking daemon capable of writing a pid # file. To get other behavoirs, implemend # do_start(), do_stop() or other functions to # override the defaults in /lib/init/init-d-script. ### END INIT INFO # Author: Foo Bar <foobar@baz.org> # # Please remove the "Author" lines above and replace them # with your own name if you copy and modify this script. DESC="Description of the service" DAEMON=/usr/sbin/daemonexecutablename
本文为实操笔记,转载请注明出处 https://www.cnblogs.com/hellxz/p/9441949.html
分类:
Linux
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了