Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list index our of range #3

Open
Fil opened this issue Mar 26, 2015 · 6 comments
Open

list index our of range #3

Fil opened this issue Mar 26, 2015 · 6 comments

Comments

@Fil
Copy link
Contributor

Fil commented Mar 26, 2015

once I apply #2 I don't get past this error:

python varnishtuner.py -o /etc/init.d/varnish
Traceback (most recent call last):
  File "varnishtuner.py", line 541, in <module>
    VC = VarnishConfig(options_file)
  File "varnishtuner.py", line 183, in __init__
    self.memorySetting = self.getMemorySetting(self.all_options_text)
  File "varnishtuner.py", line 256, in getMemorySetting
    mem_str = i.split(',')[2].strip('"')
IndexError: list index out of range
@unixy
Copy link
Owner

unixy commented Mar 26, 2015

Thanks for the patch. What does your DAEMON_OPTS line look like in /etc/init.d/varnish?

@Fil
Copy link
Contributor Author

Fil commented Mar 26, 2015

DAEMON_OPTS=${DAEMON_OPTS:--b localhost}

but a few lines before there is this:

if [ -f /etc/default/varnish ] ; then
        . /etc/default/varnish
fi

in that file (/etc/default/varnish) I have:

DAEMON_OPTS="-a :80 \
             -t 2592000 \
             -T localhost:6082 \
             -f /etc/varnish/vspip.vcl \
             -S /etc/varnish/secret \
             -w 200,4000 \
             -p thread_pools=4 -p listen_depth=4096 \
             -p thread_pool_add_delay=2 -p session_linger=50/100/150 \
             -p lru_interval=20 -h classic,500009 \
             -s malloc,2G \
             -s file,/var/lib/varnish/$INSTANCE/varnish_storage.bin,2G"

however I get the same error if I do python varnishtuner.py -o /etc/default/varnish

@unixy
Copy link
Owner

unixy commented Mar 31, 2015

The line breaks you have are confusing the script. It expects the DAEMON_OPTS line to be a continuous one. So I need a fix for this and a clean one hopefully. There's also the fact that you're running on two storage types at the same time. That will also need to be worked around.

@ArvindTrees
Copy link

Getting the following:
File "varnishtuner.py", line 541, in
VC = VarnishConfig(options_file)
File "varnishtuner.py", line 184, in init
self.possibleMemUsage = self.getPossibleMemoryUsage()
File "varnishtuner.py", line 273, in getPossibleMemoryUsage
return float(self.getMemorySetting(self.all_options_text)) * 1.10
TypeError: float() argument must be a string or a number

with a varnish config file contents of:
DAEMON_OPTS="-a 127.0.0.1:6082 -f /etc/varnish/default.vcl -T 127.0.0.1:80 -t 120 -w 50,1000,120 -u varnish -g varnish -S /etc/varnish/secret -s malloc,1G"

@ArvindTrees
Copy link

Looks like in my situation had to change mem_str = i.split(',')[2].strip('"') to mem_str = i.split(',')[4].strip('"') because of where I put the memory option in my options string. Perhaps in the future it would be better to just detect the "-s" memory flag and find it from there.

@Gribnif
Copy link

Gribnif commented Jul 18, 2016

Note also that even if one goes though the trouble of putting all of DAEMON_OPTS onto one line, the script will still fail of there is a comment line containing #DAEMON_OPTS. It will also fail if some other parameter, like "-w 50,1000,120", contains commas.

There are reasons why people use prewritten libraries to parse things like config files. It avoids exactly this sort of problem. Other people have already figured out all of the possible cases that can trip you up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants