{"id":915,"date":"2022-08-30T15:09:18","date_gmt":"2022-08-30T15:09:18","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/varnish-daemon_opts-options-errors-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:09:18","modified_gmt":"2022-08-30T15:09:18","slug":"varnish-daemon_opts-options-errors-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/varnish-daemon_opts-options-errors-collection-of-common-programming-errors\/","title":{"rendered":"Varnish DAEMON_OPTS Options Errors-Collection of common programming errors"},"content":{"rendered":"<p>Even if Jacob will probably never read this, visitors from the future might appreciate what I&#8217;m going to write.<\/p>\n<p>I believe I know what&#8217;s wrong, and it looks like a Debian-specific problem, at least verified on Ubuntu 11.04 and Debian Squeeze.<\/p>\n<p>I traced the execution from my <code>\/etc\/default\/varnish<\/code> that contains the <code>$DAEMON_OPTS<\/code> to the init script. In the init script <code>\/etc\/init.d\/varnish', the<\/code>start_varnishd()` function is:<\/p>\n<pre>\nstart_varnishd() {\n    log_daemon_msg \"Starting $DESC\" \"$NAME\"\n    output=$(\/bin\/tempfile -s.varnish)\n    if start-stop-daemon \\\n        --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \\\n        -P ${PIDFILE} ${DAEMON_OPTS} &gt; ${output} 2&gt;&amp;1; then\n        log_end_msg 0\n    else\n        log_end_msg 1\n        cat $output\n        exit 1\n    fi\n    rm $output\n}\n<\/pre>\n<p>So I modified it to print the full <code>start-stop-daemon<\/code> command line, like:<\/p>\n<pre>\n start_varnishd() {\n    log_daemon_msg \"Starting $DESC\" \"$NAME\"\n    output=$(\/bin\/tempfile -s.varnish)\n+   echo \"start-stop-daemon --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- -P ${PIDFILE} ${DAEMON_OPTS} &gt; ${output} 2&gt;&amp;1\"\n    if start-stop-daemon \\\n        --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \\\n        -P ${PIDFILE} ${DAEMON_OPTS} &gt; ${output} 2&gt;&amp;1; then\n        log_end_msg 0\n<\/pre>\n<p>So I got a command line echoed on STDOUT, and copied-pasted it into my shell. And, surprise! It worked. <strong>WTF?<\/strong><\/p>\n<p>Repeated again to be sure. Yes, it works. Mmh. Could it be another of those bash\/dash corner cases? Let&#8217;s try feeding the start-stop-daemon command line to <code>bash<\/code>, and see how it reacts:<\/p>\n<pre>\nstart_varnishd() {\n    log_daemon_msg \"Starting $DESC\" \"$NAME\"\n    output=$(\/bin\/tempfile -s.varnish)\n    if bash -c \"start-stop-daemon \\\n        --start --quiet --pidfile ${PIDFILE} --exec ${DAEMON} -- \\\n        -P ${PIDFILE} ${DAEMON_OPTS} &gt; ${output} 2&gt;&amp;1\"; then\n        log_end_msg 0\n    else\n        log_end_msg 1\n        cat $output\n        exit 1\n    fi\n    rm $output\n}\n<\/pre>\n<p>Yes, <strong>it works just fine<\/strong>, at least for my case. Here&#8217;s the relevant part of my <code>\/etc\/default\/varnish<\/code>:<\/p>\n<pre>\n...\n## Alternative 2, Configuration with VCL\n#\n# Listen on port 6081, administration on localhost:6082, and forward to\n# one content server selected by the vcl file, based on the request.  Use a 1GB\n# fixed-size cache file.\n#\nDAEMON_OPTS=\"-a :6081 \\\n             -T localhost:6082 \\\n             -f \/etc\/varnish\/geoip-example.vcl \\\n             -S \/etc\/varnish\/secret \\\n             -s malloc,100M \\\n             -p 'cc_command=exec cc -fpic -shared -Wl,-x -L\/usr\/include\/GeoIP.h -lGeoIP -o %o %s'\"\n...\n<\/pre>\n<p>I&#8217;ve seen posts where someone tried to work around this problem by moving the compile command into a separated shell script. Unfortunately that doesn&#8217;t change the fact that <code>start-stop-daemon<\/code> is going to pass the <code>$DAEMON_OPTS<\/code> var through <code>dash<\/code>, and that will result in mangled options.<\/p>\n<p>Would be something along the lines of:<\/p>\n<pre>\n-p 'cc_command=exec \/etc\/varnish\/compile.sh %o %s'\"\n<\/pre>\n<p>And then the <code>compile.sh<\/code> script as:<\/p>\n<pre>\n#!\/bin\/sh\ncc -fpic -shared -Wl,-x -L\/usr\/include\/GeoIP.h -lGeoIP -o $@\n<\/pre>\n<p>but it doesn&#8217;t work, so just patch your init scripts, and you&#8217;re good to go! Hope you can find this information useful.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-09 22:57:52. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>Even if Jacob will probably never read this, visitors from the future might appreciate what I&#8217;m going to write. I believe I know what&#8217;s wrong, and it looks like a Debian-specific problem, at least verified on Ubuntu 11.04 and Debian Squeeze. I traced the execution from my \/etc\/default\/varnish that contains the $DAEMON_OPTS to the init [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-915","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=915"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/915\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}