本文要记述的是最简单的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

Ubuntu 16.04开机自启Nginx简单脚本的更多相关文章

  1. Ubuntu 16.04 LTS nodejs+pm2+nginx+git 基础安装及配置环境(未完,未整理)

    -.Ubuntu 安装nodejs 以下内容均在命令行,完成,首先你要去你电脑的home目录:cd ~. [sudo] apt-get update [sudo] apt-get upgrade ap ...

  2. Ubuntu 16.04开机自动挂载硬盘分区(转)

    说明:如果挂载以前旧硬盘分区时不需要第2.3步! 1.查看Linux硬盘信息: sudo fdisk -l 2.格式化新硬盘(很危险,注意操作时确定硬盘分区的位置): sudo mkfs.ext4 / ...

  3. Ubuntu 16.04开机进入命令行(tty1)+分辨率调节+字体颜色设置+中文乱码解决(解决虚拟终端Ctrl+Alt+F1分辨率太大)

    一.开机进入命令行模式(tty1) sudo vim /etc/default/grub 把GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”改成GRUB_CMDLIN ...

  4. Ubuntu 16.04 LTS 安装配置 Nginx 1.10.0 Php7.0-FPM

    1. 安装Nginx,Php-7.0 ~$ sudo add-apt-repository ppa:nginx/stable ~$ sudo apt-get update ~$ sudo apt-ge ...

  5. Ubuntu 16.04开机自动开启数字键盘NumLock

    注意:以下方法不适合在登录时开启,只能是登录后开启.而且我经过测试之后会自动暗下去,但是不影响功能使用.这个是BUG的修复方法:https://askubuntu.com/questions/5090 ...

  6. linux学习之路——ubuntu 16.04 开机开启数字小键盘解决方法

    第一步:安装numlockx,输入命令 sudo apt-get install numlockx 第二步:用 vim 打开 rc.local 文件,输入命令 sudo vim /etc/rc.loc ...

  7. 如何在Ubuntu 16.04上安装Nginx

    原文链接https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04 介绍 Nginx是世 ...

  8. 【netcore基础】ubuntu 16.04 搭建.net core 2.1 linux 运行环境 nginx反向代理 supervisor配置自启动

    今天来整理下 netcore 在 linux(ubuntu) 上的运行环境搭建 对应版本 ubuntu 16.04 .net core 2.1 nginx version: nginx/1.10.3 ...

  9. Ubuntu 16.04设置rc.local开机启动命令/脚本的方法

    Ubuntu 16.04设置rc.local开机启动命令/脚本的方法       Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启 ...

随机推荐

  1. nginx 跳转

    nginx 跳转 一.需求:当需要在别的机访问本机房的服务器问题. 虚拟主机头配置 server { listen ; server_name test.zlx.com; location / { i ...

  2. Jupyter Notebook 工作空间 / 默认路径 的设置方式

    Jupyter notebook 安装后,启动后,默认的工作空间是当前用户目录.为了方便对文档进行管理,往往需要自行设置工作空间. 下面介绍两种亲试有效的工作空间设置方法. 1.修改快捷方式 对 Ju ...

  3. Appium自动化部署及连接Appium服务

    Appium自动化部署: 1)安装appium桌面程序安装:超链接 2)安装客户端 pip install appium-python-client 3)安装服务器 安装 Nodejs 4)连接app ...

  4. proe工程图输出dwg/dxf文件设置

    网上看到不少人分享proe转转dxf/dwg配置文件的,但是看了一圈,几乎都没有涉及到转化线型的,所以自己整理自己的配置文件,写在这里分享出来. 以Pro/engineer WF5.0为例: 1.复制 ...

  5. MiniNet自定义拓扑

    SDN 与 Mininet 概述 SDN 全名为(Software Defined Network)即软件定义网络,是现互联网中一种新型的网络创新架构,其核心技术 OpenFlow 通过网络设备控制面 ...

  6. shell 的 export命令

    export 功能说明:设置或显示环境变量.语 法:export [-fnp][变量名称]=[变量设置值]补充说明:在shell中执行程序时,shell会提供一组环境变量.export可新增,修改或删 ...

  7. ElasticSearch 2 (27) - 信息聚合系列之故事开始

    ElasticSearch 2 (27) - 信息聚合系列之故事开始 摘要 到目前为止,本书都在着重介绍搜索.对于搜索,我们有查询条件以及与查找到与条件匹配的集合.这个过程就和如大海捞针一样. 对于聚 ...

  8. ElasticSearch 2 (17) - 深入搜索系列之部分匹配

    ElasticSearch 2 (17) - 深入搜索系列之部分匹配 摘要 到目前为止,我们介绍的所有查询都是基于完整术语的,为了匹配,最小的单元为单个术语,我们只能查找反向索引中存在的术语. 但是, ...

  9. python文本替换

    file_data = '' str1 = ' str2 = ' with open(loginfofile, 'r+') as f: #打开文件,r+模式,读取 for line in f: if ...

  10. qemu-img.exe 工具 简介

    1. 下载地址 https://cloudbase.it/qemu-img-windows/ 2. 解压缩 然后扔到 system32目录下 或者是 修改环境变量-- 我很懒,我决定扔到system3 ...