linux - rpm build .spec 更新时删除我的程序配置目录
问题描述
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
。
我不知道为什么?
解决方案
这是我注意到的几件事。如果我知道这是什么版本的 CentOS,我可以更好地针对这些建议。
Group: Applications/System
已过时且不需要。%clean
并且rm -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。对于 systemd 命令,您应该测试
$1
该软件包是否是第一次安装、升级或删除以决定运行哪个确切的 systemd 命令。https://fedoraproject.org/wiki/Systemd_Packaging_Draft#Scriptlets有一组您可能想做的事情的示例。例如,如果这是升级,您想要daemon-reload
和restart
(或try-restart
?)。一般来说,从来没有和朋友在一起
rm -rf
。%post
这些文件应该由 RPM 本身管理,并且应该由 RPM 删除。除非您确切知道自己在做什么,否则您的脚本不应该接触它们。
推荐阅读
- jquery - Jquery将行附加到表中不起作用
- java - 如何在 ArrayList 上应用 Executorservice
- php - 如何使用 PHP-FFMpeg 将视频修剪 4 个片段到 4 秒?
- python - 如何在 Python 脚本中将变量传递给 subprocess.run?
- c# - 用户登录时如何显示 HTML 元素。(ASP.NET Core MVC,无 EF)
- java - usingRecursiveFieldByFieldElementComparator 不起作用
- php - cakephp 验证在 save() 上不起作用
- c# - 多个表单上的 C# TransctionScope 实现
- django - 构想:我的实体关系图正确吗?
- python - 如何转换作为列表的列表?