Debian開機啟動管理

來源:互聯網
上載者:User

Debian開機啟動管理

Linux下,services的啟動、停止等通常是通過/etc/init.d的目錄下的指令碼來控制的。
在啟動或改變運行層級是在/etc/rcX.d中來搜尋指令碼。其中X是運行層級。

比如Apache2,安裝完成後,預設或啟動。比如我安裝了vagrant的LMPA的box。需要禁止掉自啟動,就需要禁止掉這個服務,然後在需要的時候使用

/usr/sbin/apachectl start     #/etc/init.d/apache2 start 

在debian中使用 update-rc.d命令來實現

   update-rc.d [-n] [-f] <basename> remove   update-rc.d [-n] <basename> defaults [NN | SS KK]   update-rc.d [-n] <basename> start|stop NN runlvl [runlvl] [...] .   update-rc.d [-n] <basename> disable|enable [S|2|3|4|5]-n: not really-f: force
  1. 刪除服務

    update-rc.d -f apache2 remove # -f 為強制移除

  2. 添加服務

    update-rc.d apache2 defaults

並且可以指定該服務的啟動順序:

update-rc.d apache2 defaults 90

還可以更詳細的控制start與kill順序:

update-rc.d apache2 defaults 20 80

其中前面的20是start時的運行順序層級,80為kill時的層級。也可以寫成:

update-rc.d apache2 start 20 2 3 4 5 . stop 80 0 1 6 .

其中0~6為運行層級。 update-rc.d命令不僅適用Linux服務,編寫的指令碼同樣可以用這個命令設為開機自動運行

在debian6中使用update-rc.d會報錯,如下:

  update-rc.d: using dependency based boot sequencing

可以使用 insserv 命令來代替 update-rc.d

insserv [<options>] [init_script|init_directory]Available options:  -h, --help       This help.  -r, --remove     Remove the listed scripts from all runlevels.  -f, --force      Ignore if a required service is missed.  -v, --verbose    Provide information on what is being done.  -p <path>, --path <path>  Path to replace /etc/init.d.  -o <path>, --override <path> Path to replace /etc/insserv/overrides.  -c <config>, --config <config>  Path to config file.  -n, --dryrun     Do not change the system, only talk about it.  -d, --default    Use default runlevels a defined in the scripts

比如
insserv -r apache2

本文永久更新連結地址:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.