设置自启动nginx(适用于其他软件)(LinuxDeploy里的Ubuntu)

LinuxDeploy里的Ubuntu自启动nginx(适用于其他软件)

网上的教程是这样的,基本能用

1.编写脚本(这个文件及其内容安装Nginx后自动生成,没有的话内容自己Google)
$ sudo vi /etc/init.d/nginx

这样在控制台就很容易的操作nginx了:查看Nginx当前状态、启动Nginx、停止Nginx、重启Nginx…

android@localhost:~$ /etc/init.d/nginx
Usage: nginx {start|stop|restart|reload|force-reload|status|configtest|rotate|upgrade}
android@localhost:~$ /etc/init.d/nginx start
* Starting nginx nginx                                                                                                               [fail]
android@localhost:~$ /etc/init.d/nginx status
* nginx is running
android@localhost:~$
2.将 “ /etc/init.d/nginx start” 命令加入到 “/etc/rc.local” 文件中,这样开机的时候nginx就默认启动了

由于我的Ubuntu里没有 “rc.local” 文件,因此需要自己做一个

1.自行创建 /etc/rc.local 添加以下默认内容(在 exit 0 之前加入自定义内容)
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

exit 0
2.执行以下命令确保 rc.local 开机自启
sudo chown root:root /etc/rc.local
sudo chmod 755 /etc/rc.local
sudo systemctl enable rc-local.service

但是由于这个系统是运行在容器里的,没法用 “systemctl”

Running in chroot, ignoring request.

难道就没办法了吗?

当然不会,诀窍就在手机上Linux Deploy 这个APP里

1.点击右下角的设置图标进入设置界面
2.划到“初始化”那块,“启用”打上勾

初始化系统里面有两个选项,分别为“run-parts”和“sysv”,不知道是干什么用的。不必管他,默认即可(我的默认是“run-parts”)。

3.进入“初始化设置”选项,看到什么了?惊不惊喜!

初始化路径 —> /etc/rc.local

就是这样,一般情况下只要把“初始化”打上勾就行了,这样就可以开机自动执行“rc.local”文件里的内容了,就是这么简单

posted @ 2019-02-20 20:31  路安达  阅读(5546)  评论(1编辑  收藏  举报