sudo服务状态包括不良;


32
$ 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是全新安装)。

Answers:


42

简短答案:

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

    sudo systemctl is-enabled <unit-name>
    

    如果该单元文件是本机systemd服务,则它将提供output 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
    

    但是用命令:

    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

您可以看到单位是否像ssh和一样是systemd的本机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和units:

  1. 系统控制

  2. 系统单位此处

  3. 系统化


非常感谢您对本主题进行了全面而周到的讨论!
马特

2
这个答案似乎真的很完整,但是有点令人困惑……您似乎提供了很多信息,而没有实际陈述一个可以(也许)从信息中得出的简洁结论。例如,我从简短的回答中得出的直接简洁的结论(包括一些工作)是,当服务(系统单元)不是本机时,systemctl无法在不重定向到systemd-sysv-install的情况下获得其启用状态。由于某些原因,systemctl status命令不会执行此操作,而是报告“坏”,而启用了systemctl的将执行重定向以为您提供状态。
EricS

1
我认为让我感到困惑的是一些措辞,尤其是在开头的要点。我提交了一些修改以尝试改进。
EricS
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.