Inidian

squid

Dec 30th, 2012
299
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.85 KB | None | 0 0
  1. #! /bin/sh
  2. #
  3. # squid      Startup script for the SQUID HTTP proxy-cache.
  4. #
  5. # Version:   @(#)squid.rc  2.20  01-Oct-2001  [email protected]
  6. #
  7. ### BEGIN INIT INFO
  8. # Provides:          squid
  9. # Required-Start:    $network $remote_fs $syslog
  10. # Required-Stop:     $network $remote_fs $syslog
  11. # Should-Start:      $named
  12. # Should-Stop:       $named
  13. # Default-Start:     2 3 4 5
  14. # Default-Stop:      0 1 6
  15. # Short-Description: Squid HTTP Proxy
  16. ### END INIT INFO
  17.  
  18. NAME=squid
  19. DAEMON=/usr/sbin/squid
  20. LIB=/usr/lib/squid
  21. PIDFILE=/var/log/squid/$NAME.pid
  22. SQUID_ARGS="-D -YC"
  23.  
  24. [ ! -f /etc/default/squid ] || . /etc/default/squid
  25.  
  26. . /lib/lsb/init-functions
  27.  
  28. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  29.  
  30. [ -x $DAEMON ] || exit 0
  31.  
  32. grepconf () {
  33.    w="    " # space tab
  34.    sq=/etc/squid/squid.conf
  35.    # sed is cool.
  36.    res=`sed -ne '
  37.      s/^'$1'['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
  38.      t end;
  39.      d;
  40.      :end q' < $sq`
  41.    [ -n "$res" ] || res=$2
  42.    echo "$res"
  43. }
  44.  
  45. grepconf2 () {
  46.    w="    " # space tab
  47.    sq=/etc/squid/$NAME.conf
  48.    # sed is cool.
  49.    res=`sed -ne '
  50.      s/^'$1'['"$w"']\+[^'"$w"']\+['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
  51.      t end;
  52.      d;
  53.      :end q' < $sq`
  54.    [ -n "$res" ] || res=$2
  55.    echo "$res"
  56. }
  57.  
  58. #
  59. #   Try to increase the # of filedescriptors we can open.
  60. #
  61. maxfds () {
  62.    [ -n "$SQUID_MAXFD" ] || return
  63.    [ -f /proc/sys/fs/file-max ] || return 0
  64.    global_file_max=`cat /proc/sys/fs/file-max`
  65.    minimal_file_max=$(($SQUID_MAXFD + 4096))
  66.    if [ "$global_file_max" -lt $minimal_file_max ]
  67.    then
  68.       echo $minimal_file_max > /proc/sys/fs/file-max
  69.    fi
  70.    ulimit -n $SQUID_MAXFD
  71. }
  72.  
  73. start () {
  74.    cdr=`grepconf2 cache_dir /var/spool/$NAME`
  75.    ctp=`grepconf cache_dir ufs`
  76.  
  77.    case "$cdr" in
  78.       [0-9]*)
  79.          log_failure_msg "squid: squid.conf contains 2.2.5 syntax - not starting!"
  80.          log_end_msg 1
  81.          exit 1
  82.          ;;
  83.    esac
  84.    
  85.    #
  86.     # Create spool dirs if they don't exist.
  87.     #
  88.    if [ -d "$cdr" -a ! -d "$cdr/00" ] || [ "$ctp" = "coss" -a ! -w "$cdr" ]
  89.    then
  90.       log_warning_msg "Creating squid cache structure"
  91.       $DAEMON $SQUID_ARGS -z
  92.    fi
  93.  
  94.    if [ "$CHUID" = "" ]; then
  95.       CHUID=root
  96.    fi
  97.  
  98.    #maxfds
  99.        ulimit -n 65536
  100.    umask 027
  101.    start-stop-daemon --quiet --start \
  102.       --pidfile $PIDFILE \
  103.       --chuid $CHUID \
  104.       --exec $DAEMON -- $SQUID_ARGS < /dev/null
  105.    return $?
  106. }
  107.  
  108. stop () {
  109.    PID=`cat $PIDFILE 2>/dev/null`
  110.    start-stop-daemon --stop --quiet --pidfile $PIDFILE --name squid
  111.    #
  112.    #   Now we have to wait until squid has _really_ stopped.
  113.    #
  114.    sleep 2
  115.    if test -n "$PID" && kill -0 $PID 2>/dev/null
  116.    then
  117.       log_action_begin_msg " Waiting"
  118.       cnt=0
  119.       while kill -0 $PID 2>/dev/null
  120.       do
  121.          cnt=`expr $cnt + 1`
  122.          if [ $cnt -gt 24 ]
  123.          then
  124.             log_action_end_msg 1
  125.             return 1
  126.          fi
  127.          sleep 5
  128.          log_action_cont_msg ""
  129.       done
  130.       log_action_end_msg 0
  131.       return 0
  132.    else
  133.       return 0
  134.    fi
  135. }
  136.  
  137. case "$1" in
  138.     start)
  139.    log_daemon_msg "Starting Squid HTTP proxy" "squid"
  140.    if start ; then
  141.       log_end_msg $?
  142.    else
  143.       log_end_msg $?
  144.    fi
  145.    ;;
  146.     stop)
  147.    log_daemon_msg "Stopping Squid HTTP proxy" "squid"
  148.    if stop ; then
  149.       log_end_msg $?
  150.    else
  151.       log_end_msg $?
  152.    fi
  153.    ;;
  154.     reload|force-reload)
  155.    log_action_msg "Reloading Squid configuration files"
  156.    $DAEMON -k reconfigure
  157.    log_action_end_msg 0
  158.    ;;
  159.     restart)
  160.    log_daemon_msg "Restarting Squid HTTP proxy" "squid"
  161.    stop
  162.    if start ; then
  163.       log_end_msg $?
  164.    else
  165.       log_end_msg $?
  166.    fi
  167.    ;;
  168.     status)
  169.    status_of_proc -p "$PIDFILE" "$DAEMON" squid && exit 0 || exit $?
  170.    ;;
  171.     *)
  172.    echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart|status}"
  173.    exit 3
  174.    ;;
  175. esac
  176.  
  177. exit 0
Advertisement
Add Comment
Please, Sign In to add comment