rpmbuild 应用

最近需要将一些php和python的程序打包成rpm包,方便在服务器上面安装,并且安装后自动添加的init.d的启动过程中。需要大致执行下面的过程:

1 rpmbuild 环境准备

1.1 自定义rpmbuild宏
$ vi ~/.rpmmacros
%_topdir       /home/lht/rpmbuild
%debug_package %{nil}
%_unpackaged_files_terminate_build 0


1.2 建立rpmbuild需要的目录
在$home目录下面建立下面的目录结构
$ mkdir -p rpmbuild/BUILD rpmbuild/RPMS/athlon rpmbuild/RPMS/i386 rpmbuild/RPMS/i486 rpmbuild/RPMS/i586 rpmbuild/RPMS/i686 rpmbuild/RPMS/noarch rpmbuild/SOURCES rpmbuild/SPEC rpmbuild/SRPMS

2 创建源代码包和编写spec文件

2.1 创建源代码包
$ cd ~/rpmbuild/SOURCES
$ mkdir mirchgr; cd mirchgr
$ mkdir -p etc/init.d etc/mirchgr usr/bin var/log/mirchgr var/lib/mirchgr
拷贝要安装的文件到相应的目录中, 并打包为tgz文件
$ cd ..
$ tar czf mirchgr.tgz mirchgr

2.2 创建spec文件
$ cd ~/rpmbuild/SPEC
$ vi mirchgr.spec
Name: mirchgr
Version: 1.0.0
Release: 1%{?dist}
Summary: this is a test rpm spec
License: copyright by lht
Group: Applications
URL: http://lht.iteye.com

Source0: %{name}.tgz

BuildArch: noarch
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Prereq: /sbin/chkconfig
Requires: MySQL-python python-sqlite2

%description
A test gateway for web site, game server and the Internet applications

%prep
%setup -q -n %{name}

%build
/usr/bin/python -m compileall usr/bin/

%install
rm -rf $RPM_BUILD_ROOT

mkdir -p $RPM_BUILD_ROOT/

mv usr etc var $RPM_BUILD_ROOT
mv $RPM_BUILD_ROOT/usr/bin/%{name}.pyc $RPM_BUILD_ROOT/usr/bin/%{name}
rm -f $RPM_BUILD_ROOT/usr/bin/%{name}.py*

%clean
rm -rf $RPM_BUILD_ROOT

%pre


%post
/sbin/chkconfig --add %{name}
/sbin/chkconfig --level 345 %{name} on

%postun

%files
   /etc/init.d/%{name}
   /usr/bin/%{name}

%defattr(-,www,www)
%dir
    /var/log/%{name}
    /var/lib/%{name}
%config
   /etc/%{name}/logging.ini
   /etc/%{name}/conf.py

%changelog
* Thu Aug 5 2009 lht 1.0.0.1-rhel5
first release

3 构建
$ rpmbuild -ba --clean mirchgr.spec

然后将生成的rpm和src.rpm拷贝就可以了。

你可能感兴趣的:(应用服务器,mysql,PHP,Web,python)