Init

‘insserv’ 採取哪些步驟來安裝 init(System-V) 腳本?

  • October 6, 2017

為了學習,我在 Debian Wheezy(init來自 sysvinit 軟體包版本 2.88dsf-41+deb7u1)下使用了 LSB 初始化腳本。我的腳本如下:

# cat /etc/init.d/test-script
#! /bin/sh
### BEGIN INIT INFO
# Provides:          test
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: test script
# Description:       test script
### END INIT INFO

# always executes
touch /tmp/test-file

case "$1" in
 start)
   echo "Starting script test"
   touch /tmp/test-file-start
   ;;
 stop)
   echo "Stopping script test"
   touch /tmp/test-file-stop
   ;;
 restart)
   echo "Restarting script test"
   touch /tmp/test-file-restart
   ;;
 force-reload)
   echo "Force-reloading script test"
   touch /tmp/test-file-force-reload
   ;;
 status)
   echo "Status of test"
   touch /tmp/test-file-status
   ;;
 *)
   echo "Usage: /etc/init.d/test {start|stop}"
   exit 1
   ;;
esac

exit 0

#

我使/etc/init.d/test-script文件可執行並向/etc/rc2.d/目錄添加了符號連結:

lrwxrwxrwx 1 root root 21 Nov  2 13:19 /etc/rc2.d/S04test-script -> ../init.d/test-script

..因為我的預設執行級別是 2 並重新載入了機器,但腳本沒有啟動。作為最後一步,我還添加test/etc/init.d/.depend.start文件,但/etc/init.d/test-script在啟動期間仍未執行。

insserv安裝初始化腳本需要哪些額外步驟?

除了指向/etc/rc<runlevel>.d/目錄的符號連結之外,還向文件insserv添加了<script_name>:一行/etc/init.d/.depend.start。我的錯誤是我在文件中添加了<boot_facility>:行。/etc/init.d/.depend.start如果我們以/etc/init.d/test-script具有以下 LSB 標頭的範例為例:

### BEGIN INIT INFO
# Provides:          test
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: test script
# Description:       test script
### END INIT INFO

..然後需要添加test-script:行而/etc/init.d/.depend.start不是test:行。

引用自:https://unix.stackexchange.com/questions/240278