歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> 學習Linux >> Debian開機啟動管理

Debian開機啟動管理

日期:2017/3/6 9:31:33   编辑:學習Linux

Debian開機啟動管理


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

本文永久更新鏈接地址:

http://xxxxxx/Linuxjc/1141590.html TechArticle

Copyright © Linux教程網 All Rights Reserved