Centos開機啟動指令碼
一)在/etc/init.d下建立啟動指令碼,並將其設定為可執行檔(chmod +x)
#!/bin/bash# chkconfig: - 85 15# description: Gold Web Server.# Source function library.. /etc/rc.d/init.d/functionshomedir=/home/jack/goldweb/binprog=goldwebpidfile=/var/run/goldweb.pidstart() { echo -n $"Starting $prog: " cd $homedir ./goldweb &}stop() { echo -n $"Stopping $prog: " killproc -p ${pidfile}
}case "$1" in start) start ;; stop) stop ;; status) status -p ${pidfile} ;; restart) stop start ;; *) echo $"Usage: $prog {start|stop|restart|status}" ;;esac注意:必須有下面兩個注釋,否則無法用chkconfig添加
# chkconfig: - 85 15# description: Gold Web Server.
其中chkconfig後跟分別是運行級、啟動優先順序、關閉優先順序
# 預設的運行級,RHS用到的層級如下:
0:關機
1:單一使用者模式
2:無網路支援的多使用者模式
3:有網路支援的多使用者模式
4:保留,未使用
5:有網路支援有X-Window支援的多使用者模式
6:重新引導系統,即重啟
對各個運行級的詳細解釋:
0 為停機,機器關閉。
1 為單一使用者模式,就像Win9x下的安全模式類似。
2 為多使用者模式,但是沒有NFS支援。
3 為完整的多使用者模式,是標準的運行級。
4 一般不用,在一些特殊情況下可以用它來做一些事情。例如在筆記本 電腦的電池用盡時,可以切換到這個模式來做一些設定。
5 就是X11,進到X Window系統了。
6 為重啟,運行init 6機器就會重啟。
二)用chkconfig添加開機啟動
chkconfig --add newservice
chkconfig --list newservicenewservice 0:off 1:off 2:off 3:on 4:on 5:on 6:off
chkconfig newservice on
chkconfig --del newservice //刪除服務
chkconfig newservice off //關閉開機啟動
service newservice status //查詢服務狀態
service newservice stop //停止服務
service newservice start //啟動服務