Skip to content

Instantly share code, notes, and snippets.

@gnanet
Last active September 13, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnanet/80203fcb07cb97abb98d to your computer and use it in GitHub Desktop.
Save gnanet/80203fcb07cb97abb98d to your computer and use it in GitHub Desktop.
Check for abandoned vcl.XXXXXXX.so and _.vsm files
#!/bin/bash
varnish_user=`ps aux | grep varnishd | grep root | grep -o "\-u .* \-g" | awk {' print $2 '}`
varnish_effective_pid=`ps aux | grep varnishd | grep "^${varnish_user}" | awk {' print $2 '}`
varnish_lib=`lsof -p ${varnish_effective_pid} | grep cwd | awk {' print $9 '}`
if [ ! -d "${varnish_lib}" ]; then echo "Missing ${varnish_lib} - maybe located elsewhere?!"; exit 1; fi
while read line
do
fstest=`lsof -p ${varnish_effective_pid} | grep ${varnish_lib} | grep REG | awk {' print $9 '} | sed -e "s#${varnish_lib}/##g" | grep $line`
if [ "$fstest" == "$line" ]
then
echo "$line in use by varnish"
else
echo "mv ${varnish_lib}/${line} ${varnish_lib}/off/"
# uncomment following 2 lines to move unused files away
#if [ ! -d "${varnish_lib}/off/" ]; then mkdir -p ${varnish_lib}/off/; fi
#mv ${varnish_lib}/${line} ${varnish_lib}/off/
fi
done < <(ls -1 -I "*off*" ${varnish_lib})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment