RHEL9 ディレクトリ/tmpのファイル自動削除の設定を確認する方法

環境
# cat/etc/redhat-release
Red Hat Enterprise Linux release 9.2 (Plow)

操作方法
1.systemdに/tmp削除のサービスが登録されていることを確認します。
# systemctl list-unit-files | grep systemd-tmpfiles | sort

結果

# systemctl list-unit-files | grep systemd-tmpfiles | sort
systemd-tmpfiles-clean.service static -
systemd-tmpfiles-clean.timer static -
systemd-tmpfiles-setup-dev.service static -
systemd-tmpfiles-setup.service static -

2,サービスの起動状態を確認します
/tmpの削除に関しては、「systemd-tmpfiles-clean.service」と「systemd-tmpfiles-clean.timer」が実行されます。

serviceへの登録内容を確認します
「systemd-tmpfiles –clean」を実行していることが分かります。

# cat /usr/lib/systemd/system/systemd-tmpfiles-clean.service
#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)

DefaultDependencies=no
After=local-fs.target time-set.target
Conflicts=shutdown.target initrd-switch-root.target
Before=shutdown.target initrd-switch-root.target

[Service]
Type=oneshot
ExecStart=systemd-tmpfiles --clean
SuccessExitStatus=DATAERR
IOSchedulingClass=idle
LoadCredential=tmpfiles.extra

3.サーバ起動してから15分経過後に初回が起動されます。以後1日毎に実行されます。
# cat /usr/lib/systemd/system/systemd-tmpfiles-clean.timer

実行結果

#  SPDX-License-Identifier: LGPL-2.1-or-later
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Daily Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
ConditionPathExists=!/etc/initrd-release

[Timer]
OnBootSec=15min
OnUnitActiveSec=1d

4.削除の設定を確認する
# cat /usr/lib/tmpfiles.d/tmp.conf

実行結果

# cat /usr/lib/tmpfiles.d/tmp.conf
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

# See tmpfiles.d(5) for details

# Clear tmp directories separately, to make them easier to override
q /tmp 1777 root root 10d
q /var/tmp 1777 root root 30d

 

IT

Posted by arkgame