AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 606520
Accepted
Andy Shinn
Andy Shinn
Asked: 2014-06-20 10:00:29 +0800 CST2014-06-20 10:00:29 +0800 CST 2014-06-20 10:00:29 +0800 CST

如何删除丢失的 systemd 单元?

  • 772

我无法弄清楚如何删除不再有文件的 systemd 单元。他们似乎仍然以某种方式徘徊在系统中。

我要删除的旧损坏单元:

core@ip-172-16-32-83 ~ $ systemctl list-units --all firehose-router*
  UNIT                       LOAD      ACTIVE SUB    DESCRIPTION
<E2><97><8F> [email protected] not-found failed failed [email protected]
<E2><97><8F> [email protected] not-found failed failed [email protected]

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

2 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.

这些文件不存在,但重新加载仍然有这些单位挥之不去:

core@ip-172-16-32-83 ~ $ systemctl list-unit-files [email protected]
core@ip-172-16-32-83 ~ $ sudo systemctl daemon-reload
core@ip-172-16-32-83 ~ $ systemctl list-units --all firehose-router*
  UNIT                       LOAD      ACTIVE SUB    DESCRIPTION
<E2><97><8F> [email protected] not-found failed failed [email protected]
<E2><97><8F> [email protected] not-found failed failed [email protected]

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.

2 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.

我找不到与它们相关的文件:

core@ip-172-16-32-83 ~ $ sudo find /var/run/systemd -name "*firehose-router*"
core@ip-172-16-32-83 ~ $ find /etc/systemd/ -name "*firehose-router*"
core@ip-172-16-32-83 ~ $ find /usr/lib/systemd/ -name "*firehose-router*"
core@ip-172-16-32-83 ~ $

那么我该如何摆脱这些呢?

systemd
  • 4 4 个回答
  • 48947 Views

4 个回答

  • Voted
  1. Best Answer
    user227117
    2014-06-20T10:32:34+08:002014-06-20T10:32:34+08:00

    您要执行的命令是systemctl reset-failed

    • 109
  2. AaronDanielson
    2018-11-15T09:07:57+08:002018-11-15T09:07:57+08:00

    当 systemd 分析单元定义文件时,它会记录文件中调用的任何其他相关单元——无论这些其他单元是否存在。

    $ systemctl --state=not-found --all
    > ( ...prints list of 'not-found' units )
    
    $ grep -r "<missing-unit>" /usr/lib/systemd/system
    > ( returns files with references to <missing-unit> )
    

    当一个单元显示为“未找到”时,它不一定是错误 - 我们所知道的是,本地单元定义声称与它有某种关系。这种关系可能不是我们关心的。例如,它可能是"Before:"某个其他单位,但我们不使用该其他单位。

    • 4
  3. mbigras
    2020-01-11T23:20:38+08:002020-01-11T23:20:38+08:00
    • failed- 当一个单元进入故障状态并且可以使用systemctl reset-failed命令重置时发生
    • not-found- 当您删除了一个单元但 systemd 仍然有对它的引用时发生,例如当一个单元被启用并且一个符号链接被放置时/etc/systemd/system,这可以通过删除对单元的引用/etc/system/systemd/*.wants/然后运行来修复systemctl daemon-reload

    例如,假设以下 bash 脚本:

    #!/bin/bash
    # script.sh
    while true
    do
        sleep 1
    done
    

    和 3 个系统单元:example-foo.service、、example-bar.service和example-baz.service

    $ sudo systemctl cat example-{foo,bar,baz}.service
    # /etc/systemd/system/example-foo.service
    [Service]
    ExecStart=/home/vagrant/script.sh
    [Install]
    WantedBy=multi-user.target
    
    # /etc/systemd/system/example-bar.service
    [Service]
    ExecStart=/home/vagrant/script.sh
    [Install]
    WantedBy=multi-user.target
    
    # /etc/systemd/system/example-baz.service
    [Service]
    ExecStart=/home/vagrant/script.sh
    [Install]
    WantedBy=multi-user.target
    

    现在,让我们开始并启用这些单元。观察符号链接是如何创建的。

    $ sudo systemctl start example-{foo,bar,baz}.service
    $ sudo systemctl enable example-{foo,bar,baz}.service
    Created symlink from /etc/systemd/system/multi-user.target.wants/example-foo.service to /etc/systemd/system/example-foo.service.
    Created symlink from /etc/systemd/system/multi-user.target.wants/example-bar.service to /etc/systemd/system/example-bar.service.
    Created symlink from /etc/systemd/system/multi-user.target.wants/example-baz.service to /etc/systemd/system/example-baz.service.
    

    确认我们的 3 个单元实际上有 6 个文件。

    $ find /etc/systemd/system -name 'example*.service'
    /etc/systemd/system/multi-user.target.wants/example-bar.service
    /etc/systemd/system/multi-user.target.wants/example-foo.service
    /etc/systemd/system/multi-user.target.wants/example-baz.service
    /etc/systemd/system/example-bar.service
    /etc/systemd/system/example-foo.service
    /etc/systemd/system/example-baz.service
    

    现在,检查所有 3 个单元的状态,它们正在运行。

    $ systemctl list-units example*
    UNIT                LOAD   ACTIVE SUB     DESCRIPTION
    example-bar.service loaded active running example-bar.service
    example-baz.service loaded active running example-baz.service
    example-foo.service loaded active running example-foo.service
    

    现在,通过向example-foo.service. 观察设备如何处于故障状态。

    $ sudo systemctl kill -s KILL example-foo.service
    $ systemctl list-units example*
      UNIT                LOAD   ACTIVE SUB     DESCRIPTION
      example-bar.service loaded active running example-bar.service
      example-baz.service loaded active running example-baz.service
    ● example-foo.service loaded failed failed  example-foo.service
    

    要重置处于故障状态的单元,请使用该systemctl rese-failed命令。观察设备现在如何处于非活动状态。

    $ sudo systemctl reset-failed
    $ systemctl list-units example*
    UNIT                LOAD   ACTIVE SUB     DESCRIPTION
    example-bar.service loaded active running example-bar.service
    example-baz.service loaded active running example-baz.service
    
    ...
    $ systemctl list-units --all example*
    UNIT                LOAD   ACTIVE   SUB     DESCRIPTION
    example-bar.service loaded active   running example-bar.service
    example-baz.service loaded active   running example-baz.service
    example-foo.service loaded inactive dead    example-foo.service
    

    好的,现在让我们删除 example-bar.service 单元。观察单位如何处于未找到状态;但是,example-bar.service 损坏的符号链接仍在 /etc/system/system/multi-user.target.wants

    $ sudo rm /etc/systemd/system/example-bar.service
    $ sudo systemctl daemon-reload
    $ sudo systemctl stop example-bar.service
    Failed to stop example-bar.service: Unit example-bar.service not loaded.
    $ systemctl list-units --all example*
      UNIT                LOAD      ACTIVE   SUB     DESCRIPTION
    ● example-bar.service not-found inactive dead    example-bar.service
      example-baz.service loaded    active   running example-baz.service
      example-foo.service loaded    inactive dead    example-foo.service
    $ find /etc/systemd/system -name 'example*.service'
    /etc/systemd/system/multi-user.target.wants/example-bar.service
    /etc/systemd/system/multi-user.target.wants/example-foo.service
    /etc/systemd/system/multi-user.target.wants/example-baz.service
    /etc/systemd/system/example-foo.service
    /etc/systemd/system/example-baz.service
    

    删除损坏的符号链接并确认 example-bar.service 单元已消失。

    $ sudo rm /etc/systemd/system/multi-user.target.wants/example-bar.service
    $ sudo systemctl daemon-reload
    $ systemctl list-units --all example*
    UNIT                LOAD   ACTIVE   SUB     DESCRIPTION
    example-baz.service loaded active   running example-baz.service
    example-foo.service loaded inactive dead    example-foo.service
    
    • 2
  4. Rolf
    2018-03-30T04:39:34+08:002018-03-30T04:39:34+08:00

    似乎 systemd 维护链接,但在您删除单元文件时不知道如何处理它们。

    您可以尝试手动删除它们/etc/systemd/system/suspend.target.wants/,但当然systemctl reset-failed从以前的答案听起来是一个更好的选择。

    $ cd /etc/systemd/system
    $ sudo mv lock.service /tmp 
    $ sudo systemctl disable lock.service
    Failed to disable unit: No such file or directory
    $ sudo mv /tmp/lock.service .
    $ sudo systemctl disable lock.service
    Removed /etc/systemd/system/suspend.target.wants/lock.service.
    
    • 0

相关问题

  • 如何在systemd服务中设置环境变量?

  • 将 shell 脚本置于 systemd 控制之下

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve