$ 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
bad;
输出的第二行部分代表什么?我在许多服务中都看到过这个信息,例如 mysql、winbind、virtualbox,其中一些我已经完美地使用了(cassandra 是全新安装的)。
答案1
简短回答:
bad
:显示Systemd Unit files
启用状态- 您将在使用以下系统的系统中看到此类消息
systemd
您可以使用命令检查启用状态:
sudo systemctl is-enabled <unit-name>
如果该单元文件是本机 systemd 服务,那么它将给出输出
enabled
,disabled
等等。如果它不是本机 systemd 服务,那么它将报告类似的消息。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
但使用命令:
systemctl status apache2 or service apache2 status
它给出了状态
bad
。(可能是因为它无法打印完整的消息或开发人员决定打印bad
)
长答案:
什么是系统单元文件?
单元是 systemd 知道如何管理的对象。这些基本上是系统资源的标准化表示,可以由守护进程套件管理,并由提供的实用程序操作。它可用于抽象服务、网络资源、设备、文件系统挂载和隔离资源池。您可以详细阅读有关 systemd 单元的信息这里和这里
例子:
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
,而对于非原生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
。您可以等待下一个版本,package
它将本机支持systemd
。或者您可以使用给定的参考为您的服务或任何其他资源编写单元文件。
您可以使用以下参考资料详细了解 systemd、systemctl 和单位: