2

I wrote a .spec file on RHEL and I am building RPM using rpmbuild. I need ideas on how to handle the situation below.

My RPM creates an empty logs directory when it installs first time within the installation folder like below

 /opt/MyInstallation-1.0.0-1/some executables
 /opt/MyInstallation-1.0.0-1/lib/carries shared objects(.so files)
 /opt/MyInstallation-1.0.0-1/config/carries some XML and custom configuration files(.xml, etc)
 /opt/MyInstallation-1.0.0-1/log--->This is where application writes logs

When my RPM upgrades MyInstallation-1.0.0-1, to MyInstallation-1.0.0-2 for example, I get everything right as I wanted.

But, my question is how to preserve log files written in MyInstallation-1.0.0-1? Or to precisely copy the log directory to MyInstallation-1.0.0-2.

2 Answers 2

0

I believe if you tag the directory as %config, it is expected that the user will have files in there, so it will leave it alone.

0

I found a solution or workaround to this by hit and trial method :)

I am using rpmbuild version 4.8.0 on RHEL 6.3 x86_64. I believe it will work on other distros as well.

If you install with one name only like "MyInstallation" rather than "MyInstallation-version number-RPM Build Number" and create "logs directory as a standard directory(no additional flags on it)[See Original Question for scenario] Whenever you upgrade, you normally don't touch logs directory. RPM will leave its contents as it is. All you have to do is to ensure that you keep the line below in the install section.

%install install --directory $RPM_BUILD_ROOT%{_prefix}/%{name}/log

Here, prefix and name are macros. That has to do nothing with underlying concept.

Regarding config files, the following is a very precise table that will help you guarding your config files. Again, this rule can't be applied on logs our applications create.

http://www-uxsup.csx.cam.ac.uk/~jw35/docs/rpm_config.html

Thanks & Regards.

1
  • More to the point, ensure that %files in both packages contain a specification that includes that directory, and then it will not be removed. Of course, you will still have to create that directory if the upstream source does not - is it not cleaner to patch the upstream makefile to also make its log directory properly? Personal preference, I guess - but the key is to ensure the %files in both projects need that directory so that it's preserved between upgrades. Aug 24, 2017 at 2:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.