首页 > 解决方案 > rpm.spec 中设置 systemd 预设的正确命令是什么

问题描述

我的程序中有几个单元,例如:

以及一个“program-cleanup.preset”文件,它只是说:

enable program-cleanup.timer

我无法理解我应该如何在此处设置文件。目前我的 rpm.spec 运行以下命令:

...
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

我需要在 .spec 文件systemctl preset program-cleanup.preset%post一部分中运行吗?如果我添加更多预设,我是否必须为每个预设再添加一行?

标签: rpmsystemdrpm-spec

解决方案


我个人以前没有使用过预设文件,但它们看起来很有趣。这里似乎是一个很好的设置(我只提到相关部分):

%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

推荐阅读