用法
作為非守護進程
運行
daemonize no
作為守護進程
運行
daemonize yes
?
注意事項:
默認情況下奴潘,Redis不作為守護進程運行御板。
如果以守護進程運行魁亦,會創(chuàng)建一個.pid
文件存儲進程號喉誊。
?
redis源碼
條件判斷
// https://github.com/redis/redis/blob/6.2.6/src/server.c
7996 int background = server.daemonize && !server.supervised;
7997 if (background) daemonize();
啟動邏輯
// https://github.com/redis/redis/blob/6.2.6/src/server.c
7121 void daemonize(void) {
7122 int fd;
7123
7124 if (fork() != 0) exit(0); /* parent exits */
7125 setsid(); /* create a new session */
7126
7127 /* Every output goes to /dev/null. If Redis is daemonized but
7128 * the 'logfile' is set to 'stdout' in the configuration file
7129 * it will not log at all. */
7130 if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
7131 dup2(fd, STDIN_FILENO);
7132 dup2(fd, STDOUT_FILENO);
7133 dup2(fd, STDERR_FILENO);
7134 if (fd > STDERR_FILENO) close(fd);
7135 }
7136 }
?
原生注釋
# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /usr/local/var/run/redis.pid when daemonized.
# When Redis is supervised by upstart or systemd, this parameter has no impact.
daemonize no
本文屬于原創(chuàng)邀摆,首發(fā)于微信公眾號【小易哥學(xué)呀學(xué)】,如需轉(zhuǎn)載請后臺留言伍茄。
加微信入交流群栋盹。vx:17610015120