简短回答:
bad
:它显示了Systemd Unit files
的启用状态
- 在使用
systemd
的系统上,您会看到这种类型的消息
您可以使用以下命令检查启用状态:
sudo systemctl is-enabled <unit-name>
如果该单元文件是本机的systemd服务,则会输出enabled
、disabled
等。如果不是本机的systemd服务,则会报告如下消息。
sudo systemctl is-enabled apache2
apache2.service不是本机服务,正在重定向到systemd-sysv-install
执行/lib/systemd/systemd-sysv-install is-enabled apache2
enabled
但是使用以下命令:
systemctl status apache2
或者
service apache2 status
它会给出bad
的状态。(可能是因为无法打印完整的消息或开发人员决定打印bad
)
长答案:
系统单元文件是什么?
单元是systemd知道如何管理的对象。它们基本上是一种标准化的系统资源表示,可以由套件中的守护进程进行管理并通过提供的实用工具进行操作。它可以用于抽象服务、网络资源、设备、文件系统挂载和隔离的资源池。
您可以在这里详细了解systemd单元here和here
示例:
systemctl status apache2
* apache2.service - LSB: Apache2 web server
Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
`-apache2-systemd.conf
Active: active (running) since Wed 2016-10-12 14:29:42 UTC; 17s ago
Docs: man:systemd-sysv-generator(8)
Process: 1027 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCESS)
systemctl会检查
apache2
是否是本地单元。如果不是,它将要求
systemd-sysv-generator
生成一个以单元格式提供类似本地单元支持的文件。在上面的示例中,生成的文件保存在
/lib/systemd/system/apache2.service.d/apache2-systemd.conf
中。
Drop-In: /lib/systemd/system/apache2.service.d
`-apache2-systemd.conf
注意:您可以在“/lib/systemd/system-generators/systemd-sysv-generator”找到该生成器,并且您可以阅读更多相关内容。
man systemd-sysv-generator
主要观点:
is-enabled NAME...
Checks whether any of the specified unit files are enabled (as with
enable). Returns an exit code of 0 if at least one is enabled,
non-zero otherwise. Prints the current enable status (see table).
To suppress this output, use --quiet.
Table 1. is-enabled output
+------------------+-------------------------+-----------+
|Name | Description | Exit Code |
+------------------+-------------------------+-----------+
|"enabled" | Enabled via | |
+------------------+ .wants/, .requires/ | |
|"enabled-runtime" | or alias symlinks | |
| | (permanently in | 0 |
| | /etc/systemd/system/, | |
| | or transiently in | |
| | /run/systemd/system/). | |
+------------------+-------------------------+-----------+
|"linked" | Made available through | |
+------------------+ one or more symlinks | |
|"linked-runtime" | to the unit file | |
| | (permanently in | |
| | /etc/systemd/system/ | |
| | or transiently in | > 0 |
| | /run/systemd/system/), | |
| | even though the unit | |
| | file might reside | |
| | outside of the unit | |
| | file search path. | |
+------------------+-------------------------+-----------+
|"masked" | Completely disabled, | |
+------------------+ so that any start | |
|"masked-runtime" | operation on it fails | |
| | (permanently in | > 0 |
| | /etc/systemd/system/ | |
| | or transiently in | |
| | /run/systemd/systemd/). | |
+------------------+-------------------------+-----------+
|"static" | The unit file is not | 0 |
| | enabled, and has no | |
| | provisions for enabling | |
| | in the "[Install]" | |
| | section. | |
+------------------+-------------------------+-----------+
|"indirect" | The unit file itself is | 0 |
| | not enabled, but it has | |
| | a non-empty Also= | |
| | setting in the | |
| | "[Install]" section, | |
| | listing other unit | |
| | files that might be | |
| | enabled. | |
+------------------+-------------------------+-----------+
|"disabled" | Unit file is not | > 0 |
| | enabled, but contains | |
| | an "[Install]" section | |
| | with installation | |
| | instructions. | |
+------------------+-------------------------+-----------+
|"bad" | Unit file is invalid or | > 0 |
| | another error occurred. | |
| | Note that is-enabled | |
| | will not actually | |
| | return this state, but | |
| | print an error message | |
| | instead. However the | |
| | unit file listing | |
| | printed by | |
| | list-unit-files might | |
| | show it. | |
+------------------+-------------------------+-----------+
如果我们运行以下命令:
sudo systemctl is-enabled ssh
enabled
sudo systemctl is-enabled docker
enabled
sudo systemctl is-enabled apache2
apache2.service is not a native service, redirecting to systemd-sysv-install
Executing /lib/systemd/systemd-sysv-install is-enabled apache2
enabled
你可以看到如果单位是systemd的本地单位,比如
ssh
和
docker
,在上面的输出中只会显示
enabled
。对于那些不是本地单位但仍然启用的单位,它会给出相应的消息,而不是打印
bad
,因为有这个条件:
+------------------+-------------------------+-----------+
|"bad" | Unit file is invalid or | > 0 |
| | another error occurred. | |
| | Note that is-enabled | |
| | will not actually | |
| | return this state, but | |
| | print an error message | |
| | instead. However the | |
| | unit file listing | |
| | printed by | |
| | list-unit-files might | |
| | show it. | |
+------------------+-------------------------+-----------+
解决方案:
状态bad
不会造成问题(我不确定是否有关系),但它无法提供systemctl
的所有功能。
您可以等待下一个版本的package
,该版本将原生支持systemd
。或者,您可以使用给定的参考文献编写服务或任何其他资源的单元文件。
您可以通过以下参考文献详细了解systemd、systemctl和units:
Systemctl
Systemd units和Here
Systemd