Ubuntu開機自啟動的兩種方法總結
阿新 • • 發佈:2018-11-04
一.第一種方法
1,新建個指令碼檔案new_service.sh
#!/bin/bash
# command content
exit 0
2,設定許可權
sudo chmod 755 new_service.sh
3,把指令碼放置到啟動目錄下
sudo mv new_service.sh /etc/init.d/
4,將指令碼新增到啟動指令碼
執行如下指令,在這裡90表明一個優先順序,越高表示執行的越晚
cd /etc/init.d/
sudo update-rc.d new_service.sh defaults 90
移除Ubuntu開機指令碼
sudo update-rc.d -f new_service.sh remove
一.第二種方法
rc.local指令碼
rc.local指令碼是一個ubuntu開機後會自動執行的指令碼,我們可以在該指令碼內新增命令列指令。該指令碼位於/etc/路徑下,需要root許可權才能修改。
該指令碼具體格式如下:
#!/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
注意: 一定要將命令新增在 exit 0之前