Skip to content

Commit d7b1c3a

Browse files
Watson1978daipom
andauthored
Backport(v5): tmpfiles.d: ensure tmp dir for lock files not be cleaned up (#921) (#924)
Backport #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]> Signed-off-by: Shizuo Fujita <[email protected]> Co-authored-by: Daijiro Fukuda <[email protected]>
1 parent e8e74ca commit d7b1c3a

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

.github/workflows/apt.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ jobs:
213213
- "install-newly.sh local"
214214
- "install-newly.sh v5"
215215
- "install-newly.sh lts"
216+
- "tmpfiles.sh"
216217
include:
217218
- label: Debian bullseye amd64
218219
rake-job: debian-bullseye

.github/workflows/yum.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ jobs:
226226
- "install-newly.sh local"
227227
- "install-newly.sh v5"
228228
- "install-newly.sh lts"
229+
- "tmpfiles.sh"
229230
include:
230231
- label: RockyLinux 8 x86_64
231232
rake-job: rockylinux-8
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: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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 $DNF install -y \
13+
/host/${distribution}/${DISTRIBUTION_VERSION}/x86_64/Packages/fluent-package-[0-9]*.rpm
14+
15+
# Wait all processes to start
16+
(! systemctl status --no-pager fluentd)
17+
sudo systemctl enable --now fluentd
18+
systemctl status --no-pager fluentd
19+
sleep 3
20+
21+
# Test: the files under /tmp/ exist and not be cleaned up by default
22+
ls -d /tmp/fluent
23+
ls -d /tmp/fluentd-lock-*
24+
sudo systemd-tmpfiles --clean
25+
ls -d /tmp/fluent
26+
ls -d /tmp/fluentd-lock-*
27+
28+
# Make timestamps old
29+
touch -d "2 months ago" /tmp/fluentd
30+
touch -d "2 months ago" /tmp/fluentd-lock-*
31+
32+
# Test: the files under /tmp/ not be cleaned up even if they are old
33+
sudo systemd-tmpfiles --clean
34+
ls -d /tmp/fluent
35+
ls -d /tmp/fluentd-lock-*

0 commit comments

Comments
 (0)