1.建立Autorun Script,如下(以httpd為例):
#/bin/bash
#chkconfig: 345 79 15
# 345:表示在runlevel345下執行 79:表Start順序 15:表Kill順序
#ScriptName: httpd
APACHECTL=/usr/local/dpstg/bin/apachectl
[ -f $APACHECTL ] exit 0
case "$1" in
start)
echo -n "Starting httpd:"
$APACHECTL startssl
touch /var/lock/subsys/httpd
echo
;;
stop)
echo -n "Shutting down httpd:"
$APACHECTL stop
echo "done"
rm -f /var/lock/subsys/httpd
;;
*)
echo "Usage: httpd {startstop}"
exit 1
esac
exit 0
2.將此Script copy至 /etc/rc.d/init.d/
並chmod為750
3.根據所需其自動開啟的runlevel下,建立相關soft link
ex: in runlevel 3
$ln -sf /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S99httpd
$ln -sf /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/K99httpd
S:Start
K:Kill
99:為開始或終止的順序設定(可自訂)
-----------------------------
註:也可直接下$chkconfig --add httpd
將httpd加入chkconfig管理,此方式系統會根據Script裡面的#chkconfig: 345 79 15
在runlevel 3.4.5去做相對應的soft link
------------------------------
4.將此程式在runlevel開啟 (要開啟的runlevel也需做第3步驟)
$chkconfig --level 345 httpd on
PS:如果不用soft link的方式,簡略之方法為直接在 /etc/rc.d/rc.local
加入 /etc/rc.d/init.d/httpd start
也可達成開機AutoRun
沒有留言:
張貼留言