现在很多大公司都在自己定制公司自己的rpm包,比如apache/nginx/php等常用的包,并且把这些包加到自己的yum里面,这样业务部门要是有这些rpm的时候,只要yum install就可以了。大家都知道制作rpm最核心的地方就是spec文件了,在这里跟大家共享一下我写的一个apche的spec文件。里面有我自己定义的一些东西,保证能在线上服务器上面使用。
%define _topdir /ziji/Centos5.4/
%define _specdir %{_topdir}/SPEC
%define _rpmdir %{_topdir}/
%define _srcrpmdir %{_topdir}/SRPMS
%define _sourcedir %{_topdir}/SOURCES
%define _tmppath %{_topdir}/tmp
%define _builddir %{_topdir}/BUILD
%define _prefix /usr/local/apache2
%define _docroot /usr/local/apache2/htdocs
#BuildArch: noarch
Summary: ziji custom apache package
Name: ziji-ops-httpd
Version: 2.2.22
Release: 1_ziji.el5
License: GPL
Group: Applications/web
Source: httpd-2.2.22.tar.gz
Source1: httpd-2.2.22_config.tar.gz
Source2: httpd.init
Source3: state.sh
Source4: httpd-2.2.22_modules.tar.gz
Source5: httpd_ssl_module.tar.gz
Prereq: /sbin/chkconfig, /bin/sed, mailcap, grep, textutils
Prereq: /usr/sbin/useradd, initscripts >= 5.20, /bin/sh, zlib-devel >= 1.2.0,
#Requires: openssl , openssl-devel
URL: http://suibian
Vendor: gehailong
Packager: gehailong <391097@360.cn>
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Autoreq: no
%define debug_package %{nil}
%description
Ziji custom apache server
%prep
%setup -q -n httpd-%{version}
%build
CFLAGS="-DNO_LINGCLOSE" ./configure \
--prefix=%{_prefix} \
--enable-so \
--with-mpm=prefork \
--enable-rewrite \
--disable-userdir \
--disable-autoindex \
--enable-logio \
--enable-deflate \
--with-included-apr \
--enable-expires \
--enable-headers \
--enable-ssl \
--enable-mods-shared=most \
make %{?_smp_mflags}
%install
[ ${RPM_BUILD_ROOT} != "/" ] && rm -rf ${RPM_BUILD_ROOT}
install -d ${RPM_BUILD_ROOT}/%{_prefix}
install -d ${RPM_BUILD_ROOT}%{_sysconfdir}/init.d
install -d ${RPM_BUILD_ROOT}/usr/local/bin
# install log rotation stuff
mkdir -p $RPM_BUILD_ROOT/etc/logrotate.d
install -m644 ./build/rpm/httpd.logrotate \
$RPM_BUILD_ROOT/etc/logrotate.d/httpd
#vhost documentroot
[ -f "${RPM_BUILD_ROOT}%{_docroot}" ] && rm -rf ${RPM_BUILD_ROOT}%{_docroot}
mkdir -p ${RPM_BUILD_ROOT}%{_docroot}
make DESTDIR=${RPM_BUILD_ROOT} install
%{__install} -m 0755 %{SOURCE2} ${RPM_BUILD_ROOT}%{_sysconfdir}/init.d/httpd
%{__install} -m 0755 %{SOURCE3} ${RPM_BUILD_ROOT}/usr/local/bin/state
%{__rm} -rf ${RPM_BUILD_ROOT}%{_prefix}/conf
%{__rm} -rf ${RPM_BUILD_ROOT}%{_prefix}/htdocs/*
%{__tar} zxvf %{SOURCE1} -C ${RPM_BUILD_ROOT}%{_prefix}/
%{__tar} zxvf %{SOURCE4} -C ${RPM_BUILD_ROOT}%{_prefix}/modules/
mkdir -p ${RPM_BUILD_ROOT}%{_usr}/lib64
%{__tar} zxvf %{SOURCE5} -C ${RPM_BUILD_ROOT}%{_usr}/lib64
%files
%defattr(-,root,root,755)
%attr(0500,root,root) %config %{_sysconfdir}/init.d/httpd
%attr(0500,root,root) %config %{_sysconfdir}/logrotate.d/httpd
%{_usr}
%exclude %dir %{_usr}
%exclude %dir %{_usr}/lib64
%exclude %dir %{_usr}/local/bin
%exclude %dir %{_usr}/local
%pre
if [ "$1" -eq "1" ] ;then
if rpm -qa | grep %{name} > /dev/null ;then
echo "%{name} is already installed"
exit 1
else
/usr/sbin/useradd -c "apache" -u 48 \
-s /sbin/nologin -r -d %{_docroot} apache 2> /dev/null || :
fi
fi
%post
if [ "$1" -eq "1" ];then
/sbin/chkconfig --add httpd
/sbin/chkconfig --level 35 httpd on
chown -R apache:apache %{_prefix} %{_docroot}
elif [ "$1" -eq "2" ];then
if [ -f /var/lock/subsys/httpd ]; then
%{_sysconfdir}/init.d/httpd restart
fi
fi
%preun
if [ "$1" -eq "0" ];then
%{_sysconfdir}/init.d/httpd stop > /dev/null 2>&1
/sbin/chkconfig --del httpd
fi
%postun
/usr/sbin/userdel apache
%clean
[ "$RPM_BUILD_ROOT" != "/" ] && %{__rm} -rf $RPM_BUILD_ROOT
本文转自 gehailong 51CTO博客,原文链接:http://blog.51cto.com/gehailong/909691,如需转载请自行联系原作者