首先把自己的腳本放到/etc/init.d中,,然后執(zhí)行如下指令:
update-rc.d a start 90 2 3 4 5 . stop 90 0 1 6 .
其中a就是你的腳本,注意有兩個點(diǎn)。
a腳本范例。
#!/bin/sh
# Source function library.
if [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
else
. /lib/lsb/init-functions
fi
MOD=/a.ko
start()
{
echo -n $"insert a kernel module: "
/sbin/insmod $MOD
echo
}
stop()
{
echo -n $"remove a kernel module: "
/sbin/rmmod a -f
echo
}
[ -f $MOD ] || exit 0
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload}"
update-rc.d命令,是用來自動的升級System V類型初始化腳本,簡單的講就是,哪些東西是你想要系統(tǒng)在引導(dǎo)初始化的時候運(yùn)行的,哪些是希望在關(guān)機(jī)或重啟時停止的,可以用它來幫你設(shè)置。這些腳本的連接 位于/etc/rcn.d/LnName,對應(yīng)腳本位于/etc/init.d/Script-name.
1、設(shè)置指定啟動順序、指定運(yùn)行級別的啟動項(xiàng):
update-rc.d <service> start <o(jì)rder> <runlevels>
2、設(shè)置在指定運(yùn)行級中,按指定順序停止:
update-rc.d <service> stop <o(jì)rder> <runlevels>
3、從所有的運(yùn)行級別中刪除指定的啟動項(xiàng):
update-rc.d -f <script-name> remove
例如:
update-rc.d script-name start 90 1 2 3 4 5 . stop 52 0 6 .
start 90 1 2 3 4 5 . : 表示在1、2、3、4、5這五個運(yùn)行級別中,按先后順序,由小到大,第90個開始運(yùn)行這個腳本。
stop 52 0 6 . :表示在0、6這兩個運(yùn)行級別中,按照先后順序,由小到大,第52個停止這個腳本的運(yùn)行。
如果在 /etc/init.d 中加入一個 script,還須要制作相關(guān)的 link
在 /etc/rc*.d 中。K 開頭是 kill , S 開頭是 start , 數(shù)字順序代表啟動的順序。(SysV)
update-rc.d 可以幫你的忙。
例:
在 /etc/init.d 中建立一個叫作 zope 的 script , 然后
update-rc.d zope defaults
就會產(chǎn)生以下鏈結(jié)::
Adding system startup for /etc/init.d/zope ...
/etc/rc0.d/K20zope -> ../init.d/zope
/etc/rc1.d/K20zope -> ../init.d/zope
/etc/rc6.d/K20zope -> ../init.d/zope
/etc/rc2.d/S20zope -> ../init.d/zope
/etc/rc3.d/S20zope -> ../init.d/zope
/etc/rc4.d/S20zope -> ../init.d/zope
/etc/rc5.d/S20zope -> ../init.d/zope
其他進(jìn)階使用方式請 man update-rc.d