• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How systemd-tmpfiles cleans up /tmp/ or /var/tmp (replacement of tmpwatch) in CentOS / RHEL 7

by admin

In CentOS/RHEL 7, tmpfiles cleans up /tmp or /var/tmp by removing unused files. This function was called “tmpwatch” in CentOS/RHEL 6 which is invoked by crond, however, it is now realized by timer of systemd on CentOS/RHEL 7.

Currently the detailed functions of tmpfiles are described in configuration files:

/usr/lib/systemd/system/systemd-tmpfiles-clean.timer
/usr/lib/systemd/system/systemd-tmpfiles-clean.service
/usr/lib/tmpfiles.d/tmp.conf

Shortly speaking, the functions available are:

  • removing files/directories in /tmp un-accessed more than 10 days(defined in tmp.conf)
  • removing files/directories in /var/tmp un-accessed more than 30 days(defined in tmp.conf)
  • there are several files which will not be removed(defined in tmp.conf)
  • the removing command is “/usr/bin/systemd-tmpfiles –clean“(defined in systemd-tmpfiles-clean.service)

“un-accessed” is decided by checking all of atime/mtime/ctime of the file/directory. Thus, in case even one of atime/mtime/ctime of a file in /tmp/ is newer than 10 days, the file will not removed. If a file/directory in /tmp/ is not removed by tmpfiles even if it seems it is older than 10 days, the reason can be checked by running a command with debug options like below manually:

# SYSTEMD_LOG_TARGET=console SYSTEMD_LOG_LEVEL=debug /usr/bin/systemd-tmpfiles --clean

For example, below intends that a directory “/tmp/latest” can not be removed due to its atime.

# SYSTEMD_LOG_TARGET=console SYSTEMD_LOG_LEVEL=debug /usr/bin/systemd-tmpfiles --clean 2>&1 | grep latest
Directory "/tmp/latest": access time Wed 2017-12-06 16:56:28.771577 IST is too new

Sample configuration files

Below are the 3 sample configuration files (un-edited) with their default settings.

# cat /usr/lib/systemd/system/systemd-tmpfiles-clean.timer
[Unit]
Description=Daily Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)

[Timer]
OnBootSec=15min
OnUnitActiveSec=1d
# cat /usr/lib/tmpfiles.d/tmp.conf
# Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d
v /var/tmp 1777 root root 30d

# Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp
# cat /usr/lib/systemd/system/systemd-tmpfiles-clean.service
[Unit]
Description=Cleanup of Temporary Directories
Documentation=man:tmpfiles.d(5) man:systemd-tmpfiles(8)
DefaultDependencies=no
Conflicts=shutdown.target
After=systemd-readahead-collect.service systemd-readahead-replay.service local-fs.target time-sync.target
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=/usr/bin/systemd-tmpfiles --clean
IOSchedulingClass=idle

Filed Under: CentOS/RHEL 7, Linux

Some more articles you might also be interested in …

  1. touch: command not found
  2. “Device /dev/mappper/mpath25 Not Found (or Ignored By Filtering)” – error while creating physical volume with pvcreate
  3. Volume “test_vg/lvol0” is not active locally – Error while running lvcreate
  4. “docker login” Command Examples
  5. mkinitcpio Command Examples in Linux
  6. dnstracer Command Examples in Linux
  7. calcurse: command not found
  8. synopkg: command not found in Linux
  9. make: command not found
  10. eval: Execute arguments as a single command in the current shell and return its result

You May Also Like

Primary Sidebar

Recent Posts

  • gixy Command Examples
  • gitsome Command Examples
  • gitmoji Command Examples
  • gitlint Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright