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
This commit is contained in:
rebx 2012-04-18 11:04:37 +12:00 committed by Matt Stancliff
parent 0d22121c27
commit e6d499a446

View File

@ -2374,7 +2374,7 @@ int prepareForShutdown(int flags) {
return REDIS_ERR;
}
}
if (server.daemonize) {
if (server.daemonize || server.pidfile) {
redisLog(REDIS_NOTICE,"Removing the pid file.");
unlink(server.pidfile);
}
@ -3759,9 +3759,10 @@ int main(int argc, char **argv) {
}
server.supervised = redisIsSupervised();
if (server.daemonize && server.supervised == 0) daemonize();
int background = server.daemonize && server.supervised == 0;
if (background) daemonize();
initServer();
if (server.daemonize && server.supervised == 0) createPidFile();
if (background || server.pidfile) createPidFile();
redisSetProcTitle(argv[0]);
redisAsciiArt();