问题描述
$ sudo service cassandra status
● cassandra.service - LSB: distributed storage system for structured data
Loaded: loaded (/etc/init.d/cassandra; bad; vendor preset: enabled)
Active: active (running) since Wed 2016-10-12 15:54:40 IDT; 4min 4s ago
输出第 2 行的 bad;
部分代表什么?\n我在很多服务中都得到了这个,例如mysql、winbind、virtualbox,其中一些我已经完美地使用过(cassandra 是全新安装的)。
最佳答案
简短的回答:
-
bad
:显示Systemd Unit files
启用状态 -
您将在使用
systemd
的系统上看到此类消息 -
您可以使用命令检查启用状态:
\n
sudo systemctl is-enabled <unit-name>\n
\n
如果该单元文件是本机 systemd 服务,那么它将给出输出
enabled
、disabled
等。如果它不是本机 systemd 服务,那么它将给出类似消息的报告。\n
sudo systemctl is-enabled apache2\napache2.service is not a native service, redirecting to systemd-sysv-install\nExecuting /lib/systemd/systemd-sysv-install is-enabled apache2\nenabled\n
\n
但使用命令:
\n
systemctl status apache2\nor\nservice apache2 status\n
\n
它给出状态
bad
。 (可能是因为它无法打印完整的消息或开发人员决定打印bad
)
长答案:
什么是系统单元文件?
单元是 systemd 知道如何管理的对象。这些基本上是系统资源的标准化表示,可以由守护程序套件管理并由提供的实用程序操作。它可用于抽象服务、网络资源、设备、文件系统挂载和隔离资源池。\n您可以详细阅读有关 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
是否是本机单元。如果不是,则它\n将要求 systemd-sysv-generator
生成一个单位格式的文件,该文件提供类似于本机单位的支持。在上面的例子中,生成的文件保存在\n /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
,对于非原生单元(如 apache2
但仍启用),由于这种情况,它会提供消息而不是在此处打印 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
的所有功能。\n您可以等待将原生支持 systemd
的 package
的下一个版本。或者您可以使用给定的引用为您的服务或任何其他资源编写单元文件。
您可以使用以下参考资料详细了解 systemd 、 systemctl 和单位: