rpmbuild线上实战

最近部门忙着系统整改,所有服务器需要重装应用,为了提高效率,使用rpmbuild
小试牛刀了一把,废话不说直接贴spec配置:
++++++++++++++++++++++START-spec+++++++++++++++++++++++++++
# online rpmbulid for total_hulu

Name:             total_hulu
Version:          2015.12.09
Release:          01%{?dist}
Summary:          program for hulu
Group:            Applications/File
License:          BSD
URL:              http://www.youyuan.com/
Source0:          %{name}-%{version}.tar.gz
Source1:          hulu_root_crontab
Source2:          hulu_hosts
Source3:          hulu_rc.local
Source4:          hulu_profile
BuildRoot:        %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)

#BuildRequires:    jdk >= 1.7
ExcludeArch:      ppc64

#Requires(post):   /usr/bin/svn
Requires(post):   /bin/bash
#Requires(post):   /bin/rpm
#Requires(post):   /bin/su
Requires(postun): /bin/rm

%description
autoinstall for hulu Platform

%prep
%setup -q

%install
%{__mkdir_p} %{buildroot}/www/
%{__mkdir_p} %{buildroot}%{_usr}/local/resin
%{__cp} -r ${RPM_BUILD_DIR}/%{name}-%{version}/* %{buildroot}/www/.

###基础服务直接全部拷贝
#copy basic environment
install -p -D -m 644 %{SOURCE1} %{buildroot}%{_var}/spool/cron/root
install -p -D -m 644 %{SOURCE2} %{buildroot}%{_sysconfdir}/hosts
install -p -D -m 644 %{SOURCE3} %{buildroot}%{_sysconfdir}/rc.d/rc.local
install -p -D -m 644 %{SOURCE4} %{buildroot}%{_sysconfdir}/profile

%clean
rm -fr %{buildroot}

%post
###/usr/local/resin 也一并部署了
%{__cp} -rp /share/yunwei/project/fast_op/hulu_resin/* /usr/local/resin/.
###copy svn 认证
%{__cp} -rp /share/yunwei/project/fast_op/.subversion /root/.
###rpm安装完之后,直接初始化运行脚本,启动服务
bash /share/yunwei/project/fast_op/hulu_install_per_01.sh


%postun
###rpm 卸载后直接清理目录
if [ $1 = 0 ]; then
   /bin/rm -rf /www/youyuan.com.1
   /bin/rm -rf /www/youyuan.com.android
   /bin/rm -rf /usr/local/resin
fi

%files
%defattr(-,www,www)
/www
%dir /usr/local/resin
%attr(0755, root, root) /var/spool/cron/root
%attr(0755, root, root) /etc/hosts
%attr(0755, root, root) /etc/profile
%attr(0755, root, root) /etc/rc.d/rc.local

%changelog
* Fri Dec 09 2015 yanliang wang <[email protected]> -2015.12.09
- hulu rpmbuild

++++++++++++++++++++++END-spec+++++++++++++++++++++++++++

rpmbuild打包:
rpmbuild  -ba hulu.spec

一键安装应用:
 pkill java ; rpm -Uvh  --force --replacefiles --allfiles total_hulu-
 2015.12.14-01.el6.x86_64.rpm jdk-xxx.rpm 

 命令执行完后: crontab,rc.local,profile,hosts文件,业务resin服务全部完成并启动。
 整个业务部署20s!


你可能感兴趣的:(rpmbuild线上实战)