4

How can I find the uptime of Apache2. There are numerous suggestions out there to use

httpd fullstatus

But this fails

-bash: httpd: command not found

There is no httpd command running in top either, just an apache2 process.

I also tried (without any luck)

httpd status
apache2 status
apache2 fullstatus
/usr/sbin/apache2 fullstatus
/usr/sbin/apache2 status

What command can I use to find apache2's uptime reliably given the differences in how Apache is installed/configured on various platforms?

voretaq7
  • 80,749
Jake N
  • 243

3 Answers3

18

You can use ps -eo comm,etime for example:

$ ps -eo comm,etime | grep httpd
httpd            5-01:40:22

This shows the elapsed time since the process was started. Mine is showing 5 days, 1 hr, 40 mins, 22 secs.

And after a restart:

$ ps -eo comm,etime | grep httpd
httpd                 00:07

In a graceful restart, if an apache process is still serving a connection it won't be killed until it finishes, so if it's a large download to a slow host, it may linger for a while until it completes.

I did snip most of the output as it shows each forked process, but you will have a general overview of how long it has been running.

Regan
  • 1,011
7

I suspect there are lots of apache-version-specific ways to do this, but one generally-valid (and slightly brute-force) way is as follows.

Find the PID of the process that has the port open; it will have been the first one started:

[root@lory ~]# netstat -apn|grep -w 80|grep LISTEN
tcp        0      0 :::80                       :::*                        LISTEN      2903/httpd          

The netstat command requires privilege, so run as root or under sudo. In this case the PID is 2903. Then find how long that process has been running:

[root@lory ~]# ps auxww|grep 2903|grep -v grep
apache    2903  0.0  1.0 413316 39972 ?        S    Oct23   0:42 /usr/sbin/httpd

In this case, the start time is Oct 23, so I've been running a couple of days. You might get a field like 11:15, in which case it's a time of day, today, so you know the restart's worked.

MadHatter
  • 81,580
6

If you have mod_status installed you should be able to determine the uptime with:

apachectl status

Which will show the current time as well as the last restart time. It might be version/dstro specific, but my debian servers show "Server uptime" in the output as well