RPM 规范文件案例更新

RPM 规范文件案例更新

我正在尝试创建 rpm 包。Spec 文件包含以下宏:

%postun
systemctl stop metrics_haproxy.service
systemctl stop checker_haproxy.service
systemctl stop keep_alive.service
systemctl disable metrics_haproxy.service
systemctl disable checker_haproxy.service
systemctl disable keep_alive.service
rm -f /etc/httpd/conf.d/haproxy-wi.conf
rm -f /etc/rsyslog.d/metric.conf
rm -f /etc/rsyslog.d/checker.conf
rm -f /etc/rsyslog.d/keep_alive.conf
rm -f /etc/logrotate.d/metric
rm -f /etc/logrotate.d/checker
rm -f /etc/logrotate.d/keep_alive
systemctl restart rsyslog
systemctl daemon-reload

%post
systemctl daemon-reload
systemctl restart rsyslog
systemctl restart metrics_haproxy.service
systemctl restart checker_haproxy.service
systemctl restart keep_alive.service
systemctl restart httpd
systemctl enable metrics_haproxy.service
systemctl enable checker_haproxy.service
systemctl enable keep_alive.service
systemctl enable httpd

但面临一个问题:当我使用新版本的 rpm 更新时,yum 会首先创建所有服务,然后删除。更新后,我仍未运行和启用任何服务

有没有什么解决方法?

答案1

你应该读这一页了解 rpm 安装时运行的脚本的顺序。最重要的是:

  1. 新软件包的发布量
  2. %旧包的postun

因此%postun旧包的脚本运行新包的脚本%post。你可能想做的是:

%postun
if [ $1 = 0 ]
then
  # the package is really being uninstalled, not upgraded
fi

由于你的旧包已经安装,%postun旧包的脚本仍将运行。因此,要修复此问题,我认为最简单的解决方案是进行更改,%post使其%posttrans运行剧本%postun

相关内容