Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
377 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?


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

1 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...