ofelia icon indicating copy to clipboard operation
ofelia copied to clipboard

remove old log files

Open Ridder90 opened this issue 6 years ago • 8 comments

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?

Ridder90 avatar Jul 11 '18 14:07 Ridder90

Latter variant may work if the base image would be changed from scratch to something more "full".

thatside avatar Jul 24 '18 09:07 thatside

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

Ridder90 avatar Jul 27 '18 10:07 Ridder90

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.

andrewebdev avatar Aug 29 '18 16:08 andrewebdev

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 avatar Aug 29 '18 16:08 thatside

@thatside that's a very good point, and yes, I agree would be good if we could use logrotate to manage this.

andrewebdev avatar Aug 29 '18 18:08 andrewebdev

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)

thatside avatar Aug 29 '18 18:08 thatside

Any workarounds for this inside ofelia? My servers are getting full.

lucaswxp avatar Jun 02 '20 21:06 lucaswxp

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

taraspos avatar Jun 03 '20 07:06 taraspos