spec文件中的 %pre %post %preun %postun
转载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:
- Run %pre from "software-2".
- Place files from "software-2".
- Run %post from "software-2".
- Run %preun from "software-1".
- Delete files unique to "software-1".
- 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的更多相关文章
- Pyinstaller通过spec文件打包py程序(多个py脚本)
Pyinstaller pyinstaller是python的一个第三方模块,使用它可以将python程序打包为可执行文件,实现打包后的程序在没有python环境的机器上也可以运行.pyinstall ...
- rpm 系 linux 系统中 repo 文件中的 $release 到底等于多少?
rpm 系 linux 系统中 repo 文件中的 $release 到底等于多少? 结论 对于 8 来说,通过以下命令 #/usr/libexec/platform-python -c 'impor ...
- 以libfuse为例介绍rpm打包工具rpmbuild的使用和SPEC文件的编写
一.rpmbuild命令的安装 yum install rpm-build 二.用法 rpmbuild -bb XXXX.spec或者rpmbuild -ba XXX.tar.gz 三.目录概述 rp ...
- 使用spec文件语法创建一个rpm
How to create an RPM package/zh-hk < How to create an RPM package 此页面包含 Packaging:ScriptletSnippe ...
- spec 文件详解
转自http://blog.sina.com.cn/s/blog_43b39e250100nnu4.html rpm软件包系统的标准分组:/usr/share/doc/rpm-4.3.3/GROUPS ...
- spec文件写作规范
spec文件写作规范 2008-09-28 11:52:17 分类: LINUX 1.The RPM system assumes five RPM directories BUILD:rpmbuil ...
- RPM安装包-Spec文件參数具体解释与演示样例分析
spec文件是整个RPM包建立过程的中心,它的作用就如同编译程序时的Makefile文件. 1.Spec文件參数 spec文件包括建立一个RPM包必需的信息,包括哪些文件是包的一部分以及它们安装在哪个 ...
- Servlet从本地文件中读取图片,并显示在页面中
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSer ...
- HTML控件ID和NAME属性的区别,以及如何在asp.net页面的.CS文件中获得.ASPX页面中HTML控件的值
在html中:name指的是用户名称,ID指的是用户注册是系统自动分配给用户的一个序列号. name是用来提交数据的,提供给表单用,可以重复: id则针对文档操作时候用,不能重复.如:document ...
随机推荐
- JWT(JSON Web Token)
摘要: 在Web应用中,使用JWT替代session并不是个好主意 适合JWT的使用场景 抱歉,当了回标题党.我并不否认JWT的价值,只是它经常被误用. 什么是JWT 根据维基百科的定义,JSON W ...
- 11175-From D to E and Back(思维)
Problem UVA11175-From D to E and Back Accept: 164 Submit: 607Time Limit: 3000 mSec Problem Descript ...
- CSAPP:第八章 异常控制流1
CSAPP:第八章 异常控制流1 关键点:异常 8.1 异常8.2 进程 现代系统通过使控制流发生突变来对这些情况做出反应,一般而言,我们把这些突变称为异常控制流(Exceptional Cont ...
- centos7 mongodb安装
参考文档 http://www.runoob.com/mongodb/mongodb-connections.html https://www.cnblogs.com/layezi/p/7290082 ...
- 17 python 初学(迭代器)
生成器都是迭代器,迭代器不一定是生成器 迭代器满足两个条件: 1. 有iter方法 2. 有next方法 # list, tuple, dict, string: iterable(他们都有iter方 ...
- P3368 【模板】树状数组 2--洛谷luogu
题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数数加上x 2.求出某一个数的值 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个数. ...
- 学号 20175329 2018-2019-3《Java程序设计》第四周学习总结
学号 20175329 2018-2019-3<Java程序设计>第四周学习总结 教材学习内容总结 第五章 上周学习的第四章是体现了数据的封装,本章第五章主要是体现出对象的另外两个方面的重 ...
- List对象去重碎碎念之神叨叨
前言 List集合操作去除重复数据的这种情况经常会碰到,博客园里面也有很多大神们做过,在这里主要是借鉴然后自己整理了一下,主要是为了方便自己,以后再次碰到这种去重问题,直接打开自己的链接拿起键盘就是干 ...
- 从 0 到 1 实现 React 系列 —— 5.PureComponent 实现 && HOC 探幽
本系列文章在实现一个 cpreact 的同时帮助大家理顺 React 框架的核心内容(JSX/虚拟DOM/组件/生命周期/diff算法/setState/PureComponent/HOC/...) ...
- shell 读取配置文件的方法
原文地址:http://bbs.chinaunix.net/thread-3628456-1-1.html 总结地址:https://www.cnblogs.com/binbinjx/p/568021 ...