How to Fix Failed to Start Daily Cleanup of Temporary Directories in Ubuntu

Ubuntu utilizes the systemd temporary files management framework (systemd-tmpfiles-clean.service) triggered by systemd-tmpfiles-clean.timer to periodically purge stale files, sockets, and lockfiles from volatile storage directories such as /tmp and /var/tmp. However, reviewing system logs with systemctl is-system-running can report a degraded state accompanied by the error: Failed to start Daily Cleanup of Temporary Directories.

Why Does systemd-tmpfiles-clean.service Fail?

The cleanup service parses declarative configuration files in /usr/lib/tmpfiles.d/, /run/tmpfiles.d/, and /etc/tmpfiles.d/ before scanning temporary storage paths. Primary causes of service failures include:

  • Permission and Sticky Bit Violations on /tmp: The standard sticky bit permission (1777) missing from /tmp or /var/tmp, causing security traversal checks to abort.
  • Corrupted or Unreadable Sockets in /tmp: Dead daemon sockets or deeply nested directory trees holding unprivileged file handles that systemd-tmpfiles cannot unlink.
  • Syntax Errors in Custom tmpfiles.d Configurations: Third-party packages or administrators adding malformed line entries inside /etc/tmpfiles.d/*.conf.
  • Read-Only Root Filesystem: Disk volume faults forcing Ubuntu to remount the root partition in read-only mode, blocking cleanup transactions.
  • Extended File Attributes (Immutable Flags): Files inside temporary directories flagged with the immutable attribute (chattr +i), preventing standard deletion.

Method 1: Check Journal Logs and Identify Syntax Errors

Running the cleanup binary with diagnostic parameters reveals the exact configuration file or path triggering the failure.

  1. Open a root shell or connect via SSH.
  2. Check the service status:
    sudo systemctl status systemd-tmpfiles-clean.service
  3. Query the systemd journal for the service:
    sudo journalctl -u systemd-tmpfiles-clean.service -b --no-pager
  4. Look for log entries indicating Failed to parse line or Operation not permitted.

Method 2: Restore Standard Sticky Bit Permissions on /tmp and /var/tmp

The Linux filesystem standard requires temporary directories to have the sticky bit enabled (permissions 1777) so users can only delete their own files.

  1. Check current permissions on temporary directories:
    ls -ld /tmp /var/tmp
  2. If permissions do not display as drwxrwxrwt, restore the standard sticky bit and full permissions:
    sudo chmod 1777 /tmp
    sudo chmod 1777 /var/tmp
  3. Ensure that both directories are owned by root:
    sudo chown root:root /tmp /var/tmp
  4. Attempt to run the cleanup service manually:
    sudo systemd-tmpfiles --clean

Method 3: Remove Immutable Attributes from Stale Files

If automated deployment scripts inadvertently marked files inside /tmp as immutable, the cleanup process cannot remove them.

  1. Scan /tmp for files with the immutable (i) attribute:
    sudo lsattr -R /tmp 2>/dev/null | grep -E '^....i'
  2. If immutable files are identified, remove the attribute:
    sudo chattr -i /tmp/problematic-file
  3. Test running the service again:
    sudo systemctl restart systemd-tmpfiles-clean.service

Method 4: Validate Custom tmpfiles.d Configuration Files

Syntax errors in configuration files under /etc/tmpfiles.d/ cause the parser to exit prematurely.

  1. List custom configuration files:
    ls -la /etc/tmpfiles.d/
  2. Execute a dry-run test of all tmpfiles definitions:
    sudo systemd-tmpfiles --dry-run --clean
  3. Review the output for syntax warnings or line errors. Correct or remove any obsolete third-party configuration files.
  4. Verify that the service transitions to an active (exited) status with code 0:
    sudo systemctl status systemd-tmpfiles-clean.service

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.