squid源码安装的服务启动脚本

  
  
  
  
  1. #!/bin/bash  
  2. # squid     This shell script takes care of starting and stopping  
  3. #       Squid Internet Object Cache  
  4. #  
  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. # pidfile: /var/run/squid.pid  
  13. # config: /etc/squid/squid.conf  
  14.  
  15. PATH=/usr/bin:/sbin:/bin:/usr/sbin  
  16. export PATH  
  17.  
  18. # Source function library.  
  19. . /etc/rc.d/init.d/functions  
  20.  
  21. # Source networking configuration.  
  22. . /etc/sysconfig/network  
  23.  
  24. # don't raise an error if the config file is incomplete  
  25. # set defaults instead:  
  26. SQUID_OPTS=${SQUID_OPTS:-"-D"}  
  27. SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}  
  28. SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}  
  29.  
  30. # determine the name of the squid binary  
  31. [ -f /usr/local/squid/sbin/squid ] && SQUID=/usr/local/squid/sbin/squid && SQUID_id=squid 
  32.  
  33. prog="$SQUID" 
  34.  
  35. # determine which one is the cache_swap directory  
  36. CACHE_SWAP=`sed -e 's/#.*//g' /usr/local/squid/etc/squid.conf | \  
  37.     grep cache_dir |  awk '{ print $3 }'`  
  38. [ -z "$CACHE_SWAP" ] && CACHE_SWAP=/usr/local/squid/var/cache  
  39.  
  40. RETVAL=0 
  41.  
  42. start() {  
  43.         #check if the squid conf file is present  
  44.         if [ ! -f /usr/local/squid/etc/squid.conf ]; then  
  45.             echo "Configuration file /usr/local/squid/etc/squid.conf missing" 1>&2  
  46.             exit 6  
  47.         fi  
  48.         . /etc/sysconfig/squid  
  49.  
  50.         # don't raise an error if the config file is incomplete.  
  51.         # set defaults instead:  
  52.         SQUID_OPTS=${SQUID_OPTS:-"-D"}  
  53.         SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}  
  54.         SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}  
  55.         if [ -z "$SQUID" ]; then  
  56.                 echo "Insufficient privilege" 1>&2  
  57.                 exit 4  
  58.         fi  
  59.         for adir in $CACHE_SWAP; do  
  60.         if [ ! -d $adir/00 ]; then  
  61.          echo -n "init_cache_dir $adir... "  
  62.          $SQUID -z -F -D >> /usr/local/squid/var/logs/squid.out 2>&1  
  63.     fi  
  64.     done  
  65.     echo -n $"Starting $prog: "  
  66.     $SQUID $SQUID_OPTS >> /usr/local/squid/var/logs/squid.out 2>&1  
  67.     RETVAL=$?  
  68.     if [ $RETVAL -eq 0 ]; then  
  69.        timeout=0;  
  70.        while : ; do  
  71.           [ ! -f /usr/local/squid/var/run/squid.pid ] || break  
  72.       if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then  
  73.          RETVAL=1 
  74.          break  
  75.       fi  
  76.       sleep 1 && echo -n "."  
  77.       timeout=$((timeout+1))  
  78.        done  
  79.     fi  
  80.     [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID_uid  
  81.     [ $RETVAL -eq 0 ] && echo_success  
  82.     [ $RETVAL -ne 0 ] && echo_failure  
  83.     echo  
  84.     return $RETVAL  
  85. }  
  86.  
  87. stop() {  
  88.     . /etc/sysconfig/squid  
  89.     # don't raise an error if the config file is incomplete.  
  90.     # set defaults instead:  
  91.     SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}  
  92.     echo -n  $"Stopping $prog: "  
  93.     $SQUID -k check >> /usr/local/squid/var/logs/squid.out 2>&1  
  94.     RETVAL=$?  
  95.     if [ $RETVAL -eq 0 ] ; then  
  96.         $SQUID -k shutdown &  
  97.         rm -f /var/lock/subsys/$SQUID_id  
  98.     timeout=0 
  99.     while : ; do  
  100.         [ -f /usr/local/squid/var/run/squid.pid ] || break  
  101.         if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then  
  102.             echo  
  103.             return 1  
  104.         fi  
  105.         sleep 2 && echo -n "."  
  106.         timeout=$((timeout+2))  
  107.         done  
  108.     echo_success  
  109.     echo  
  110.     else  
  111.         echo_failure  
  112.     if [ ! -e /var/lock/subsys/$SQUID_id ]; then  
  113.         RETVAL=0 
  114.     fi  
  115.     echo  
  116.     fi  
  117.     return $RETVAL  
  118. }  
  119.  
  120. reload() {  
  121.     . /etc/sysconfig/squid  
  122.     # don't raise an error if the config file is incomplete.  
  123.     # set defaults instead:  
  124.     SQUID_OPTS=${SQUID_OPTS:-"-D"}  
  125.  
  126.     $SQUID $SQUID_OPTS -k reconfigure  
  127. }  
  128.  
  129. restart() {  
  130.     stop  
  131.     start  
  132. }  
  133.  
  134. condrestart() {  
  135.     [ -e /var/lock/subsys/squid_id ] && restart || :  
  136. }  
  137.  
  138. rhstatus() {  
  139.     status $SQUID_id && $SQUID -k check  
  140. }  
  141.  
  142. probe() {  
  143.     return 0  
  144. }  
  145.  
  146. case "$1" in  
  147. start)  
  148.     start  
  149.     ;;  
  150.  
  151. stop)  
  152.     stop  
  153.     ;;  
  154.  
  155. reload)  
  156.     reload  
  157.     ;;  
  158.  
  159. restart)  
  160.     restart  
  161.     ;;  
  162.  
  163. condrestart)  
  164.     condrestart  
  165.     ;;  
  166.  
  167. status)  
  168.     rhstatus  
  169.     ;;  
  170.  
  171. probe)  
  172.     exit 0  
  173.     ;;  
  174.  
  175. *)  
  176.     echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"  
  177.     exit 2  
  178. esac  
  179.  
  180. exit $?  

 

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