0

This is a somewhat mystifying situation - not a crisis as far as I can tell, since the service in question still seems to work.

The background is, I wanted to upgrade to the latest apache2, which isn't available in my version of Debian, so I built it from source, installed it in /usr/local/apache2/, changed the service file and did the 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

This didn't work for some reason I still have to figure out, so I changed it back to what it was before - and now I see the service twice:

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.

If I spell out the service name apache2, it shows up just once, but it used to be the same with wildcards. Why is that?

2
  • Are you sure you don't have two files or directories on your current $PWD? One would be named apache2, the other apache2.service for example. Try again with quotes. Commented Mar 6, 2024 at 11:01
  • @A.B That's it! I made a backup copy of the service file. God, I feel stupid :-) Commented Mar 6, 2024 at 11:04

1 Answer 1

4

If you have any files that match your pattern in your current working directory, it your shell would expand those files ("Pathname Expansion", AKA Globbing).

For instance, I create two files that match the pattern. If I echo the command to be executed, you'll see it will run status on the expanded filenames:

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

That's why you get 2 results:

$ 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)

In order to avoid this, you need to quote the pattern to avoid the expansion.

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.