sudo 服务状态包括坏;

mat*_*ter 38 services systemd

$ 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
Run Code Online (Sandbox Code Playgroud)

bad;输出第二行的部分代表什么?我为许多服务获得了这个,例如 mysql、winbind、virtualbox,其中一些我已经完美地使用了(cassandra 是全新安装的)。

pl_*_*ock 47

简短的回答:

  • bad: 它显示Systemd Unit files启用状态
  • 您将在使用的系统上看到此类消息 systemd
  • 您可以使用以下命令检查启用状态:

    sudo systemctl is-enabled <unit-name>
    
    Run Code Online (Sandbox Code Playgroud)

    如果该单元文件是本机 systemd 服务,那么它会给出输出enableddisabled等等。如果它不是本机 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
    
    Run Code Online (Sandbox Code Playgroud)

    但使用命令:

    systemctl status apache2
    or
    service apache2 status
    
    Run Code Online (Sandbox Code Playgroud)

    它给出了状态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)
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

注意:您可以在以下位置找到生成器,/lib/systemd/system-generators/systemd-sysv-generator您可以阅读更多相关信息

man systemd-sysv-generator
Run Code Online (Sandbox Code Playgroud)

要点

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.                |           |
       +------------------+-------------------------+-----------+
Run Code Online (Sandbox Code Playgroud)

如果我们运行命令:

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
Run Code Online (Sandbox Code Playgroud)

您可以查看单元是否是 systemd 之类的sshdocker,在上面的输出中,它只会显示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.                |           |
       +------------------+-------------------------+-----------+
Run Code Online (Sandbox Code Playgroud)

解决方案:

statusbad不会产生问题(我不确定这取决于)但它不会提供systemctl. 您可以等待下一个package本机支持的版本systemd。或者您可以使用给定的引用为您的服务或任何其他资源编写单元文件。

您可以使用以下参考资料详细了解 systemd 、 systemctl 和单位:

  1. 系统控制

  2. 系统单位这里

  3. 系统化

  • 这个答案似乎很完整,但有点令人困惑……您似乎提供了很多信息,但实际上并未说明可以(也许)从这些信息中得出的简洁结论。例如,我从您的简短回答中(通过一些工作)推断出的直接、简洁的结论是,当服务(systemd 单元)不是本机时,systemctl 无法在不重定向到 systemd-sysv-install 的情况下获得其启用状态。systemctl status 命令出于某种原因不会这样做,而是报告“坏”,而 systemctl is-enabled 将执行重定向以提供状态。 (2认同)