在做软件包管理时,如果把常用的包做成rpm的形式,然后集成到自己的yum源中,并配合puppet的package资源,可以很方便的进行自动化的操作。

附一个简单spec文件,下载下来改改就可以使用:

%define src_version             Vipshop-Webcdn-Tengine-1.0.0%define release                 1Name:           Vipshop-Webcdn-TengineSummary:        This is for Vipshop WEB CDN Nginx and Hash Cache server.Group:          System Environment/DaemonsVersion:        1.0.0Release:        1#Distribution:  RHEL 5License:        Copyright 2011 Vipshop Inc.Source:                 Vipshop-Webcdn-Tengine-1.0.0-1.tar.gz#Source1:               nginx_upstream_hash-0.3.1.tar.gzURL:            http://www.vipshop.comPackager:       EricNiVendor:         Vipshop Inc.Provides:       Vipshop Inc.BuildRequires:  gcc-c++ libtoolConflicts:              httpdRequires:       pcre,pcre-devel,zlib-devel%descriptionThis is CDN Cache Service pakeage , and it only distributed in Vipshop Servers .%preptest -d /usr/local/nginx && rm -rf /usr/local/nginx[ `cat /etc/passwd|grep apps|wc -l` -eq 0 ] && useradd apps%setup -n %{name}-%{version}-%{release}#%setup  -T -D -b 1 -n nginx_upstream_hash-0.3.1%buildcd ../Vipshop-Webcdn-Tengine-1.0.0-1export NGINX_HOME=/usr/local/nginxexport CFLAGS="-O6 -mtune=core2 -march=x86-64 -falign-loops=4 -falign-jumps=4 -falign-functions=4"# Building Nginx./configure --prefix=${NGINX_HOME}  --with-http_stub_status_module --without-http_memcached_module  --without-http_empty_gif_module   --without-http_auth_basic_module --without-http_map_module   --without-http_browser_module  --with-http_upstream_check_module --with-http_concat_module --dso-path=/usr/local/nginx/dso  --with-http_limit_req_module=shared   --with-http_limit_conn_module=sharedmakemake installcat > ${NGINX_HOME}/conf/nginx.conf << "EOF"user  apps apps;worker_processes 6;error_log  /log/nginx/nginx_error.log  crit;pid        /usr/local/nginx/logs/nginx.pid;worker_rlimit_nofile 307200;events{    use epoll;    worker_connections 51200;}http{    include       mime.types;    default_type  application/octet-stream;    log_format access   '$remote_addr $host $remote_user [$time_local] "$request" '                        '$status $body_bytes_sent "$http_referer" '                        '"$http_user_agent" "$http_x_forwarded_for" "$upstream_response_time" "$upstream_addr" "$upstream_status" "$request_time"';    access_log /log/nginx/access.log access;          server_names_hash_bucket_size 128;    client_header_buffer_size 32k;    large_client_header_buffers 4 32k;           sendfile on;    keepalive_timeout 30;    tcp_nodelay on;    gzip on;    gzip_http_version 1.1;    gzip_comp_level 6;    gzip_vary on;    gzip_proxied any;    gzip_types text/plain text/css text/xml application/x-javascript  application/xml application/xml+rss text/javascript;    gzip_min_length 1100;    gzip_buffers 8 16k;    gzip_disable "MSIE [1-6]\.(?!.*SV1)";    proxy_redirect off;    proxy_set_header Host $host;    proxy_set_header X-Real-IP $remote_addr;    client_max_body_size 0m;    client_body_buffer_size 128k;    proxy_connect_timeout 5;    proxy_send_timeout 5;    proxy_read_timeout 90;    proxy_buffer_size 4k;    proxy_buffers 4 32k;    proxy_busy_buffers_size 64k;    proxy_temp_file_write_size 64k;    #client_header_timeout  3m;    #client_body_timeout    3m;    #send_timeout           3m;    proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;include default.vhosts.conf;include vhosts/*.conf;}EOFcat > ${NGINX_HOME}/conf/default.vhosts.conf << "EOF"upstream  default.vhosts  {        server   127.0.0.1:8081 weight=1 max_fails=2 fail_timeout=5s;        server   webcdnbackup:8081 backup;}upstream  default.p_w_picpath.cache  {        server   127.0.0.1:8080 weight=1 max_fails=2 fail_timeout=5s;        server   webcdnbackup:8080 backup;}server {        listen  80 default;        server_name _;        proxy_set_header Host $host;        proxy_set_header X-Forwarded-For  $remote_addr;        location / {                if ($uri ~ \.(jpg|jpeg|bmp|gif|png|zip|exe|txt|mp40drag|js|css|swf|mp3)$) {                        proxy_pass http://default.p_w_picpath.cache;                }                if ( $request_uri ~* ^(.*)(\?|\&)rcc.*$ )  {                        proxy_pass http://default.vhosts$1;                }                proxy_pass http://default.vhosts;        }}EOFcat > /etc/init.d/nginx << "EOF"#!/bin/sh# Last Modified: Sep 08 2010 Wen# nginx - this script starts and stops the nginx daemon## chkconfig:   - 85 15# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \#               proxy and IMAP/POP3 proxy server# processname: nginx# config:      /etc/nginx/nginx.conf# config:      /etc/sysconfig/nginx# pidfile:     /var/run/nginx.pid   # Source function library.. /etc/rc.d/init.d/functions   # Source networking configuration.. /etc/sysconfig/network   # Check that networking is up.[ "$NETWORKING" = "no" ] && exit 0   nginx="/usr/local/nginx/sbin/nginx"prog=$(basename $nginx)   NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"   [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx   lockfile=/var/lock/subsys/nginx   make_dirs() {   # make required directories   user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`   options=`$nginx -V 2>&1 | grep 'configure arguments:'`   for opt in $options; do       if [ `echo $opt | grep '.*-temp-path'` ]; then           value=`echo $opt | cut -d "=" -f 2`           if [ ! -d "$value" ]; then               # echo "creating" $value               mkdir -p $value && chown -R $user $value           fi       fi   done}   start() {    [ -x $nginx ] || exit 5    [ -f $NGINX_CONF_FILE ] || exit 6    make_dirs    echo -n $"Starting $prog: "    daemon $nginx -c $NGINX_CONF_FILE    retval=$?    echo    [ $retval -eq 0 ] && touch $lockfile    return $retval}   stop() {    echo -n $"Stopping $prog: "    killproc $prog -QUIT    retval=$?    echo    [ $retval -eq 0 ] && rm -f $lockfile    return $retval}   restart() {    configtest || return $?    stop    sleep 1    start}   reload() {    configtest || return $?    echo -n $"Reloading $prog: "    killproc $nginx -HUP    RETVAL=$?    echo}   force_reload() {    restart}   configtest() {  $nginx -t -c $NGINX_CONF_FILE}   rh_status() {    status $prog}   rh_status_q() {    rh_status >/dev/null 2>&1}   case "$1" in    start)        rh_status_q && exit 0        $1        ;;    stop)        rh_status_q || exit 0        $1        ;;    restart|configtest)        $1        ;;    reload)        rh_status_q || exit 7        $1        ;;    force-reload)        force_reload        ;;    status)        rh_status        ;;    condrestart|try-restart)        rh_status_q || exit 0            ;;    *)        echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"        exit 2esacEOFchmod 755 /etc/init.d/nginxmkdir -p /log/nginx/bakmkdir -p /log/nginx/error_bakmkdir -p /log/nginx/oldmkdir -p /usr/local/nginx/conf/vhostsmkdir -p /usr/local/nginx/dso%preif [ ! `grep apps /etc/passwd` ];thenuseradd  -M appsfi%postchkconfig --add nginxchkconfig nginx on%cleanrm -rf /usr/local/nginx%files/etc/init.d/nginx/usr/local/nginx/%doc%changelog* Thu May 8 2013 Ericni 
.- Create SPEC file.