squid启动脚本

squid启动脚本:

  
  
  
  
  1. #!/bin/bash 
  2.  
  3. # squid         This shell script takes care of starting and stopping 
  4. #               Squid Internet Object Cache 
  5. # chkconfig: - 90 25 
  6. # description: Squid - Internet Object Cache. Internet object caching is \ 
  7. #       a way to store requested Internet objects (i.e., data available \ 
  8. #       via the HTTP, FTP, and gopher protocols) on a system closer to the \ 
  9. #       requesting site than to the source. Web browsers can then use the \ 
  10. #       local Squid cache as a proxy HTTP server, reducing access time as \ 
  11. #       well as bandwidth consumption. 
  12. #Creation_date=2011-10-31 
  13. #pidfile=/usr/local/squid/var/run/squid.pid 
  14. #config=/etc/squid.conf 
  15. #Author=ftqzy 
  16. #Modified=2011-10-31 
  17. #Version=1.0 
  18.   
  19. PATH=/usr/bin:/sbin:/bin:/usr/sbin 
  20. export PATH 
  21.   
  22. # Source function library. 
  23. . /etc/rc.d/init.d/functions 
  24.   
  25. # Source networking configuration. 
  26. . /etc/sysconfig/network 
  27.   
  28. # don't raise an error if the config file is incomplete 
  29. # set defaults instead: 
  30. SQUID_OPTS=${SQUID_OPTS:-"-D"} 
  31. SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20} 
  32. SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100} 
  33.   
  34. squid=/usr/local/squid/sbin/squid 
  35. squid_config=/etc/squid.conf 
  36. squid_pid=/usr/local/squid/var/run/squid.pid 
  37.   
  38. # determine the name of the squid binary 
  39. [ -f $squid ] && prog="squid" 
  40.   
  41. # determine which one is the cache_swap directory 
  42. CACHE_SWAP=`sed -e 's/#.*//g' $squid_config | grep cache_dir |  awk '{ print $3 }'` 
  43.   
  44. [ -z "$CACHE_SWAP" ] && CACHE_SWAP=/cache 
  45.   
  46. RETVAL=0 
  47.   
  48. start() { 
  49.     if [ ! -f $squid_config ]; then 
  50.         echo "Configuration file $squid_config missing" 1>&2 
  51.             exit 6 
  52.         fi 
  53.     if [ -z "$squid" ]; then 
  54.                 echo "Insufficient privilege" 1>&2 
  55.                 exit 4 
  56.         fi 
  57.     for adir in $CACHE_SWAP; do 
  58.         if [ ! -d $adir/00 ]; then 
  59.              echo -n "init_cache_dir $adir... " 
  60.              $squid -z -f $squid_config >> /var/log/squid/cache.log 
  61.         fi 
  62.     done 
  63.     echo -n $"Starting $prog: " 
  64.     $squid $SQUID_OPTS -s -f $squid_config >> /var/log/squid/cache.log 2>&1 
  65.     RETVAL=$? 
  66.     if [ $RETVAL -eq 0 ]; then 
  67.            timeout=0
  68.            while : ; do 
  69.           [ ! -f $squid_pid ] || break 
  70.           if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then 
  71.              RETVAL=1 
  72.              break 
  73.           fi 
  74.           sleep 1  
  75.           timeout=$((timeout+1)) 
  76.            done 
  77.     fi 
  78.     [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog 
  79.     [ $RETVAL -eq 0 ] && echo_success 
  80.     [ $RETVAL -ne 0 ] && echo_failure 
  81.     echo 
  82.     return $RETVAL 
  83.   
  84. stop() { 
  85.     echo -n  $"Stopping $prog: " 
  86.     $squid -k check -f $squid_config >> /var/log/squid/cache.log 2>&1 
  87.     RETVAL=$? 
  88.     if [ $RETVAL -eq 0 ] ; then 
  89.         $squid -k shutdown -f $squid_config & 
  90.         rm -f /var/lock/subsys/$prog 
  91.         timeout=0 
  92.         while : ; do 
  93.             [ -f $squid_pid ] || break 
  94.             if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then 
  95.                 echo 
  96.                 return 1 
  97.             fi 
  98.             sleep 2  
  99.             timeout=$((timeout+2)) 
  100.         done 
  101.         echo_success 
  102.         echo 
  103.     else 
  104.         echo_failure 
  105.         if [ ! -e /var/lock/subsys/$prog ]; then 
  106.             RETVAL=0 
  107.         fi 
  108.         echo 
  109.     fi 
  110.     return $RETVAL 
  111.   
  112. reload() { 
  113.     $squid -k reconfigure -f $squid_config 
  114.     echo -n  $"reload_config $prog: " 
  115.     echo_success 
  116.     echo 
  117.   
  118. restart() { 
  119.     stop 
  120.     sleep 5 
  121.     start 
  122.   
  123. condrestart() { 
  124.     [ -e /var/lock/subsys/squid ] && restart || : 
  125.   
  126. rhstatus() { 
  127.     status $squid && $squid -k check -f $squid_config 
  128.   
  129. probe() { 
  130.     return 0 
  131.   
  132. case "$1" in 
  133. start) 
  134.     start 
  135.     ;; 
  136.   
  137. stop) 
  138.     stop 
  139.     ;; 
  140.   
  141. reload) 
  142.     reload 
  143.     ;; 
  144.   
  145. restart) 
  146.     restart 
  147.     ;; 
  148.   
  149. condrestart) 
  150.     condrestart 
  151.     ;; 
  152.   
  153. status) 
  154.     rhstatus 
  155.     ;; 
  156.   
  157. probe) 
  158.     exit 0 
  159.     ;; 
  160.   
  161. *) 
  162.     echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}" 
  163.     exit 2 
  164. esac 
  165.   
  166. exit $? 

你可能感兴趣的:(职场,squid,休闲)