1. 程式人生 > >ubuntu14.04 設定開機自啟動指令碼

ubuntu14.04 設定開機自啟動指令碼

方法一, 編輯rc.local指令碼
ubuntu開機之後會執行/etc/rc.local檔案中的指令碼。所以可以直接在/etc/rc.local中新增啟動指令碼。指令碼要新增到 exit 0 之前。
以下是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

方法二, 新增一個ubuntu的開機啟動服務
分為以下幾個步驟:
1)新建一個指令碼檔案 new_services.sh

#!/bin/bash
# command content
exit 0

2)將指令碼放置到啟動目錄下

sudo mv new_services.sh /etc/init.d/

3)設定許可權

sudo chmod 755
new_services.sh

4)將指令碼新增到啟動指令碼

cd /etc/init.d/
sudo update-rc.d new_serviecs.sh defaults 90

這裡90表明一個優先順序,越高表示執行的越晚。

移除ubuntu開機指令碼

sudo update-rc.d -f new_services.sh remove