涛子 - 简单就是美

成单纯魁增,永继振国兴,克复宗清政,广开家必升

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

安装

yum install -y rpm-build
yum install -y ruby-devel gcc
gem source -a https://ruby.taobao.org/
gem source -r http://rubygems.org/
gem install fpm -V

fpm常用参数

-s: 指定源类型
-t: 指定目标类型,即想要制作为什么包
-n: 指定包的名字
-v: 指定包的版本号
-a: all - onarch, native x86_64 or i386
-C: 指定打包的相对路径,即build directory
-d --depends: 指定依赖于哪些包
--post-install: 软件包安装完成之后所要运行的脚本,和'--after-install'意思一样
--pre-install: 软件包安装完成之前所要运行的脚本,和'--before-install'意思一样
--post-uninstall: 软件包卸载完成之后所要运行的脚本,和'--after-remove'意思一样
--pre-uninstall: 软件包卸载完成之前所要运行的脚本,和'--before-remove'意思一样

示例

# tree monitor-agent-2.0/
monitor-agent-2.0/
├── etc
│   ├── nagios
│   │   └── nrpe.cfg.rpmnew
│   └── nrpe.d
│       ├── app.cfg
│       ├── base.cfg
│       └── dell.cfg
├── monitor-agent-2.0-1.x86_64.rpm
├── post-install
├── post-uninstall
├── pre-install
├── pre-uninstall
└── usr
    └── lib64
        └── nagios
            └── plugins
                ├── check_broadcast_status
                ├── check_live_status
                ├── check_live_transfer
                └── check_system

pre-install

#!/bin/bash

mv /etc/nagios/nrpe.cfg /etc/nagios/nrpe.cfg.rpmsave

post-install

#!/bin/bash

chmod 755 /usr/lib64/nagios/plugins/check_*
cp /etc/nagios/nrpe.cfg.rpmnew /etc/nagios/nrpe.cfg

version=$(rpm -q --queryformat '%{VERSION}' centos-release)

if [ $version == '6' ]; then
	/etc/init.d/nrpe start && chkconfig nrpe on
elif [ $version == '7' ]; then
	systemctl start nrpe.service && systemctl enable nrpe.service
fi

pre-uninstall

#!/bin/bash

post-uninstall

#!/bin/bash

version=$(rpm -q --queryformat '%{VERSION}' centos-release)

if [ $version == '6' ]; then
    /etc/init.d/nrpe restart
elif [ $version == '7' ]; then
	systemctl restart nrpe.service
fi

打包

fpm -s dir -t rpm -n 'monitor-agent' -v 2.0 --vendor 'tvm' -d 'nrpe >= 2.15' -d 'nagios-plugins >= 2.0.3' \
--pre-install pre-install --post-install post-install --pre-uninstall post-uninstall --post-uninstall post-uninstall \
etc usr
posted on 2015-03-25 15:34  北京涛子  阅读(358)  评论(0编辑  收藏  举报