You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Tom Browder <to...@gmail.com> on 2017/02/21 13:53:35 UTC

[users@httpd] apache run status: how to tell as non-root user (on *nix)?

I need to programatically determine whether httpd is running or not,
whether I'm root or not. The only reliable way I have found is to use the
system command 'ps -C httpd' and grep the results.

Is there a better way?

Thanks.

Best regards,

-Tom

Re: [users@httpd] apache run status: how to tell as non-root user (on *nix)?

Posted by Tom Browder <to...@gmail.com>.
On Tue, Feb 21, 2017 at 8:15 AM, Yehuda Katz <ye...@ymkatz.net> wrote:
> That grep would not work on Debian-style packages because they show apache2
> as the executable but it might be the best way on other systems.

Good point, Yehuda.  I guess I should find out

But I just looked at my ps output and it shows the complete star line
so grepp ing apache should work for me, too:

$ ps -C httpd -o cmd=
/usr/local/apache2/bin/httpd -k start

Thanks!

-Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] apache run status: how to tell as non-root user (on *nix)?

Posted by Yehuda Katz <ye...@ymkatz.net>.
That grep would not work on Debian-style packages because they show apache2
as the executable but it might be the best way on other systems.

- Y

Sent from a device with a very small keyboard and hyperactive autocorrect.

On Feb 21, 2017 8:54 AM, "Tom Browder" <to...@gmail.com> wrote:

> I need to programatically determine whether httpd is running or not,
> whether I'm root or not. The only reliable way I have found is to use the
> system command 'ps -C httpd' and grep the results.
>
> Is there a better way?
>
> Thanks.
>
> Best regards,
>
> -Tom
>

Re: [users@httpd] apache run status: how to tell as non-root user (on *nix)?

Posted by Rainer Canavan <ra...@sevenval.com>.
On Tue, Feb 21, 2017 at 3:53 PM, Yann Ylavic <yl...@gmail.com> wrote:
> On Tue, Feb 21, 2017 at 3:19 PM, Rainer Canavan
> <ra...@sevenval.com> wrote:
[...]
>> If you know where the .pid file is, you can read that and check if the
>> process is
>> running, e.g. via ps --pid `cat /var/run/apache2.pid`
>
> Or:
>     kill -0 `cat /var/run/apache2.pid`
>
> which is likely "lighter".

That's probably the preferred way if the user has the proper
permissions, but fails if a non-privileged user attempts to check if a
process running as root is actually running.  I also haven't checked
if ps --pid is POSIX or a GNU extension, but it should at least work
on debian.


rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] apache run status: how to tell as non-root user (on *nix)?

Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Feb 21, 2017 at 3:19 PM, Rainer Canavan
<ra...@sevenval.com> wrote:
> On Tue, Feb 21, 2017 at 2:53 PM, Tom Browder <to...@gmail.com> wrote:
>> I need to programatically determine whether httpd is running or not, whether
>> I'm root or not. The only reliable way I have found is to use the system
>> command 'ps -C httpd' and grep the results.
>>
>> Is there a better way?
>
>
> If you know where the .pid file is, you can read that and check if the
> process is
> running, e.g. via ps --pid `cat /var/run/apache2.pid`

Or:
    kill -0 `cat /var/run/apache2.pid`

which is likely "lighter".


Regards,
Yann.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] apache run status: how to tell as non-root user (on *nix)?

Posted by Rob De Langhe <ro...@twistfare.be>.
  the existence of the PID file only gives a hint; its contents (the PID of
the process) should then be checked to see if that particular process is
indeed (still) running.

Citeren Rainer Canavan <ra...@sevenval.com>:

> On Tue, Feb 21, 2017 at 2:53 PM, Tom Browder <to...@gmail.com>
> wrote:
>> I need to programatically determine whether httpd is running or not,
>> whether
>> I'm root or not. The only reliable way I have found is to use the system
>> command 'ps -C httpd' and grep the results.
>>
>> Is there a better way?
>
> If you know where the .pid file is, you can read that and check if the
> process is
> running, e.g. via ps --pid `cat /var/run/apache2.pid`
>
> rainer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.orgFor additional
> commands, e-mail: users-help@httpd.apache.org

Re: [users@httpd] apache run status: how to tell as non-root user (on *nix)?

Posted by Rainer Canavan <ra...@sevenval.com>.
On Tue, Feb 21, 2017 at 2:53 PM, Tom Browder <to...@gmail.com> wrote:
> I need to programatically determine whether httpd is running or not, whether
> I'm root or not. The only reliable way I have found is to use the system
> command 'ps -C httpd' and grep the results.
>
> Is there a better way?


If you know where the .pid file is, you can read that and check if the
process is
running, e.g. via ps --pid `cat /var/run/apache2.pid`


rainer

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] apache run status: how to tell as non-root user (on *nix)?

Posted by Tom Browder <to...@gmail.com>.
On Tue, Feb 21, 2017 at 07:58 Mike Schlottman <ms...@spe.org> wrote:

> If you have httpd running as a service in Centos, you can run service
> httpd status.
>

Thanks, Mike. But I'm running Debian and, for httpd, the old init.d thing.
I would love to get a systemd working for it, but I need a real cookbook
solution, 'cause everything I've looked at seems kind of hand wavy.

But, anyway, is the 'service' command usable by a non-root user?

Best regards,

-Tom

RE: [users@httpd] apache run status: how to tell as non-root user (on *nix)?

Posted by Mike Schlottman <ms...@spe.org>.
If you have httpd running as a service in Centos, you can run service httpd status.   It will return a status code of 0 if it is running.

% service httpd status > /dev/null
Redirecting to /bin/systemctl status  httpd.service

% echo $?
0

From: Tom Browder [mailto:tom.browder@gmail.com]
Sent: Tuesday, February 21, 2017 7:54 AM
To: users@httpd.apache.org
Subject: [users@httpd] apache run status: how to tell as non-root user (on *nix)?

I need to programatically determine whether httpd is running or not, whether I'm root or not. The only reliable way I have found is to use the system command 'ps -C httpd' and grep the results.

Is there a better way?

Thanks.

Best regards,

-Tom