我一直在尝试设置一个脚本,在Debian 7.1系统上启动运行一段时间,但没有运气.我已经尝试过使用insserv和update-rc.d,但我的问题似乎与任何一个工具相同.这是我的脚本的LSB部分:
#!/bin/bash
### BEGIN INIT INFO
# Provides: start_guest
# Required-Start: $bootlogs $sudo $virtualbox-guest-utils $syslog
# Required-Stop: $bootlogs $sudo $virtualbox-guest-utils $syslog
# Should-Start:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start_guest
### END INIT INFO
Run Code Online (Sandbox Code Playgroud)
使用update-rc.d,以下是我尝试的各种命令,所有命令都具有相同的结果:
sudo update-rc.d start_guest defaults
sudo update-rc.d start_guest defaults 22
sudo update-rc.d start_guest start 22 2 3 4 5 . stop 78 2 3 4 5 .
Run Code Online (Sandbox Code Playgroud)
无论我跑哪一个,我都被告知(显示运行级别2只有2,3,4,5是相同的,0,1,6都是K01):
insserv: remove service /etc/init.d/../rc2.d/S21rc.local
insserv: enable service ../init.d/rc.local -> /etc/init.d/../rc2.d/S20rc.local
insserv: remove service /etc/init.d/../rc2.d/S21rmnologin
insserv: enable service ../init.d/rmnologin -> /etc/init.d/../rc2.d/S20rmnologin
insserv: enable service ../init.d/start_guest -> /etc/init.d/../rc2.d/S17start_guest
Run Code Online (Sandbox Code Playgroud)
无论我得到什么样的依赖信息,我都无法从S17以外的其他地方开始.不幸的是,../rc2.d/S19bootlogs将在我的脚本之后启动,这将阻止我获取有时关键的日志记录信息.
当我尝试使用insserv做同样的事情时,我被告知已经指示正常服务启动我的新服务,但它似乎仍然没有遵循依赖性排序.在start_guest开始运行之前我还需要运行几个服务(比如sudo,virtualbox-guest-utils等)
me@bronze:/etc/init.d# sudo insserv start_guest
insserv: Service remote_fs has to be enabled to start service start_guest
insserv: Service syslog has to be enabled to start service start_guest
insserv: exiting now!
Run Code Online (Sandbox Code Playgroud)
大卫Krmpotic对这个问题的回答几乎可以回答我的问题,但看起来似乎并不是"必需 - 开始"依赖关系.
如何让我的脚本在启动时运行并遵循给定的依赖项?谢谢!
事实证明,有三种不同的方法可以将依赖项添加到LSB标头中,并且很少有文档来解释这些差异.我的目的正确的LSB标题实际上是这样的:
# Required-Start: bootlogs sudo virtualbox-guest-utils $syslog
# Required-Stop: bootlogs sudo virtualbox-guest-utils $syslog
Run Code Online (Sandbox Code Playgroud)
(在这两行中,我可以删除sudo和virtualbox-guest-utils,因为它是bootlogs,强制我的start_guest脚本启动最新的.)
一旦我的LSB标头遵循这种语法,我就能够运行update-rc.d start_guest defaults
并且它完全符合我的要求.
列出需要在新的init脚本之前或之后启动或停止的服务时,有几种方法可以列出它们.
$name
指一个机构的服务或虚拟服务name
指一个现有的<服务-我所需要的所有沿+name
指一个服务,这是可选其中一些在文档中提到,但在各个部分甚至各种文档之间并不清楚和分解.我遇到的每个例子都只使用设施服务,不包括任何正常或可选的服务,这导致了很大的语法混乱.
从insserv的手册页:
insserv scans for System Facilities in the configuration file /etc/insserv.conf
and each file in the directory /etc/insserv.conf.d/. Each line which begins with
$ and a following name defines a system facility accordingly to the Linux Standard
Base Specification (LSB)
Run Code Online (Sandbox Code Playgroud)
和:
Names starting with a `+' sign are marked as optional. If the service with the
name after the plus sign is available it will be used, if not available it
is ignored silently.
Run Code Online (Sandbox Code Playgroud)
我不打算问,然后回答我自己的问题.我一直在困惑这个问题超过一个月,虽然我得到了提示,没有什么能给我一个足够的答案,我可以看到它做我需要它做的事情.几周之后重新审视事情会给我提供更好的洞察力,即使仍然存在令人费解的问题.
归档时间: |
|
查看次数: |
10945 次 |
最近记录: |