ubuntu添加開機啟動項,ubuntu18.04設置開機自啟動的腳本

 2023-12-25 阅读 29 评论 0

摘要:ubuntu-18.04不能像ubuntu16.04那樣通過編輯rc.local來設置開機啟動腳本,但是如果在18.04鐵了心要通過rc.local來添加開機自啟動腳本也不是不行,方法如下: 1、建立rc-local.service文件,(如果不是root用戶記得前面要加sudo操作) vi

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文件來添加開機自啟動腳本了。

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/194833.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息