I have a rake task that deletes some files. It is possible for these files to be in active use by the application. Due to what I suspect are some peculiarities of the file system I’m running on (AFS), I can’t delete the files while the app (and the server) are running.
I’d like to abort early if the server is running. Is there any way to check whether the server started by script/generate is running while inside of a rake task?
You can check for the existence of
tmp/pids/server.pid, whichrails swill create when it starts, and should remove when it exits. Note that if the server didn’t exit cleanly, the file could still be around, so you should read the PID from the file and check if it is in fact running: