RPM参数详解

1、centos6准备打包环境

执行如下命令安装rpmbuild和rpmdevtools

#yum install rpmbuild
#yum install rpmdevtools

2、下载nginx源代码

#wget http://nginx.org/download/nginx-1.10.2.tar.gz
#cp nginx-1.10.2.tar.gz  /root/rpmbuild/SOURCES

3、编写spec文件

%global nginx_version   1.10.2
%if %{undefined src_base}
%define src_base nginx
%endif
%define src_dir %{src_base}-%{nginx_version}
%define debug_package   %{nil}
%if "%{_arch}" == "ia64"
RPM_OPT_FLAGS=
%endif
%define _prefix  /opt/nginx
Summary:nginx
Name:nginx-soonyo
Version:1.10.2
Release:1%{?dist}
Vendor:test@test.com
License:Share
Group:System Environment/Daemons
Source0:nginx-1.10.2.tar.gz
Prefix:    %{_prefix}
%description
nginx-1.10.2
%prep
%setup -T -a 0 -c -n %{src_dir}
%build
cd %{src_dir}
./configure \
        --prefix=%{_prefix} \
        --user=www \
        --group=www \
        --with-http_stub_status_module \
        --with-http_gzip_static_module \
        --with-http_realip_module \
        --with-http_ssl_module \
        --with-openssl=  \
        --with-stream  \
        --with-stream_ssl_module
make
%install
cd  %{src_dir}
make  install DESTDIR=$RPM_BUILD_ROOT 
install -d $RPM_BUILD_ROOT/etc/rc.d/init.d
cp /root/soft/nginx/nginx  $RPM_BUILD_ROOT/etc/rc.d/init.d
%clean
rm -rf $RPM_BUILD_DIR/%{src_dir}
rm -rf $RPM_BUILD_ROOT
%files
%defattr(-,root,root)
%{_prefix}
/etc/rc.d/init.d/nginx
%config(noreplace)  /opt/nginx/conf/*
%post
groupadd  www 2> /dev/null || true
useradd -M  -d %{_prefix} -s /sbin/nologin \
  -g www www 2> /dev/null || true
chkconfig --add nginx

4、编写启动脚本

#vim /root/soft/nginx/nginx

#!/bin/sh
#
# nginx        Startup script for nginx
#
# chkconfig: - 85 15
# processname: nginx
# config: /opt/nginx/conf/nginx.conf
# pidfile: /opt/nginx/logs/nginx.pid
# description: nginx is an HTTP and reverse proxy server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop nginx
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
nginx=${NGINX-/opt/nginx/sbin/nginx}
prog=`/bin/basename $nginx`
conffile=${CONFFILE-/opt/nginx/conf/nginx.conf}
lockfile=${LOCKFILE-/var/lock/subsys/nginx}
pidfile=${PIDFILE-/opt/nginx/logs/nginx.pid}
SLEEPMSEC=${SLEEPMSEC-200000}
UPGRADEWAITLOOPS=${UPGRADEWAITLOOPS-5}
RETVAL=0
start() {
    echo -n $"Starting $prog: "
    daemon --pidfile=${pidfile} ${nginx} -c ${conffile}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch ${lockfile}
    return $RETVAL
}
stop() {
    echo -n $"Stopping $prog: "
    killproc -p ${pidfile} ${prog}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    killproc -p ${pidfile} ${prog} -HUP
    RETVAL=$?
    echo
}
upgrade() {
    oldbinpidfile=${pidfile}.oldbin
    configtest -q || return
    echo -n $"Starting new master $prog: "
    killproc -p ${pidfile} ${prog} -USR2
    echo
    for i in `/usr/bin/seq $UPGRADEWAITLOOPS`; do
        /bin/usleep $SLEEPMSEC
        if [ -f ${oldbinpidfile} -a -f ${pidfile} ]; then
            echo -n $"Graceful shutdown of old $prog: "
            killproc -p ${oldbinpidfile} ${prog} -QUIT
            RETVAL=$?
            echo
            return
        fi
    done
    echo $"Upgrade failed!"
    RETVAL=1
}
configtest() {
    if [ "$#" -ne 0 ] ; then
        case "$1" in
            -q)
                FLAG=$1
                ;;
            *)
                ;;
        esac
        shift
    fi
    ${nginx} -t -c ${conffile} $FLAG
    RETVAL=$?
    return $RETVAL
}
rh_status() {
    status -p ${pidfile} -b ${nginx} ${nginx}
}
# See how we were called.
case "$1" in
    start)
        rh_status >/dev/null 2>&1 && exit 0
        start
        ;;
    stop)
        stop
        ;;
    status)
        rh_status
        RETVAL=$?
        ;;
    restart)
        configtest -q || exit $RETVAL
        stop
        start
        ;;
    upgrade)
        rh_status >/dev/null 2>&1 || exit 0
        upgrade
        ;;
    condrestart|try-restart)
        if rh_status >/dev/null 2>&1; then
            stop
            start
        fi
        ;;
    force-reload|reload)
        reload
        ;;
    configtest)
        configtest
        ;;
    *)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|upgrade|reload|status|help|configtest}"
        RETVAL=2
esac
exit $RETVAL

5、生成rpm包

#rpmbuild -bb nginx.spec

6、查看rpm包内文件

#rpm -qpl nginx-soonyo-1.10.2-1.el6.x86_64.rpm

/etc/rc.d/init.d/nginx
/opt/nginx
/opt/nginx/conf
/opt/nginx/conf/fastcgi.conf
/opt/nginx/conf/fastcgi.conf.default
/opt/nginx/conf/fastcgi_params
/opt/nginx/conf/fastcgi_params.default
/opt/nginx/conf/koi-utf
/opt/nginx/conf/koi-win
/opt/nginx/conf/mime.types
/opt/nginx/conf/mime.types.default
/opt/nginx/conf/nginx.conf
/opt/nginx/conf/nginx.conf.default
/opt/nginx/conf/scgi_params
/opt/nginx/conf/scgi_params.default
/opt/nginx/conf/uwsgi_params
/opt/nginx/conf/uwsgi_params.default
/opt/nginx/conf/win-utf
/opt/nginx/html
/opt/nginx/html/50x.html
/opt/nginx/html/index.html
/opt/nginx/logs
/opt/nginx/sbin
/opt/nginx/sbin/nginx
Last modification:February 21st, 2019 at 02:16 pm
If you think my article is useful to you, please feel free to appreciate