Skip to content

Deploy FileCleaner with Docker and systemd

Refer to CLI Commands and Exit Codes before you start this procedure.

Prerequisites

  1. Make sure that you have sudo or root access on the Linux host.
  2. Make sure that Docker Engine or systemd is active on the host.
  3. Prepare /etc/filecleaner, /var/lib/filecleaner, and /var/log/filecleaner directories.

Safety Instructions

CAUTION: Set dry_run = true in new configuration files before you start the service. Rules with dry_run = false immediately compress, move, or delete files.

Procedure

  1. Create /etc/filecleaner/filecleaner.toml with dry_run = true and a validated rule:
dry_run = true
global_trash_dir = "/var/tmp/filecleaner-trash"

[daemon]
mode = "hybrid"
interval = "5m"
watch = true
debounce = "2s"
sweep_on_start = true
pid_file = "/var/lib/filecleaner/filecleaner.pid"
state_file = "/var/lib/filecleaner/state.json"
stop_file = "/var/lib/filecleaner/filecleaner.stop"

[audit]
log_path = "/var/log/filecleaner/audit.jsonl"
jsonl = true

[[rules]]
name = "app-backups"
path = "/var/backups/app"
recursive = false
follow_symlinks = false
include_globs = ["*.sql", "*.dump"]
max_files = 14
max_age = "30d"
actions = ["compress", "move"]
compression = "gzip"
move_to = "/mnt/cold-archive/app"

[rules.backup_guard]
enabled = true
min_keep_files = 3
min_valid_backup_bytes = "1MiB"
require_newer_within = "36h"
freeze_on_empty_valid = true
  1. Restrict permissions on the configuration file to owner read and write:
sudo chmod 0600 /etc/filecleaner/filecleaner.toml
  1. Validate the configuration file before you start any container or service:
filecleaner validate --config /etc/filecleaner/filecleaner.toml
  1. Run a read-only sweep plan to examine projected decisions:
filecleaner plan --config /etc/filecleaner/filecleaner.toml --json
  1. For a Docker deployment, set UID 10001 and GID 10001 on the configuration and host volumes:
sudo chown 10001:10001 /etc/filecleaner/filecleaner.toml
sudo chown -R 10001:10001 /var/lib/filecleaner /var/log/filecleaner /var/backups/app /mnt/cold-archive/app
  1. Pull the official Docker container image:
docker pull jmrenouard/filecleaner:v1.0.1
  1. Start container filecleaner-daemon with the mounted configuration and volume paths:
docker run -d \
  --name filecleaner-daemon \
  --restart unless-stopped \
  -v /etc/filecleaner:/etc/filecleaner:ro \
  -v /var/backups/app:/var/backups/app \
  -v /mnt/cold-archive/app:/mnt/cold-archive/app \
  -v /var/lib/filecleaner:/var/lib/filecleaner \
  -v /var/log/filecleaner:/var/log/filecleaner \
  jmrenouard/filecleaner:v1.0.1 \
  daemon run --config /etc/filecleaner/filecleaner.toml
  1. For a host systemd deployment, generate /etc/systemd/system/filecleaner.service and enable the unit:
sudo filecleaner daemon service-template \
  --init-system systemd \
  --config /etc/filecleaner/filecleaner.toml \
  --output /etc/systemd/system/filecleaner.service
sudo systemctl daemon-reload
sudo systemctl enable --now filecleaner
  1. Change dry_run = true to dry_run = false in /etc/filecleaner/filecleaner.toml, then restart the service.

NOTE: The official Docker image runs as non-root UID and GID 10001. Mounted host files and directories must permit UID 10001 access.

Verification

  1. Examine container or systemd unit status:
docker ps --filter name=filecleaner-daemon
sudo systemctl status filecleaner --no-pager
  1. Run filecleaner daemon status and confirm exit code 0:
filecleaner daemon status --config /etc/filecleaner/filecleaner.toml --json
  1. Examine /var/log/filecleaner/audit.jsonl and make sure that sweep_end records appear.

Rollback

If an error occurs after deployment, do these steps:

  1. Stop the Docker container or systemd service:
docker stop filecleaner-daemon && docker rm filecleaner-daemon
sudo systemctl disable --now filecleaner
  1. If a stale PID remains, run filecleaner daemon stop with a timeout:
filecleaner daemon stop --config /etc/filecleaner/filecleaner.toml --timeout 15s
  1. Replace /etc/filecleaner/filecleaner.toml with the previous valid configuration file.
  2. Start the previous service version and confirm healthy daemon status output.