Commit e6d499a4 authored by rebx's avatar rebx Committed by Matt Stancliff
Browse files

Create PID file even if in foreground

Previously, Redis only wrote the pid file if
it was daemonizing, but many times it's useful to have
the pid written out even if you're in the foreground.

Some background for this is:
I usually run redis via daemontools. That entails running
redis-server on the foreground. Given that, I'd also want
redis-server to create a pidfile so other processes (e.g. nagios)
can run checks for that.

Closes #463
parent 0d22121c
...@@ -2374,7 +2374,7 @@ int prepareForShutdown(int flags) { ...@@ -2374,7 +2374,7 @@ int prepareForShutdown(int flags) {
return REDIS_ERR; return REDIS_ERR;
} }
} }
if (server.daemonize) { if (server.daemonize || server.pidfile) {
redisLog(REDIS_NOTICE,"Removing the pid file."); redisLog(REDIS_NOTICE,"Removing the pid file.");
unlink(server.pidfile); unlink(server.pidfile);
} }
...@@ -3759,9 +3759,10 @@ int main(int argc, char **argv) { ...@@ -3759,9 +3759,10 @@ int main(int argc, char **argv) {
} }
server.supervised = redisIsSupervised(); server.supervised = redisIsSupervised();
if (server.daemonize && server.supervised == 0) daemonize(); int background = server.daemonize && server.supervised == 0;
if (background) daemonize();
initServer(); initServer();
if (server.daemonize && server.supervised == 0) createPidFile(); if (background || server.pidfile) createPidFile();
redisSetProcTitle(argv[0]); redisSetProcTitle(argv[0]);
redisAsciiArt(); redisAsciiArt();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment