Centos開機啟動指令碼

來源:互聯網
上載者:User

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其他動作
chkconfig --del newservice //刪除服務
chkconfig newservice off   //關閉開機啟動
service newservice status  //查詢服務狀態
service newservice stop    //停止服務
service newservice start   //啟動服務

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.