ubuntu-18.04不能像ubuntu16.04那樣通過編輯rc.local來設置開機啟動腳本,但是如果在18.04鐵了心要通過rc.local來添加開機自啟動腳本也不是不行,方法如下:
1、建立rc-local.service文件,(如果不是root用戶記得前面要加sudo操作)
vi /etc/systemd/system/rc-local.service
ubuntu添加開機啟動項、2、將下列內容復制進rc-local.service文件
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99[Install]
WantedBy=multi-user.target
3、創建文件rc.local
vi /etc/rc.local
4、將下列內容復制進rc.local文件,這里相當于往 /usr/local/hello.log 寫入 “hello world”,如果開機自啟動了rc.local這個服務,就會執行這個寫入的動作,通過查看hello.log的內容,可以確認是否生效。
#!/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.
echo "hello world" > /usr/local/hello.log
exit 0
ubuntu設置開機自啟。5、給rc.local加上權限
chmod +x /etc/rc.local
6、啟用服務和檢查狀態
systemctl enable rc-local
systemctl status rc-local.service
7、重啟并檢查hello.log文件,確認是否生效
root@qcom_865:~# cat /usr/local/hello.log
hello world
ubuntu開機自啟動程序。8、第7步如果能看到hello world的打印,說明設置成功,你就可以通過編輯rc.local文件來添加開機自啟動腳本了。
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态