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
Ubuntu 16.04开机自启Nginx简单脚本的更多相关文章
- Ubuntu 16.04 LTS nodejs+pm2+nginx+git 基础安装及配置环境(未完,未整理)
-.Ubuntu 安装nodejs 以下内容均在命令行,完成,首先你要去你电脑的home目录:cd ~. [sudo] apt-get update [sudo] apt-get upgrade ap ...
- Ubuntu 16.04开机自动挂载硬盘分区(转)
说明:如果挂载以前旧硬盘分区时不需要第2.3步! 1.查看Linux硬盘信息: sudo fdisk -l 2.格式化新硬盘(很危险,注意操作时确定硬盘分区的位置): sudo mkfs.ext4 / ...
- Ubuntu 16.04开机进入命令行(tty1)+分辨率调节+字体颜色设置+中文乱码解决(解决虚拟终端Ctrl+Alt+F1分辨率太大)
一.开机进入命令行模式(tty1) sudo vim /etc/default/grub 把GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”改成GRUB_CMDLIN ...
- 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 ...
- Ubuntu 16.04开机自动开启数字键盘NumLock
注意:以下方法不适合在登录时开启,只能是登录后开启.而且我经过测试之后会自动暗下去,但是不影响功能使用.这个是BUG的修复方法:https://askubuntu.com/questions/5090 ...
- linux学习之路——ubuntu 16.04 开机开启数字小键盘解决方法
第一步:安装numlockx,输入命令 sudo apt-get install numlockx 第二步:用 vim 打开 rc.local 文件,输入命令 sudo vim /etc/rc.loc ...
- 如何在Ubuntu 16.04上安装Nginx
原文链接https://www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04 介绍 Nginx是世 ...
- 【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 ...
- Ubuntu 16.04设置rc.local开机启动命令/脚本的方法
Ubuntu 16.04设置rc.local开机启动命令/脚本的方法 Ubuntu 16.04设置rc.local开机启动命令/脚本的方法(通过update-rc.d管理Ubuntu开机启 ...
随机推荐
- mount命令详解及常见问题汇总
一 .mount命令(用来挂载硬盘或镜像等) 用法:mount [-t vfstype] [-o options] device dir1.-t vfstype 指定文件系统的类型,通常不必指定.mo ...
- Postman安装与入门使用
Postman官方下载地址:https://www.getpostman.com/apps Postman 是一个很强大的 API调试.Http请求的工具.我们可以用来很方便的模拟get或者post或 ...
- SQL Server中事务日志管理的步骤,第5级:完全恢复模式管理日志(译)
SQL Server中事务日志管理的步骤,第5级:完全恢复模式管理日志 作者:Tony Davis,2012/01/27 系列 本文是进阶系列的一部分:SQL Server中事务日志管理的步骤 当事情 ...
- 机器学习英雄访谈录之 Kaggle Kernels 专家:Aakash Nain
目录 机器学习英雄访谈录之 Kaggle Kernels 专家:Aakash Nain 正文 对我的启发 机器学习英雄访谈录之 Kaggle Kernels 专家:Aakash Nain Sanyam ...
- kubeadm安装K8S单master双节点集群
宿主机:master:172.16.40.97node1:172.16.40.98node2:172.16.40.99 # 一.k8s初始化环境:(三台宿主机) 关闭防火墙和selinux syste ...
- 微软职位内部推荐-Software Development Engineer II_Commerce
微软近期Open的职位: Are you looking for a high impact project that involves processing of billions of dolla ...
- PAT甲题题解-1032. Sharing (25)-链表水题
#include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...
- C# 7中函数多值返回_转自InfoQ
本文要点 应遵循<.NET设计规范:.NET约定惯用法与模式>一书.和十年前第一版出版时一样,书中给出的原则在当前依然有指导意义. API设计是最重要的.设计不好的API会在极大地增加软件 ...
- Web网络服务介绍
Web网络服务也叫WWW(World Wide Web),一般是指能够让用户通过浏览器访问到互联网中文档资源服务.目前提供WEB网络服务的程序有Apache .Nginx 和 IIS 等等,Web ...
- 『编程题全队』Alpha阶段事后诸葛亮分析
一.设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? Answer: (1)我们软件主要解决个人和团队的事务管理问题 (2)我们软件的定义明确和清楚 ...