redis.conf详解之daemonize

用法

作为非守护进程运行

daemonize no

作为守护进程运行

daemonize yes 

 

注意事项:

默认情况下,Redis不作为守护进程运行。
如果以守护进程运行,会创建一个.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

本文属于原创,首发于微信公众号【小易哥学呀学】,如需转载请后台留言。
加微信入交流群。vx:17610015120

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容