脚本如下:
#!/bin/bash
# chkconfig: 2345 90 25
# config: /etc/squid.conf
# pidfile:/ /usr/local/squid/var/run/squid.pid
# Description: Squid -Internet Object Cache.
PID="/usr/local/squid/var/run/squid.pid"
CONF="/etc/squid.conf"
CMD="/usr/local/squid/sbin/squid"
case "$1" in
start)
netstat -anpt | grep squid &> /dev/null
if [ $? -eq 0 ]
then
echo "squid is running"
else
echo "正在启动squid. . . "
$CMD
fi
;;
stop)
$CMD -k kill &> /dev/null
rm -rf $PID &> /dev/null
;;
status)
[ -f $PID ] &> /dev/null
if [ $? -eq 0 ]
then
netstat -anpt | grep squid
else
echo"Squid is not running . . ."
fi
;;
restart)
$0 stop &> /dev/null
echo "正在关闭squid . . . "
$0 start &> /dev/null
echo "正在启动squid . . ."
;;
reload)
$CMD -k reconfigure
;;
check)
$CMD -k parse
;;
*)
echo "用法: $0 {start | stop | restart | reload | check | status }"
esac
[root@localhost ~]# chmod +x /etc/init.d/squid
[root@localhost ~]# chkconfig --add squid //添加为系统服务
[root@localhost ~]# chkconfig squid on
这样一来,就可以通过Squid脚本来启动,停止,重启,重载,Squid服务器了,方法是在执行时添加相应的start,stop,restart,reload参数。