Advertisement
punces

squid.sh

Oct 10th, 2016
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. #! /bin/sh
  2. #
  3. # squid3 Startup script for the SQUID HTTP proxy-cache.
  4. #
  5. # Version: @(#)squid3.rc 1.0 07-Jul-2006 luigi@debian.org
  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 version 3.x
  16. ### END INIT INFO
  17.  
  18. NAME=squid
  19. DESC="Squid HTTP Proxy 3.x"
  20. DAEMON=/usr/sbin/squid
  21. PIDFILE=/var/run/$NAME.pid
  22. CONFIG=/etc/squid/squid.conf
  23. SQUID_ARGS="-YC -f $CONFIG"
  24.  
  25. [ ! -f /etc/default/squid ] || . /etc/default/squid
  26.  
  27. . /lib/lsb/init-functions
  28.  
  29. PATH=/bin:/usr/bin:/sbin:/usr/sbin
  30.  
  31. [ -x $DAEMON ] || exit 0
  32.  
  33. ulimit -n 65535
  34.  
  35. find_cache_dir () {
  36. w=" " # space tab
  37. res=`sed -ne '
  38. s/^'$1'['"$w"']\+[^'"$w"']\+['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
  39. t end;
  40. d;
  41. :end q' < $CONFIG`
  42. [ -n "$res" ] || res=$2
  43. echo "$res"
  44. }
  45.  
  46. find_cache_type () {
  47. w=" " # space tab
  48. res=`sed -ne '
  49. s/^'$1'['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
  50. t end;
  51. d;
  52. :end q' < $CONFIG`
  53. [ -n "$res" ] || res=$2
  54. echo "$res"
  55. }
  56.  
  57. start () {
  58. cache_dir=`find_cache_dir cache_dir`
  59. cache_type=`find_cache_type cache_dir`
  60.  
  61. #
  62. # Create spool dirs if they don't exist.
  63. #
  64. if [ "$cache_type" = "coss" -a -d "$cache_dir" -a ! -f "$cache_dir/stripe" ] || [ "$cache_type" != "coss" -a -d "$cache_dir" -a ! -d "$cache_dir/00" ]
  65. then
  66. log_warning_msg "Creating $DESC cache structure"
  67. $DAEMON -z -f $CONFIG
  68. fi
  69.  
  70. umask 027
  71. ulimit -n 65535
  72. cd $cache_dir
  73. start-stop-daemon --quiet --start \
  74. --pidfile $PIDFILE \
  75. --exec $DAEMON -- $SQUID_ARGS < /dev/null
  76. return $?
  77. }
  78.  
  79. stop () {
  80. PID=`cat $PIDFILE 2>/dev/null`
  81. start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON
  82. #
  83. # Now we have to wait until squid has _really_ stopped.
  84. #
  85. sleep 2
  86. if test -n "$PID" && kill -0 $PID 2>/dev/null
  87. then
  88. log_action_begin_msg " Waiting"
  89. cnt=0
  90. while kill -0 $PID 2>/dev/null
  91. do
  92. cnt=`expr $cnt + 1`
  93. if [ $cnt -gt 24 ]
  94. then
  95. log_action_end_msg 1
  96. return 1
  97. fi
  98. sleep 5
  99. log_action_cont_msg ""
  100. done
  101. log_action_end_msg 0
  102. return 0
  103. else
  104. return 0
  105. fi
  106. }
  107.  
  108. case "$1" in
  109. start)
  110. rm -rf /var/log/squid/*
  111. rm -rf /rmp/*
  112. log_daemon_msg "Starting $DESC" "$NAME"
  113. if start ; then
  114. log_end_msg $?
  115. else
  116. log_end_msg $?
  117. fi
  118. ;;
  119. stop)
  120. log_daemon_msg "Stopping $DESC" "$NAME"
  121. if stop ; then
  122. log_end_msg $?
  123. else
  124. log_end_msg $?
  125. fi
  126. ;;
  127. reload|force-reload)
  128. log_action_msg "Reloading $DESC configuration files"
  129. start-stop-daemon --stop --signal 1 \
  130. --pidfile $PIDFILE --quiet --exec $DAEMON
  131. log_action_end_msg 0
  132. ;;
  133. restart)
  134. log_daemon_msg "Restarting $DESC" "$NAME"
  135. stop
  136. if start ; then
  137. log_end_msg $?
  138. else
  139. log_end_msg $?
  140. fi
  141. ;;
  142. status)
  143. status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit 3
  144. ;;
  145. *)
  146. echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart|status}"
  147. exit 3
  148. ;;
  149. esac
  150.  
  151. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement