centos rpm build .spec在更新时删除我的程序配置目录

ikfrs5lh  于 2022-11-07  发布在  其他
关注(0)|答案(1)|浏览(199)

uniin-cluster-agent是我的程序,etc是我的程序配置。
/usr/bin/uniin-cluster-agent -c /etc/unilin_cluster_agent/config.yml
这是启动命令

Name: uniin-cluster-agent
Version: %{?agent_version}
Release: %{?dist}

Summary: uniin-cluster-agent servcie
Group: Applications/System
License: xxx

%description

%install
mkdir -p %{buildroot}%{_bindir}
cp uniin-cluster-agent %{buildroot}%{_bindir}
cp -r etc %{buildroot}

%clean
rm -rf %{_builddir}/*

%files
%{_bindir}/uniin-cluster-agent
/etc/unilin_cluster_agent/*
/etc/systemd/system/uniin-cluster-agent.service

%post
systemctl daemon-reload
systemctl enable uniin-cluster-agent.service
systemctl restart uniin-cluster-agent.service

%preun
systemctl stop uniin-cluster-agent.service
systemctl disable uniin-cluster-agent.service

%postun
systemctl daemon-reload
rm -rf /etc/unilin_cluster_agent

安装得很好,但我更新时使用rpm -Uvh xxx.rpm
我可以看到系统安装我的新版本rpm,然后清理并删除旧版本。但它也删除了dir /etc/unilin_cluster_agent/usr/bin/uniin-cluster-agent,更新后。
我不知道为什么?

mbyulnm0

mbyulnm01#

这里有几件事我注意到了。如果我知道这是什么版本的CentOS,我可以更好地定位建议。

  • Group: Applications/System已过时,不再需要。
  • %cleanrm -rf %{_builddir}/*通常是隐含的,至少在最近的CentOS/Fedora/RHEL版本中是这样。
  • 您应该拥有%files中的集群代理目录(沿着子目录)。我会将/etc/unilin_cluster_agent/*更改为/etc/unilin_cluster_agent。这表示“拥有该目录及其中的所有内容。一个很好的好处是,当卸载软件包时,文件/目录将自动删除。
  • 配置文件(那些安装在/etc/下的文件)应该标记为%config(或%config(noreplace))。请参见https://www.cl.cam.ac.uk/~jw35/docs/rpm_config.html以了解它们的含义以及哪一个更适合您的用例。
  • %pre%post%preun%postun的顺序完全不直观。所有这些都将在软件包升级期间运行。有关顺序,请访问https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#ordering。
  • 若要实际正确侦测升级/解除安装,您应该在执行命令档时测试$1的值。此值是作业(安装、升级、移除)完成时,系统上会保留的套服程序数目。https://docs.fedoraproject.org/en-US/packaging-guidelines/Scriptlets/#_syntax如需完整详细信息,请参阅www.example.com。
  • 对于systemd命令,您应该使用$1进行测试,以查看软件包是首次安装、升级还是删除,从而确定要运行哪个systemd命令。https://fedoraproject.org/wiki/Systemd_Packaging_Draft#Scriptlets提供了一组您可能需要执行的操作的示例。例如,如果这是升级,您需要daemon-reloadrestart(或try-restart?)。
  • 一般来说,千万不要在%post和朋友的时候使用rm -rf。这些文件应该由RPM自己管理,并且应该由RPM删除。除非你确切地知道你在做什么,否则你的脚本不应该接触它们。

相关问题