升级和安装的rpm过程中 spec 文件中脚本调用顺序和参数

升级和安装的rpm过程中 spec 文件中脚本调用顺序和参数

RPM has 4 parts where (shell) scripts can be used:
RPM 在升级/安装的过程中,有4个部分的脚本会被调用:

  • %pre - 安装前调用
  • %preun - 卸载前调用
  • %post - 安装后调用
  • %postun - 卸载后调用

在执行这些脚本时,都会同一个变量 “$1” 传入的值,来判断具体执行的是以下的哪步操作:

  • Initial installation
  • Upgrade
  • Un-installation
%pre%preun%post%postun
Initial installation1不适用1不适用
Upgrade2121
Un-installation不适用0不适用0

下面是一个脚本的模板:

%post
case "$1" in
1)
# This is an initial install.
chkconfig --add newservice
;;
2)
# This is an upgrade.
# First delete the registered service.
chkconfig --del newservice
# Then add the registered service. In case run levels changed in the init script, the service will be correctly re-added.
chkconfig --add newservice
;;
esac

%preun
case "$1" in
0)
# This is an un-installation.
service newservice stop
chkconfig --del newservice
;;
1)
# This is an upgrade.
# Do nothing.
:
;;
esac

下表是安装/升级过程中,具体执行的操作的顺序:

installupgradeun-install
pre $1=1%pre $1=2%preun $1=0
copy filescopy filesremove files
%post $1=1%post $1=2%postun $1=0
%preun $1=1 from old RPM.
delete files only found in old package
%postun $1=1 from old RPM.

所以,如果对某一个包从版本1升级到版本2的操作, 脚本的执行顺序会如下所示:

  1. 执行 v2 的 %pre
  2. 释放 v2 中的文件
  3. 执行 v2 的 %post
  4. 执行 v1 的 %preun
  5. 删除 v1 中特有的文件
  6. 执行 v1 中的 %postun

这就意味着,如果 v1 的程序中包含有不正确的脚本,就会导致无法正常升级。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值