PackagingDrafts/Logfiles

From FedoraProject

Jump to: navigation, search

Contents

Handling of Logfiles

Goals

  • logfiles should stay intact during package upgrades (e.g. do not lose old content)
  • logfiles should not be removed by package removals
  • rpm -V operations should not list them as bad files
  • logfiles should be associated with an rpm packages

Sniplet

%post
test -e %logfile || {
touch %logfile
chmod 0620 %logfile
chown root:somegroup %logfile
}

%files
%ghost %config                      %logfile

Rationale

rpm knows several attributes (%verify, %ghost, %config) which are candidates for handling logfiles. The following spec file uses possible combinations and shows their effects:
%global foos	A B C D E F H
%global logdir	/var/log/%name

Name:		foo
Version:	1
Release:	1
Summary:	none

Group:		none
License:	GPL
BuildRoot:	%_tmppath/%name-%version-%release-root
BuildArch:	noarch


%description

%install
rm -rf $RPM_BUILD_ROOT
mkdir -p $RPM_BUILD_ROOT%logdir

for i in %foos; do
touch $RPM_BUILD_ROOT%logdir/foo-$i
done


%post
for i in %foos; do
date >> %logdir/foo-$i
done
date >> %logfile/foo-Z

%clean
rm -rf $RPM_BUILD_ROOT


%files
%defattr(-,root,root,-)
%logdir/foo-A
%verify(not md5 size mtime) %logdir/foo-B
%config            %verify(not md5 size mtime) %logdir/foo-C
%config %ghost                                 %logdir/foo-D
%ghost                                 %logdir/foo-E
%config                                        %logdir/foo-F
%config(noreplace)                             %logdir/foo-G
%config(noreplace) %verify(not md5 size mtime) %logdir/foo-H

Initial installation

# rpm -U foo-1-1.noarch.rpm
# rpm -V foo
S.5....T   /var/log/foo/foo-A
S.5....T c /var/log/foo/foo-F
S.5....T c /var/log/foo/foo-G
# rpm -qf /var/log/foo/*
foo-1-1
foo-1-1
foo-1-1
foo-1-1
foo-1-1
foo-1-1
foo-1-1
foo-1-1
file /var/log/foo/foo-Z is not owned by any package

Conclusion::

  • case A (no attributes), F (plain %config) and G (%config(noreplace)) are violating third constraint (silent rpm -V)
  • case Z (not listed in %files) can not be associated with rpm package which violates fourth constraint

Upgrade

  • increase Release
# rpm -U foo-1-2.noarch.rpm
# wc -l /var/log/foo/*
1 /var/log/foo/foo-A
1 /var/log/foo/foo-B
2 /var/log/foo/foo-C
2 /var/log/foo/foo-D
2 /var/log/foo/foo-E
2 /var/log/foo/foo-F
2 /var/log/foo/foo-G
2 /var/log/foo/foo-H
2 /var/log/foo/foo-Z

Conclusion:: case A (no attributes) and B (only %verify) are violating first constraint (content must stay intact during upgrade)

Removal

# rpm -e foo
warning: /var/log/foo/foo-H saved as /var/log/foo/foo-H.rpmsave
warning: /var/log/foo/foo-G saved as /var/log/foo/foo-G.rpmsave
warning: /var/log/foo/foo-F saved as /var/log/foo/foo-F.rpmsave
warning: /var/log/foo/foo-C saved as /var/log/foo/foo-C.rpmsave
# ls  /var/log/foo/
foo-C.rpmsave
foo-D
foo-F.rpmsave
foo-G.rpmsave
foo-H.rpmsave
foo-Z

Conclusion::

  • only cases D (%config %ghost) and Z (not listed in %files) do not remove file after removal
  • A and B (no %ghost or %config) plus E (plain %ghost) remove logfiles completely
  • cases C, F, G and H (various %config attributes) rename old logfiles to .rpmsave; since .rpmsave files will not be backup-ed by rpm, subsequent rpm -U ; rpm -e operations will cause loss of logfiles too

Overall Comments

So it looks like case D satisfies all the requirements? --abadger1999 14:55, 24 April 2009 (UTC)

Usage of %config is misuse of this tag, just because of its behavior. It breaks semantics, because clearly log files are not configs. I suggested new tag %ghost(noremove) in rpm, which would solve this. BZ 1136453 --Msuchy (talk) 15:30, 2 September 2014 (UTC)