Syntax for piping varnish logs to rotatelogs

Posted by jetboy on Server Fault See other posts from Server Fault or by jetboy
Published on 2012-06-25T21:41:19Z Indexed on 2012/06/26 21:18 UTC
Read the original article Hit count: 245

Filed under:
|
|
|

Ubuntu 12.04 Server x64, Varnish 3.0.2

I'm trying to pipe varnishncsa's logs through Apache's rotatelogs, and running from the shell, things work fine:

sudo varnishncsa -a -P /var/run/varnishncsa/varnishncsa.pid |/usr/sbin/rotatelogs /var/log/varnish/varnish.log.%Y%m%d%H 3600

creates a new logfile in /var/log/varnish, with rotation every hour (3600 seconds). However, I'm struggling to get things working the same way inside /etc/init.d/varnishncsa:

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME/$NAME.pid
LOGFILE=/var/log/varnish/varnishncsa.log
USER=varnishlog

DAEMON_OPTS="-a -P ${PIDFILE}"
DAEMON_PIPE="|/usr/sbin/rotatelogs /var/log/varnish/varnish.log.%Y%m%d%H 3600"

...

start_varnishncsa() {
    output=$(/bin/tempfile -s.varnish)
    log_daemon_msg "Starting $DESC" "$NAME"
    create_pid_directory
    if start-stop-daemon --start --verbose --pidfile ${PIDFILE} \
        --chuid $USER --exec ${DAEMON} -- ${DAEMON_OPTS} \
        > ${output} 2>&1; then
        log_end_msg 0
    else
        log_end_msg 1
        cat $output
        exit 1
    fi
    rm $output
}

Where should I put DAEMON_PIPE in the above code? I've tried at the end of:

if start-stop-daemon --start --verbose --pidfile ${PIDFILE}

which is where additional command line parameters usually go, but it isn't creating a logfile.

© Server Fault or respective owner

Related posts about apache2

Related posts about shell