PackagingDrafts/Logfiles

= 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
 * 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
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 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
 * 1) rpm -U foo-1-1.noarch.rpm
 * 2) rpm -V foo
 * 1) rpm -qf /var/log/foo/*

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

Upgrade
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
 * increase
 * 1) rpm -U foo-1-2.noarch.rpm
 * 2) wc -l /var/log/foo/*

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

Removal
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 foo-C.rpmsave foo-D foo-F.rpmsave foo-G.rpmsave foo-H.rpmsave foo-Z
 * 1) rpm -e foo
 * 1) ls  /var/log/foo/

Conclusion::
 * only cases D and Z (not listed in  ) do not remove file after removal
 * A and B (no  or  ) plus E (plain  ) remove logfiles completely
 * cases C, F, G and H (various  attributes) rename old logfiles to  ; since   files will not be backup-ed by rpm, subsequent   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)