Last active
September 13, 2015 22:19
-
-
Save gnanet/80203fcb07cb97abb98d to your computer and use it in GitHub Desktop.
Check for abandoned vcl.XXXXXXX.so and _.vsm files
This file contains 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
#!/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