Location of PID file (or executable) at runtime

Hi there,

I’m looking for a way to find the fully qualified path of the “PID” file
at run time. Basically, I’ve got some code that I need to run when the
server is starting, and some different code I need to run when the
server is shutting down (daemon mode).

I use fopen(“logs/nginx.pid”, “r”) == NULL to decide if the file exists
of not.

If it doesn’t, I assume the server is starting. If it does, I assume the
server is shutting down. I am aware that this code must execute before
the pid file is created to work, which it does. This all works fine,
except the location I’m starting it from must be relative to the path I
give in fopen. Thus, I have to start it in the same folder as logs,
usually by saying sbin/nginx. I want to be able to start it from
anywhere, thus I want to use the fully qualified path of the pid file
instead of it’s relative path. I suppose even if I knew the full
executable path, I could escape it one level up and tack on
logs/nginx.pid but knowing the pid itself would likely be better.

So does nginx make the location of the pid file available at run time?
Is there a way I can extract the full location of the PID (or exe) at
run time? Thanks!

Posted at Nginx Forum:

Or…

If there is a better way to tell if the server (or a module) is starting
or stopping, I’d be interested in knowing that too! Thanks.

Posted at Nginx Forum:

You can probably look at this http://hg.dutov.org/nginx-module-events/

rr


From: “Tronman” [email protected]
Sent: Wednesday, April 07, 2010 4:33 PM
To: [email protected]
Subject: Re: Location of PID file (or executable) at runtime

Tronman ha scritto:

Hi there,

I’m looking for a way to find the fully qualified path of the “PID” file at run time.

What do you mean by “run time”?

The path to the PID file is well know.

You just need to check when the file is modified (as an example, using
inotify on Linux or kqueue on FreeBSD)

[…]

Regards Manlio

Manlio P. Wrote:

You just need to check when the file is modified
[email protected]
nginx Info Page

By runtime I simply mean when the server is running. I can specify the
path to the PID file in the configuration file, but if I don’t, it
usually sticks it in “logs/nginx.pid”. But that logs/nginx.pid could be
anywhere I built the server from source (it specifies a default path
when you run configure). So the file could be in
/bla/bla2/bla3/logs/nginx.pid.

What I’m trying to find is the entire path of where it sticks the PID
file when you start the server. For now, I’m specifying the full path in
the path file, and I can extract that using the configuration functions
regularly enough, but it’s a bit annoying. So I’m wondering if I can get
it’s path when it’s not specified. Just wondering if there’s a better
way. I will take a look at events module too, thanks.

Posted at Nginx Forum: