Last active
December 14, 2015 13:38
-
-
Save garlandkr/5094637 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I've got this script: | |
NAME=varnishncsa | |
DAEMON=/usr/bin/$NAME | |
DAEMON_OPTS="-a -f -w ${LOGFILE} -D -P ${PIDFILE}" | |
# Include defaults if available | |
if [ -f /etc/default/$NAME ] ; then | |
. /etc/default/$NAME | |
fi | |
# If unset, or set to "0" or "no", exit | |
if [ -z "${VARNISHNCSA_ENABLED}" ] || \ | |
[ "${VARNISHNCSA_ENABLED}" = "0" ] || \ | |
[ "${VARNISHNCSA_ENABLED}" = "no" ]; then | |
exit 0; | |
fi | |
test -x "$DAEMON" || exit 0 | |
start-stop-daemon --start --exec $DAEMON -- $DAEMON_OPTS | |
DAEMON_OPTS in /etc/default/daemon_opts contains: | |
DAEMON_OPTS="-F \"{ \\\"remote_addr\\\": \\\"%h\\\",\\\"remote_user\\\": \\\"%u\\\",\\\"x_forwarded_for\\\": \\\"%{X-Forwarded-For}i\\\",\\\"hit_miss\\\": \\\"%{Varnish:hitmiss}x\\\",\\\"body_bytes_sent\\\": \\\"%b\\\",\\\"request_time\\\": \\\"%{Varnish:time_firstbyte}x\\\",\\\"status\\\": \\\"%s\\\",\\\"request\\\": \\\"%r\\\",\\\"host\\\": \\\"%{host}i\\\",\\\"request_method\\\": \\\"%m\\\",\\\"time_first_byte\\\": \\\"%{Varnish:time_firstbyte}x\\\",\\\"handling\\\": \\\"%{Varnish:handling}x\\\",\\\"http_referrer\\\": \\\"%{Referrer}i\\\",\\\"http_user_agent\\\": \\\"%{User-agent}i\\\"}\"" | |
The ps tree 'ps auxww | grep -i ncsa' shows this: | |
/usr/bin/varnishncsa -F "{ \"remote_addr\": \"%h\",\"remote_user\": \"%u\",\"x_forwarded_for\": \"%{X-Forwarded-For}i\",\"hit_miss\": \"%{Varnish:hitmiss}x\",\"body_bytes_sent\": \"%b\",\"request_time\": \"%{Varnish:time_firstbyte}x\",\"status\": \"%s\",\"request\": \"%r\",\"host\": \"%{host}i\",\"request_method\": \"%m\",\"time_first_byte\": \"%{Varnish:time_firstbyte}x\",\"handling\": \"%{Varnish:handling}x\",\"http_referrer\": \"%{Referrer}i\",\"http_user_agent\": \"%{User-agent}i\"}" | |
Which should work for this application, but only outputs "{ | |
When the command is run directly in the bash terminal it looks like this: | |
root@myserver:~# /usr/bin/varnishncsa -F "{ \"remote_addr\": \"%h\",\"remote_user\": \"%u\",\"x_forwarded_for\": \"%{X-Forwarded-For}i\",\"hit_miss\": \"%{Varnish:hitmiss}x\",\"body_bytes_sent\": \"%b\",\"request_time\": \"%{Varnish:time_firstbyte}x\",\"status\": \"%s\",\"request\": \"%r\",\"host\": \"%{host}i\",\"request_method\": \"%m\",\"time_first_byte\": \"%{Varnish:time_firstbyte}x\",\"handling\": \"%{Varnish:handling}x\",\"http_referrer\": \"%{Referrer}i\",\"http_user_agent\": \"%{User-agent}i\"}" | |
{ "remote_addr": "x.x.x.x","remote_user": "-","x_forwarded_for": "x.x.x.x","hit_miss": "hit","body_bytes_sent": "5105","request_time": "0.000234365","status": "200","request": "GET some_website_image.jpg HTTP/1.1","host": "myhost.com","request_method": "GET","time_first_byte": "0.000234365","handling": "hit","http_referrer": "-","http_user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/536.26.17 (KHTML, like Gecko) Version/6.0.2 Safari/536.26.17"} | |
As you can see the above example when used directly on the commandline works just fine. It is only when I put it inside a wrapper that things go to hell for me. | |
GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment