Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
284 views
in Technique[技术] by (71.8m points)

What are the correct commands in rpm.spec to set-up the systemd preset

I have a few units in my program, such as:

  • program.service
  • program-cleanup.service
  • program-cleanup.timer
  • ...

As well as a 'program-cleanup.preset' file which just says:

enable program-cleanup.timer

I am having trouble understanding how I should be setting up the files here. Currently my rpm.spec runs the following commands:

...
install -D -m 0644 %{_sourcedir}/build/program.service %{_unitdir}/program.service
install -D -m 0644 %{_sourcedir}/build/program-cleanup.service %{_unitdir}/program-cleanup.service
install -D -m 0644 %{_sourcedir}/build/program-cleanup.timer %{_unitdir}/program-cleanup.timer
install -D -m 0644 %{_sourcedir}/build/program-cleanup.preset %{_presetdir}/program-cleanup.preset

Do I need to run a systemctl preset program-cleanup.preset in the %post part of the .spec file? If I add more presets, would I have to add one more line per preset?

question from:https://stackoverflow.com/questions/65661946/what-are-the-correct-commands-in-rpm-spec-to-set-up-the-systemd-preset

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I personally haven't used preset files before, but they look interesting. What seems to be a good setup here (I mention only the relevant parts):

%install
install -D -m 0644 %{_sourcedir}/build/program-cleanup.preset %{_presetdir}/program-cleanup.preset

%post
systemd preset program-cleanup.preset

%preun
if [ $1 -eq 0 ] ; then
  # really uninstalling, not upgrading:
  # probably you might want to stop and disable your units when uninstalling:
  systemctl stop program.service
  systemctl disable program.service
  ...
fi

%files
%{_presetdir}/program-cleanup.preset

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...