其他人也有同样的问题。请参阅此要点。
当 daemonize 选项被激活时,Redis 不会检查进程是否已经是守护进程(没有调用 getppid)。它系统地分叉,但只有一次。这有点不寻常,其他守护进程机制可能需要对 getppid 进行初始检查,并调用两次 fork(在调用 setsid 之前和之后),但在 Linux 上这不是严格要求的。
有关守护进程的更多信息,请参阅此常见问题解答。
Redis daemonize 功能极其简单:
void daemonize(void) {
int fd;
if (fork() != 0) exit(0); /* parent exits */
setsid(); /* create a new session */
/* Every output goes to /dev/null. If Redis is daemonized but
* the 'logfile' is set to 'stdout' in the configuration file
* it will not log at all. */
if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
dup2(fd, STDIN_FILENO);
dup2(fd, STDOUT_FILENO);
dup2(fd, STDERR_FILENO);
if (fd > STDERR_FILENO) close(fd);
}
}
新贵文档说:
expect daemon
Specifies that the job's main process is a daemon, and will fork twice after being run.
init(8) will follow this daemonisation, and will wait for this to occur before running
the job's post-start script or considering the job to be running.
Without this stanza init(8) is unable to supervise daemon processes and will
believe them to have stopped as soon as they daemonise on startup.
expect fork
Specifies that the job's main process will fork once after being run. init(8) will
follow this fork, and will wait for this to occur before running the job's post-start
script or considering the job to be running.
Without this stanza init(8) is unable to supervise forking processes and will believe
them to have stopped as soon as they fork on startup.
所以我要么在 Redis 端停用守护进程,要么尝试在新贵配置中使用 expect fork 而不是 expect 守护进程。