重新加载容器化流利配置



假设我的容器名为fluentd,我希望这个命令能够重新加载配置:

sudo docker kill -s HUP fluentd

相反,它会杀死容器。

似乎从入口点生成了一些进程:

PID   USER     TIME   COMMAND
1 root       0:00 {entrypoint.sh} /usr/bin/dumb-init /bin/sh /bin/entrypoint.sh /bin/sh -c fluentd -c /fluentd/etc/${FLUENTD_CONF} -p /fluentd/pl
5 root       0:00 /bin/sh /bin/entrypoint.sh /bin/sh -c fluentd -c /fluentd/etc/${FLUENTD_CONF} -p /fluentd/plugins $FLUENTD_OPT
13 fluent     0:00 /bin/sh -c fluentd -c /fluentd/etc/${FLUENTD_CONF} -p /fluentd/plugins $FLUENTD_OPT
14 fluent     0:00 {fluentd} /usr/bin/ruby /usr/bin/fluentd -c /fluentd/etc/fluentd.conf -p /fluentd/plugins
16 fluent     0:00 {fluentd} /usr/bin/ruby /usr/bin/fluentd -c /fluentd/etc/fluentd.conf -p /fluentd/plugins

尝试从容器pid 13内部进行HUPping,它似乎有效。

Docker 正在将信号发送到入口点。如果我检查 State.Pid,我看到 4450。这是主机ps:

root      4450  4432  0 18:30 ?        00:00:00 /usr/bin/dumb-init /bin/sh /bin/entrypoint.sh /bin/sh -c fluentd -c 
/fluentd/etc/${FLUENTD_CONF} -p /fluentd/plugins $FLUENTD_OPT
root      4467  4450  0 18:30 ?        00:00:00 /bin/sh /bin/entrypoint.sh /bin/sh -c fluentd -c /fluentd/etc/${FLUENTD_CONF} -p /fluentd/plugins $FLUENTD_OPT
ubuntu    4475  4467  0 18:30 ?        00:00:00 /bin/sh -c fluentd -c /fluentd/etc/${FLUENTD_CONF} -p /fluentd/plugins $FLUENTD_OPT
ubuntu    4476  4475  0 18:30 ?        00:00:00 /usr/bin/ruby /usr/bin/fluentd -c /fluentd/etc/fluentd.conf -p /fluentd/plugins
ubuntu    4478  4476  0 18:30 ?        00:00:00 /usr/bin/ruby /usr/bin/fluentd -c /fluentd/etc/fluentd.conf -p /fluentd/plugins

任何想法如何在没有自定义脚本的情况下重新加载 conf 以找到正确的 HUP 进程?

我相信这个命令应该有效

sudo docker exec fluentd pkill -1 -x fluentd

我在流利容器内的睡眠命令上测试了它,它可以工作。

在我的例子中,fluentd 在 kubernetes 上作为 pod 运行。 对我有用的命令是:

kubectl -n=elastic-system exec -it fluentd-pch5b -- kill  --signal SIGHUP 7

其中7的数字是容器内流利进程 ID 如下所示:

root@fluentd-pch5b:/home/fluent# ps -elf
F S UID        PID  PPID  C PRI  NI ADDR SZ WCHAN  STIME TTY          TIME CMD
4 S root         1     0  0  80   0 -  2075 -      14:42 ?        00:00:00 tini -- /fluentd/entrypoint.sh
4 S root         7     1  0  80   0 - 56225 -      14:42 ?        00:00:02 ruby /fluentd/vendor/bundle/ruby/2.6.0/bin/fluentd -c /fluentd/etc/fluent.co
4 S root        19     7  0  80   0 - 102930 -     14:42 ?        00:00:06 /usr/local/bin/ruby -Eascii-8bit:ascii-8bit /fluentd/vendor/bundle/ruby/2.6.
4 S root        70     0  0  80   0 -  2439 -      14:52 pts/0    00:00:00 bash
0 R root        82    70  0  80   0 -  3314 -      14:54 pts/0    00:00:00 ps -elf

最新更新