Score:2

What config file applies to edit this line: Main PID: 675992 (/usr/sbin/ seen when invoking systemctl status apache2)?

ng flag

Headless server 22.04.2 I have what appears to be a typo when I invoke systemctl status apache2 I get this:

_________________________________________________________________
 systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2023-03-04 08:56:03 EST; 8h ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 675992 (/usr/sbin/apach)
      Tasks: 56 (limit: 2283)
     Memory: 26.1M
        CPU: 8.882s
     CGroup: /system.slice/apache2.service
             ├─675992 /usr/sbin/apache2 -k start
             ├─675993 /usr/sbin/apache2 -k start
             ├─675994 /usr/sbin/apache2 -k start
             └─675995 /usr/sbin/apache2 -k start
____________________________________________________

where Main PID: 675992 (/usr/sbin/apach) appears wrong to me. Shouldn't apach be apache or apache2? I may of made a typo when it setting up. If so - how do I edit it?

hr flag
Hello and welcome. Can you also show us the output of `cat /proc/675992/comm` please? Replace 675992 with the current Main PID, if you have restarted the server in the meantime. Is this a bare-metal server, or some kind of container?
user129821 avatar
ng flag
Steeldriver - My output of cat /proc/675992/comm is: /usr/sbin/apach and PID is the same, its a bare metal server.
user129821 avatar
ng flag
Steeldriver - Based on your previous comment I found the file, but its live, any edits are immediately overwritten, your auto truncate suggestion makes sense. Maybe its not an error at all... I'm trying to get a cgi script working again after a move from a bsd server to a deb server. Paths are very different.
hr flag
So... where my question was leading is that so far as I can see, the process name in `Main PID: 675992 (/usr/sbin/apach)` is populated by reading `/proc/<Main PID>/comm`, and that's why it's truncated (to 15 characters + newline) - see the section `/proc/[pid]/comm` in `man proc`. **However** everything I've read says that in general `/proc/<PID>/comm` contains the process basename, and indeed that's what I see for `apache2` on my 22.04 VM. So the more interesting question is why your system writes the full path to the comm file.
hr flag
... either way, it's unlikely to be any kind of mis-configuration of the apache2 server on your part
hr flag
... actually think I may have found the culprit - have you installed `mod_perl` (libapache2-mod-perl2)?
user129821 avatar
ng flag
Not as far as I can tell - I find only this: perl 5.34.0-3ubuntu1.1 amd64 perl-base 5.34.0-3ubuntu1.1 amd64 perl-modules-5.34 5.34.0-3ubuntu1.1
hr flag
so nothing from `a2query -m perl` ?
user129821 avatar
ng flag
This: perl (enabled by maintainer script) Sorry I'm having confusion about how to interact jere! Newbie. Is mod-perl the same as perl?
Score:2
hr flag

tl;dr

No, you didn't make a typo when setting up the apache2 server. The process name is not read from a configuration file, it is read from the /proc/[pid]/comm kernel interface, and the truncation occurs there.

It appears to be a particular apache2 module, mod_perl, that is responsible for replacing the basename apache2 with the (truncated) path /usr/sbin/apach.

Details

The systemctl status command reads the process name from the kernel's process information pseudo-filesystem at /proc/[pid]/comm where the process ID [pid] is the apache2 Main PID. You can verify this by running systemctl status apache2 under strace, for example:

$ systemctl show -P MainPID apache2.service
6525
$ strace -P /proc/6525/comm -e trace=%file,read,write systemctl --no-pager status apache2 >/dev/null
openat(AT_FDCWD, "/proc/6525/comm", O_RDONLY|O_CLOEXEC) = 4
newfstatat(4, "", {st_mode=S_IFREG|0644, st_size=0, ...}, AT_EMPTY_PATH) = 0
read(4, "/usr/sbin/apach\n", 1024)      = 16
read(4, "", 1024)                       = 0
+++ exited with 0 +++

You can see that it's reading the string /usr/sbin/apach\n, a total of 16 characters including the terminating newline \n. That length limit is imposed by the kernel TASK_COMM_LEN parameter, as noted in man proc:

/proc/[pid]/comm (since Linux 2.6.33)
      This  file exposes the process's comm value—that is, the command
      name associated with the process.  Different threads in the same
      process   may   have   different  comm  values,  accessible  via
      /proc/[pid]/task/[tid]/comm.   A  thread  may  modify  its  comm
      value,  or  that of any of other thread in the same thread group
      (see the discussion of CLONE_THREAD in clone(2)), by writing  to
      the   file   /proc/self/task/[tid]/comm.   Strings  longer  than
      TASK_COMM_LEN (16) characters (including  the  terminating  null
      byte) are silently truncated.
      This  file  provides  a superset of the prctl(2) PR_SET_NAME and
      PR_GET_NAME operations, and is employed by pthread_setname_np(3)
      when used to rename threads other than the caller.  The value in
      this file  is  used  for  the  %e  specifier  in  /proc/sys/ker‐
      nel/core_pattern; see core(5).

If you look at almost any other process, you will see that its /proc/[pid]/comm file contains just the program's basename. The 16-character TASK_COMM_LEN value suggests it is not intended to contain path components - and indeed if you install a basic apache2 server, that's exactly what you see. So what is changing it to /usr/sbin/apach?

Summoning up some google-fu, it turns out the answer is mod_perl. Specifically, in this comment on Red Hat Bugzilla – Bug 782369

A process can call prctl(PR_SET_NAME) to set it's task name (task->comm) in the kernel, as long as the name is under 16 characters. If you have mod_perl included in httpd, it calls prctl and sets the name to '/usr/sbin/httpd'.

Why it does this, I have absolutely no clue. But it does.

("httpd" is what RedHat calls apache2). If you're running apache2 in a testing environment, you can verify that's the culprit by temporarily disabling the mod_perl module:

sudo a2dismod perl
sudo systemctl restart apache2

and you should see the process name in the systemctl status output revert back to (apache2). You can re-enable the mod afterwards with

sudo a2enmod perl

and restarting the service again.

Raffa avatar
jp flag
Probably this https://src.fedoraproject.org/rpms/mod_perl/blob/f31/f/mod_perl-short-name.patch should explain the why ... If I am not mistaken.
user129821 avatar
ng flag
Steeldriver- Wow! That's deep! Apache is voo doo... Is this something I need to "fix" to get my perl cgiScript.pl to work? Thanks for all your time.
hr flag
@Raffa good find yes that looks like it might be it
user129821 avatar
ng flag
Thank you Steeldriver and Raffa - My horizon has been expanded...
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.