ofelia
ofelia copied to clipboard
remove old log files
Hi there,
I really like the logging feature. But i want to be able to remove log files older then say 7 days.
I mounted the ofelia logs volume: logs/cron:/tmp/logs
Next i tried to just remove all files:
[job-exec "clean logs"]
schedule = @every 20s
container = ofelia
command = rm /tmp/logs/*
Unfortunately this fails with stdout unable to find user root: no matching entries in passwd file
I also tried to run it on the host:
[job-local "clean logs"]
schedule = @every 20s
command = rm /home/florian/Projects/myproject/logs/cron/*
But it fails with : failed: true, skipped: false, error: exec: "rm": executable file not found in $PATH
Any suggestions?
Latter variant may work if the base image would be changed from scratch to something more "full".
Thanks! Will try to fork this and change line 12 in the dockerfile to FROM alpine and see if running the command on the host will work.
https://github.com/mcuadros/ofelia/blob/master/Dockerfile#12
Maybe add a [global] config var that specifies the maximum log age, and then ofelia cleans any logs older than the log-age variable?
I would be willing to create a PR to add this feature if there is interest? I guess it's up to @mcuadros and he's vision for what scope for this project is.
This seems to be more difficult solution and it adds some functions which aren't actually related to Ofelia as a cron replacement.
Personally I think that Ofelia log format should be changed to allow using logrotate in a common way.
@thatside that's a very good point, and yes, I agree would be good if we could use logrotate to manage this.
Maybe the best solution would be to have 2 logging modes:
- one with simple logging (without task output):
started-success-failure - one with full logging (maybe adding nested folders for each task and maybe even writing all execution logs to same files - just appending new data including some metadata like execution timestamp)
Any workarounds for this inside ofelia? My servers are getting full.
Not for the moment, but I think the approach of adding job to clean up log files must work. Similar as OP posted, something like:
[job-local "cleanup logs"]
schedule = @hourly
command = find /tmp/ -name "*.log" -type f -mtime +7 -delete -print