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

Categories

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?


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

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...