Packaging Varnish for Slackware

It’s always necessary and a good manner to use the system package management tools when installing software into the system, rather than just issuing “./configure && make && make install” which would lead the file system to be knacker’s yard.

Okay, maybe you need to read about slackware package howtos before continuing reading ;)

The related files are as below. You’d better use the newest ones in my SlackBuild directory.

slack-desc

varnish: VARNISH - a high-performance HTTP accelerator
varnish:
varnish: Varnish is targeted primarily at the FreeBSD 6 and
varnish: Linux 2.6 platforms, and will take full advantage
varnish: of the virtual memory system and advanced I/O
varnish: features offered by these operating systems.
varnish:
varnish: Homepage: http://varnish.projects.linpro.no/
varnish:
varnish:

rc.varnishd

#!/bin/sh
# Written to start/stop/restart varnishd.
# by Cowyn Li <cowynli_#_gmail.com>
#

VARNISH_VCL_CONF=/etc/varnish/default.vcl
VARNISH_PIDFILE=/var/run/varnish.pid
VARNISH_LOCKFILE=/var/lock/subsys/varnish
VARNISH_DAEMON=/usr/sbin/varnishd
VARNISH_PARAM="-p thread_pool_max=1500 \
                                -p thread_pools=5 \
                                -p listen_depth=512 \
                                -p client_http11=off"

VARNISH_LOG_PIDFILE=/var/run/varnishlog.pid
VARNISH_LOG_LOCKFILE=/var/lock/subsys/varnishlog
VARNISH_LOG_DAEMON=/usr/bin/varnishlog
LOGFILE=/var/log/varnish.log
VARNISH_LOG_OPTS="-a -w ${LOGFILE} \
                                      -D -P ${VARNISH_LOG_PIDFILE}"

# Default address and port to bind to
# Blank address means all IPv4 and IPv6 interfaces, otherwise specify
# a host name, an IPv4 dotted quad, or an IPv6 address in brackets.
VARNISH_LISTEN_ADDRESS=
VARNISH_LISTEN_PORT=80

# Telnet admin interface listen address and port
VARNISH_ADMIN_LISTEN_ADDRESS=127.0.0.1
VARNISH_ADMIN_LISTEN_PORT=81

# The minimum number of worker threads to start
VARNISH_MIN_THREADS=1

# The Maximum number of worker threads to start
VARNISH_MAX_THREADS=100

# Idle timeout for worker threads
VARNISH_THREAD_TIMEOUT=120

# Cache file location
VARNISH_STORAGE_FILE=/var/lib/varnish_storage.bin

# Cache file size: in bytes, optionally using k / M / G / T suffix,
# or in percentage of available disk space using the % suffix.
VARNISH_STORAGE_SIZE=1G

# Backend storage specification
VARNISH_STORAGE="file,${VARNISH_STORAGE_FILE},\
                                    ${VARNISH_STORAGE_SIZE}"

# Default TTL used when the backend does not specify one
VARNISH_TTL=120

# VARNISH_DAEMON_OPTS is used by the init script.
# If you add or remove options, make sure you
# update this section, too.
VARNISH_DAEMON_OPTS="\
-a ${VARNISH_LISTEN_ADDRESS}:\
     ${VARNISH_LISTEN_PORT} \
-f ${VARNISH_VCL_CONF} \
-T ${VARNISH_ADMIN_LISTEN_ADDRESS}:\
     ${VARNISH_ADMIN_LISTEN_PORT} \
-t ${VARNISH_TTL} \
-w ${VARNISH_MIN_THREADS},\
     ${VARNISH_MAX_THREADS},\
     ${VARNISH_THREAD_TIMEOUT} \
-u nobody -g nobody \
-P ${VARNISH_PIDFILE} \
-s ${VARNISH_STORAGE}"

case "$1" in
'start')
        echo -n "Starting varnish daemon..."
        $VARNISH_DAEMON \
                $VARNISH_DAEMON_OPTS \
                $VARNISH_PARAM > /dev/null 2>&1
        $VARNISH_LOG_DAEMON $VARNISH_LOG_OPTS
        touch $VARNISH_LOCKFILE $VARNISH_LOG_LOCKFILE
        echo
        ;;
'stop')
        echo -n "Stopping varnish daemon..."
        kill -9 `cat $VARNISH_PIDFILE`
        kill -9 `cat $VARNISH_LOG_PIDFILE`
        rm -f $VARNISH_PIDFILE $VARNISH_LOG_PIDFILE \
                  $VARNISH_LOCKFILE $VARNISH_LOG_LOCKFILE
        killall varnishd 2> /dev/null
        echo
        ;;
'restart')
        $0 stop
        sleep 1
        $0 start
        ;;
*)
        echo "usage $0 start|stop|restart"
        exit 1
esac

exit 0

varnish.SlackBuild

#!/bin/sh
# Build/install varnish the way Slackware's binary package is made:
# Written by Cowyn Li <cowynli_#_gmail.com>

# Set initial variables:
PRGNAM=varnish
VERSION=1.1.2
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

DOCUMENTATION="ChangeLog LICENSE INSTALL README"

if [ "$ARCH" = "i386" ]; then
  SLKCFLAGS="-O2 -march=i386 -mcpu=i686"
elif [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
fi

set -e

rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $PRGNAM-$VERSION
tar -xvf $CWD/$PRGNAM-$VERSION.tar.gz
cd $PRGNAM-$VERSION
chown -R root:root .
chmod -R u+w,go+r-w,a-s .

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
./configure \
  --prefix=/usr \
  --sysconfdir=/etc/varnish/ \
  --localstatedir=/var \
  --mandir=/usr/man

make -j3 || exit 1
make install DESTDIR=$PKG || exit 1

mkdir -p $PKG/etc/{varnish,rc.d} $PKG/usr/man
cat $TMP/$PRGNAM-$VERSION/etc/default.vcl > $PKG/etc/default.vcl.new
cat $TMP/$PRGNAM-$VERSION/etc/zope-plone.vcl > $PKG/etc/zope-plone.vcl.new
cat $CWD/rc.varnishd > $PKG/etc/rc.d/rc.varnishd.new

# Strip everything for good measure:
( cd $PKG
  find . | xargs file | grep "executable" | grep ELF |\
        cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
  find . | xargs file | grep "shared object" | grep ELF |\
        cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null
)

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a $DOCUMENTATION $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > \
        $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

( cd $PKG/usr/man
  find . -type f -exec gzip -9 {} \;
  for i in $( find . -type l ) ; do ln -s $( readlink $i ).gz $i.gz ; rm $i ; done
)

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh

cd $PKG
/sbin/makepkg -l y -c n \
        $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz

Tarball download
Download a tarball including the three files above, but without the varnish source code.

Enjoy (-:

Printed from: http://dotimes.com/iscale/2007/12/packaging-varnish-for-slackware.html .
© Cowyn Li 2010.

1 Comment   »

  1. cowyn says:

    I submitted this packaging script to slackbuilds.org which has been approved ;-)

RSS feed for comments on this post , TrackBack URI

Leave a Comment