这是一个有点令人困惑的情况 - 据我所知,这并不是一场危机,因为相关服务似乎仍然有效。
背景是,我想升级到最新的 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
,它只会显示一次,但它过去与通配符相同。这是为什么?
答案1
如果当前工作目录中有任何与您的模式匹配的文件,则您的 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)