Skip to content

Commit dd39211

Browse files
authored
tmpfiles.d: ensure tmp dir for lock files not be cleaned up (#921)
We should exclude `/tmp/fluentd-lock-*` directory. If `/tmp/fluentd-lock-*` is cleaned up while Fluentd is running: * out_file can fail flushing. * out_secondary can fail flushing. * The supervisor process exit abnormally when Fluentd stops. At least, RHEL 8 has the following default conf for tmpfiles.d: /usr/lib/tmpfiles.d/tmp.conf q /tmp 1777 root root 10d This can delete directories under `/tmp` if they are not used for more than 10 days. We don't need to protect the old lock files under `/tmp/fluentd-lock-*/`, so use `X` instead of `x`. In configs where lock files are not used, there is no problem even if this directory is deleted. In configurations that do use lock files, it’s unlikely that this directory would not be updated for more than 10 days. Therefore, the cases where this actually becomes an issue should be quite limited. If only out_secondary_file uses lock files, this can become an issue. Signed-off-by: Daijiro Fukuda <[email protected]>
1 parent e96985f commit dd39211

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

.github/workflows/apt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ jobs:
253253
- "update-without-data-lost.sh v6 v7"
254254
- "update-without-data-lost.sh v7 v6"
255255
- "obsolete-plugins.sh"
256+
- "tmpfiles.sh"
256257
include:
257258
- label: Debian bookworm amd64
258259
rake-job: debian-bookworm

.github/workflows/yum.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ jobs:
310310
- "update-without-data-lost.sh v6 v7"
311311
- "update-without-data-lost.sh v7 v6"
312312
- "obsolete-plugins.sh"
313+
- "tmpfiles.sh"
313314
include: ${{ fromJSON(needs.define-matrix.outputs.matrix).include }}
314315
exclude:
315316
- label: Amazon Linux 2023 x86_64
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -exu
4+
5+
. $(dirname $0)/../commonvar.sh
6+
7+
# Display unit info for debug
8+
sudo systemctl cat systemd-tmpfiles-clean.service
9+
sudo systemctl cat systemd-tmpfiles-clean.timer
10+
11+
# Install the built package
12+
sudo apt install -V -y \
13+
/host/${distribution}/pool/${code_name}/${channel}/*/*/fluent-package_*_${architecture}.deb
14+
15+
# Wait all processes to start
16+
systemctl status --no-pager fluentd
17+
sleep 3
18+
19+
# Test: the files under /tmp/ exist and not be cleaned up by default
20+
ls -d /tmp/fluent
21+
ls -d /tmp/fluentd-lock-*
22+
sudo systemd-tmpfiles --clean
23+
ls -d /tmp/fluent
24+
ls -d /tmp/fluentd-lock-*
25+
26+
# Make timestamps old
27+
touch -d "2 months ago" /tmp/fluentd
28+
touch -d "2 months ago" /tmp/fluentd-lock-*
29+
30+
# Test: the files under /tmp/ not be cleaned up even if they are old
31+
sudo systemd-tmpfiles --clean
32+
ls -d /tmp/fluent
33+
ls -d /tmp/fluentd-lock-*

fluent-package/templates/usr/lib/tmpfiles.d/fluentd.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ d /var/run/<%= package_dir %> 0755 <%= service_name %> <%= service_name %> - -
1919

2020
# Exclude <%= service_name %>
2121
x /tmp/<%= package_dir %>
22+
X /tmp/fluentd-lock-*
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
set -exu
4+
5+
. $(dirname $0)/common.sh
6+
7+
# Display unit info for debug
8+
sudo systemctl cat systemd-tmpfiles-clean.service
9+
sudo systemctl cat systemd-tmpfiles-clean.timer
10+
11+
# Install the built package
12+
install_current
13+
14+
# Wait all processes to start
15+
(! systemctl status --no-pager fluentd)
16+
sudo systemctl enable --now fluentd
17+
systemctl status --no-pager fluentd
18+
sleep 3
19+
20+
# Test: the files under /tmp/ exist and not be cleaned up by default
21+
ls -d /tmp/fluent
22+
ls -d /tmp/fluentd-lock-*
23+
sudo systemd-tmpfiles --clean
24+
ls -d /tmp/fluent
25+
ls -d /tmp/fluentd-lock-*
26+
27+
# Make timestamps old
28+
touch -d "2 months ago" /tmp/fluentd
29+
touch -d "2 months ago" /tmp/fluentd-lock-*
30+
31+
# Test: the files under /tmp/ not be cleaned up even if they are old
32+
sudo systemd-tmpfiles --clean
33+
ls -d /tmp/fluent
34+
ls -d /tmp/fluentd-lock-*

0 commit comments

Comments
 (0)