Run Reactive Daemon and Rotate Logs¶
Refer to CLI Commands and Exit Codes and Configuration Schema and Invariants before you edit daemon settings.
Prerequisites¶
- Make sure that
/run/filecleanerand/var/log/filecleanerexist with write permissions. - Make sure that
/var/log/nginx/archiveand/var/log/myapp/rotateddirectories exist or are writable. - Confirm whether your application reopens log files on
SIGUSR1or keeps an open descriptor.
Safety Instructions¶
CAUTION: Select copy_truncate only when the writer cannot reopen log files.
Log bytes written between copy completion and file truncation are lost permanently.
CAUTION: Exclude archive subfolders inside recursive rules with exclude_globs.
Otherwise filecleaner validate rejects the self-referential path with INV-CFG-09.
Procedure¶
- Create
/etc/filecleaner/daemon-logs.yamlwithhybridmode and two log rotation rules:
dry_run: true
daemon:
mode: hybrid
interval: 5m
watch: true
debounce: 2s
sweep_on_start: true
pid_file: /run/filecleaner/filecleaner.pid
state_file: /run/filecleaner/state.json
stop_file: /run/filecleaner/filecleaner.stop
audit:
log_path: /var/log/filecleaner/logs-audit.jsonl
jsonl: true
rules:
- name: app-active-logs
path: /var/log/myapp
recursive: false
follow_symlinks: false
include_globs:
- "*.log"
min_file_size: 10MiB
time_basis: modified
max_total_size: 2GiB
in_use:
enabled: true
check_sidecar_locks: true
check_os_locks: false
check_proc_fd: false
min_idle_age: 5s
actions:
- copy_truncate
copy_truncate_to: /var/log/myapp/rotated
compression: lz4
rename_template: "%Y%m%d_%H%M%S"
- name: nginx-reopened-logs
path: /var/log/nginx
recursive: true
max_depth: 2
follow_symlinks: false
include_globs:
- "*.log.[0-9]*"
exclude_globs:
- "archive/**"
time_basis: modified
max_files: 30
max_age: 14d
actions:
- rename_by_date
- compress
- move
rename_template: "%Y%m%d_%H%M%S"
compression: brotli
compress_remove_source: true
move_to: /var/log/nginx/archive
move_date_subdir: "%Y/%m"
- Run
filecleaner validateand examine the expectedcopy_truncateadvisory message onstderr:
- Run one bounded dry-run daemon cycle to test watcher setup and JSON state output:
filecleaner daemon run --config /etc/filecleaner/daemon-logs.yaml --mode interval --max-sweeps 1 --dry-run
-
Change
dry_run: truetodry_run: falsein/etc/filecleaner/daemon-logs.yaml. -
Start the daemon in
hybridmode under your process supervisor or in a dedicated terminal:
- Stop the daemon cleanly when maintenance is necessary:
NOTE: AuditLogger rotates logs-audit.jsonl to logs-audit.jsonl.1 when size reaches 50 MiB.
FileCleaner automatically excludes rotated .1 audit files from rule scans.
Verification¶
- Run
filecleaner daemon statusand confirm"running": truein JSON output:
- Inspect
/var/log/nginx/archiveand/var/log/myapp/rotatedfor compressed.brand.lz4files. - Inspect
/run/filecleaner/state.jsonand confirmlast_errorisnull.
Rollback¶
If log rotation drops active bytes or causes high I/O load, do these steps:
- Stop the daemon cleanly:
- Set
dry_run: truein/etc/filecleaner/daemon-logs.yaml. - Replace
copy_truncatewithrename_by_date,compress, andmoveafterSIGUSR1log reopen. - Validate the updated configuration and restart the daemon.
Related Documentation¶
- Reference: CLI Commands and Exit Codes
- Reference: Configuration Schema and Invariants
- Explanation: Fail-Closed 6-Phase Pipeline