I have written a simple python script to check if squid works normally
/scripts/proxychecker
#!/usr/bin/python
import urllib2
import sys, os, time
import socket
socket.setdefaulttimeout(5)
proxy_support = urllib2.ProxyHandler({'http': 'http://127.0.0.1:3128/'})
opener = urllib2.build_opener(proxy_support)
urllib2.install_opener(opener)
try:
response = urllib2.urlopen('http://python.org/')
html = response.read()
except:
#os.system("/etc/init.d/squid3 stop");
#os.system("/etc/init.d/squid3 start");
os.system("/etc/init.d/squid3 restart");
#os.system("service squid3 restart");
I shutdown squid, and manually executed this script "/scripts/proxychecker ", it did bring up squid but if I add this script to cron job: */1 * * * * /scripts/proxychecker >/root/debug.txt
it did not work and from /root/debug.txt it said "Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the start(8) utility, e.g. start squid3"
I do not think this is the reason why squid not be brought up
because I have changed command as bellows , and still did not work
#os.system("/etc/init.d/squid3 stop");
#os.system("/etc/init.d/squid3 start");
os.system("/etc/init.d/squid3 restart");
#os.system("service squid3 restart");
it is a strange problem
also cron is created by root and this script also executed by root, permission should not be the reason
Use restart squid
instead of service squid restart
.