systemctl statusに同じサービスが2回リストされていますか?

systemctl statusに同じサービスが2回リストされていますか?

少し混乱した状況です。私が知っている限り、問題のサービスがまだ機能しているように見えるので、危機ではありません。

背景は、私のDebianバージョンでは利用できなかった最新のapache2にアップグレードしたいので、ソースからビルドしてインストールし、/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

何らかの理由でこれがうまくいかず、まだそれを見つけなければならなかったので、私は以前の方法に戻って変更しました。これでサービスが2回表示されます。

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

現在の作業ディレクトリにパターンと一致するファイルがある場合、シェルはそのファイルを拡張します(「パス名拡張」、別名globbing)。

たとえば、パターンに一致する 2 つのファイルを作成します。コマンドを実行すると、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)

おすすめ記事