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!
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:
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.