[systemd-devel] [Feature request] Retentiontime per unit configuration

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed Oct 22 21:25:12 PDT 2014


On Thu, Oct 23, 2014 at 01:09:25AM +0200, Lennart Poettering wrote:
> On Wed, 27.08.14 08:39, Kris Erik Schwerdt (Schwerdt at itsc.uni-luebeck.de) wrote:
> 
> > Hallo 
> > 
> > During a task of migration of multiple servers to a systemd-based
> > distribution I was wondering if there would be a way of setting the
> > retentiontime of journald per unit.
> > In some cases e.g. there are limits for special program e.g. webserver
> > where it is not allowed to keep the logs as long as the syslog. So it would
> > be nice to have such a feature to avoid as much as possible plain-logfiles.
> 
> The retention logic is currently implemented per-journal. As soon as
> the retention time is reached we rotate the whole journal away, and
> rotate.
> 
> To allow per-service retention times would mean we'd either have to
> split up the journal files per-service from the beginning (which would
> suck perfomance-wise while viewing), or we'd have to "repack" the
> files during rotate/vacuuming (which would suck perfomance-wise while
> roating/vacuuming). The latter sounds slightly better for this. 
> 
> In the past, we got requests to allow different retention times for
> the various log priorities. I figure if we implement that we can also
> implement per-service retention times at the same time, using the same
> logic. 
> 
> That all said, I am not entirely sure what a natural way to configure
> the retention time could be and (assuming that we'd want to configure
> this in .service files) how we'd pass this nicely to journald to
> enforce.
> 
> Anyway, for now I added this to the TODO list, so that it is not
> forgotten.
The code to rewrite journal files is mostly there... You could already
do something like this:

  for i in /var/log/journal/*/*@*; do
     journalctl --file $i -p info -o export | systemd-journal-remote -o $i.tmp - \
     && mv $i.tmp $i
  done

(which would filter out all debug messages, but you can apply any filter).

Doing this in C should be fairly easy. I don't see why this couldn't be
run as a separate process.

Zbyszek


More information about the systemd-devel mailing list