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
    • 最新
    • 标签
主页 / unix / 问题 / 771726
Accepted
j4nd3r53n
j4nd3r53n
Asked: 2024-03-06 18:53:23 +0800 CST2024-03-06 18:53:23 +0800 CST 2024-03-06 18:53:23 +0800 CST

systemctl status 列出同一个服务两次?

  • 772

这是一个有点令人困惑的情况 - 据我所知,这并不是一场危机,因为相关服务似乎仍然有效。

背景是,我想升级到最新的 apache2,这在我的 Debian 版本中不可用,所以我从源代码构建了它,将其安装在 中/usr/local/apache2/,更改了服务文件并执行了以下操作systemctl daemon-reload:

root@vogon:~# cat /lib/systemd/system/apache2.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=https://httpd.apache.org/docs/2.4/

[Service]
Type=forking
Environment=APACHE_STARTED_BY_SYSTEMD=true
ExecStart=/usr/local/apache2/bin/apachectl start
ExecStop=/usr/local/apache2/bin/apachectl graceful-stop
ExecReload=/usr/local/apache2/bin/apachectl graceful
KillMode=mixed
PrivateTmp=true
Restart=on-abort

[Install]
WantedBy=multi-user.target

由于某种原因,这不起作用,我仍然需要弄清楚,所以我将其改回之前的状态 - 现在我看到该服务两次:

root@vogon:~# systemctl status *apa*
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-03-06 10:29:12 UTC; 21min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 3660993 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 3660997 (apache2)
      Tasks: 9 (limit: 35927)
     Memory: 68.8M
        CPU: 22.258s
     CGroup: /system.slice/apache2.service
             ├─3660997 /usr/sbin/apache2 -k start
             ├─3660998 /usr/sbin/apache2 -k start
             ├─3660999 /usr/sbin/apache2 -k start
             ├─3661000 /usr/sbin/apache2 -k start
             ├─3661001 /usr/sbin/apache2 -k start
             ├─3661002 /usr/sbin/apache2 -k start
             ├─3661003 /usr/sbin/apache2 -k start
             ├─3661006 /usr/sbin/apache2 -k start
             └─3661007 /usr/sbin/apache2 -k start

Mar 06 10:29:12 vogon systemd[1]: Starting The Apache HTTP Server...
Mar 06 10:29:12 vogon systemd[1]: Started The Apache HTTP Server.

● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2024-03-06 10:29:12 UTC; 21min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 3660993 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 3660997 (apache2)
      Tasks: 9 (limit: 35927)
     Memory: 68.8M
        CPU: 22.258s
     CGroup: /system.slice/apache2.service
             ├─3660997 /usr/sbin/apache2 -k start
             ├─3660998 /usr/sbin/apache2 -k start
             ├─3660999 /usr/sbin/apache2 -k start
             ├─3661000 /usr/sbin/apache2 -k start
             ├─3661001 /usr/sbin/apache2 -k start
             ├─3661002 /usr/sbin/apache2 -k start
             ├─3661003 /usr/sbin/apache2 -k start
             ├─3661006 /usr/sbin/apache2 -k start
             └─3661007 /usr/sbin/apache2 -k start

Mar 06 10:29:12 vogon systemd[1]: Starting The Apache HTTP Server...
Mar 06 10:29:12 vogon systemd[1]: Started The Apache HTTP Server.

如果我拼写出服务名称apache2,它只会显示一次,但它过去与通配符相同。这是为什么?

linux
  • 1 1 个回答
  • 41 Views

1 个回答

  • Voted
  1. Best Answer
    aviro
    2024-03-06T19:12:22+08:002024-03-06T19:12:22+08:00

    如果当前工作目录中有任何与您的模式匹配的文件,则您的 shell 会扩展这些文件(“路径名扩展”,又名 Globbing)。

    例如,我创建两个与模式匹配的文件。如果我echo要执行的命令,您将看到它将在扩展文件名上运行状态:

    $ touch apache apache2
    $ echo systemctl status *apa* 
    systemctl status apache apache2
    

    这就是为什么你会得到 2 个结果:

    $ systemctl status *apa* |grep -B1 Loaded:
    ● apache2.service - The Apache Webserver
         Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
    --
    ● apache2.service - The Apache Webserver
         Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
    

    为了避免这种情况,您需要引用模式以避免扩展。

    $ systemctl status '*apa*' |grep -B1 Loaded:
    ● apache2.service - The Apache Webserver
         Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; vendor preset: disabled)
    
    • 4

相关问题

  • 有没有办法让 ls 只显示某些目录的隐藏文件?

  • 使用键盘快捷键启动/停止 systemd 服务 [关闭]

  • 需要一些系统调用

  • astyle 不会更改源文件格式

  • 通过标签将根文件系统传递给linux内核

Sidebar

Stats

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

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

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

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve