转载http://meinit.nl/rpm-spec-prepostpreunpostun-argument-values

RPM has 4 parts where (shell) scripts can be used:

  • %pre - Executed before installation.
  • %preun - Executed before un-installation.
  • %post - Executed after installation.
  • %postun - Executed after un-installation.

In all these parts or sections the variable "$1" can be checked to see what's being done:

  • Initial installation
  • Upgrade
  • Un-installation

This table show the values of "$1" per section related to the action.

  %pre %preun %post %postun
Initial installation 1 not applicable 1 not applicable
Upgrade 2 1 2 1
Un-installation not applicable 0 not applicable 0

This can be used for example when registering new services:

%post
case "$1" in
)
# This is an initial install.
chkconfig --add newservice
;;
)
# 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
)
# This is an un-installation.
service newservice stop
chkconfig --del newservice
;;
)
# This is an upgrade.
# Do nothing.
:
;;
esac

Good to know; this is the order for certain RPM actions:

install upgrade un-install
%pre ($1=1) %pre ($1=2) %preun ($1=0)
copy files copy files remove 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.  

So when upgrading the exemplary package "software" from version 1 to version 2, this is the script (%post and %postun) order:

  1. Run %pre from "software-2".
  2. Place files from "software-2".
  3. Run %post from "software-2".
  4. Run %preun from "software-1".
  5. Delete files unique to "software-1".
  6. Run %postun from "software-1".

This means there are cases where "software-1" has incorrect scripts, and there is no way to upgrade. In that case the RPM can be uninstalled, which might execute different commands because $1 equals 0 (un-install) instead of 1 (upgrade).
When the RPM uninstall scripts fail, the only way to fix things is to manually execute the intended commands... RPM is not perfect, but it's pretty well thought through!

spec文件中的 %pre %post %preun %postun的更多相关文章

  1. Pyinstaller通过spec文件打包py程序(多个py脚本)

    Pyinstaller pyinstaller是python的一个第三方模块,使用它可以将python程序打包为可执行文件,实现打包后的程序在没有python环境的机器上也可以运行.pyinstall ...

  2. rpm 系 linux 系统中 repo 文件中的 $release 到底等于多少?

    rpm 系 linux 系统中 repo 文件中的 $release 到底等于多少? 结论 对于 8 来说,通过以下命令 #/usr/libexec/platform-python -c 'impor ...

  3. 以libfuse为例介绍rpm打包工具rpmbuild的使用和SPEC文件的编写

    一.rpmbuild命令的安装 yum install rpm-build 二.用法 rpmbuild -bb XXXX.spec或者rpmbuild -ba XXX.tar.gz 三.目录概述 rp ...

  4. 使用spec文件语法创建一个rpm

    How to create an RPM package/zh-hk < How to create an RPM package 此页面包含 Packaging:ScriptletSnippe ...

  5. spec 文件详解

    转自http://blog.sina.com.cn/s/blog_43b39e250100nnu4.html rpm软件包系统的标准分组:/usr/share/doc/rpm-4.3.3/GROUPS ...

  6. spec文件写作规范

    spec文件写作规范 2008-09-28 11:52:17 分类: LINUX 1.The RPM system assumes five RPM directories BUILD:rpmbuil ...

  7. RPM安装包-Spec文件參数具体解释与演示样例分析

    spec文件是整个RPM包建立过程的中心,它的作用就如同编译程序时的Makefile文件. 1.Spec文件參数 spec文件包括建立一个RPM包必需的信息,包括哪些文件是包的一部分以及它们安装在哪个 ...

  8. Servlet从本地文件中读取图片,并显示在页面中

    import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSer ...

  9. HTML控件ID和NAME属性的区别,以及如何在asp.net页面的.CS文件中获得.ASPX页面中HTML控件的值

    在html中:name指的是用户名称,ID指的是用户注册是系统自动分配给用户的一个序列号. name是用来提交数据的,提供给表单用,可以重复: id则针对文档操作时候用,不能重复.如:document ...

随机推荐

  1. ddt框架优化(生成html报告注释内容传变量)

    https://blog.csdn.net/weixin_33923148/article/details/86017742 按要求修改后发现  注释只传值第一个变量 这是因为 ddt数据驱动生成ht ...

  2. RESTful学习笔记

    作为一名只有几个月IT自学经历的人,在接受新知识的时候总是想找到浅显易懂的方式去理解,但往往却很难找到相关的文章,大部分都是针对具有一定经验的开发人员,因此在看了很多相关的文章才对RESTful架构有 ...

  3. 深入学习Redis:Redis内存模型

    每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 一.Redis内存统计 工欲善其事必先利其器,在说明Redis内存之前首先说明如何统计 ...

  4. P3374 【模板】树状数组 1--洛谷luogu

    题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...

  5. 不可变对象和Biulder模式(面试问题)

    String就是一个典型的不可变对象.外界的操作不能改变它,如果尝试改变都会返回一个新的String对象. 具体实现起来就是把属性全部变成private 和 final的,这个类也是final的不可继 ...

  6. jquery()后续版本中,live()取消后使用on()实现功能写法

    今天做项目想用live()功能,写完打开浏览器发现报错 然后查了查发现自己用的是jquery是jquery-2.1.1.min.js,而jquery早就取消了live()方法,在后续版本里都已经没有使 ...

  7. devops工具-Ansible基础

    一.Ansible介绍 简介     Ansible使用Python语言开发,是一个配置管理型工具,与之类似的工具还有Puppet.SaltStack.chef等,默认通过SSH协议进行远程命令执行或 ...

  8. JavaScript原生秒表、计时器

    可以开始.暂停.清除. 效果图: 下面贴代码: <!DOCTYPE html> <html lang="en"> <head> <meta ...

  9. .NET(C#)主流ORM总揽

    前言 在以前的一篇文章中,为大家分享了<什么是ORM?为什么用ORM?浅析ORM的使用及利弊>.那么,在目前的.NET(C#)的世界里,有哪些主流的ORM,SqlSugar,Dapper, ...

  10. tornado设置cookie并加密

    最近看看tornado,遇到了sso的东西,了解下如何设置cookie 1.基本cookie set_cookie 方法在用户的浏览中设置 cookie: get_cookie 方法在用户的浏览中获取 ...