設置自啟動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”文件里的內容了,就是這么簡單


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM