AndrzejL

/etc/init.d/squid

Nov 4th, 2012
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. #!/bin/bash
  2. # squid This shell script takes care of starting and stopping
  3. # Squid Internet Object Cache
  4. #
  5. # chkconfig: 345 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. ### BEGIN INIT INFO
  16. # Provides: squid
  17. # Required-Start: $network
  18. # Required-Stop: $network
  19. # Should-Start: $named icapd
  20. # Should-Stop: $named
  21. # Default-Start: $named
  22. # Default-Stop: $named
  23. # Short-Description: Starts the squid daemon
  24. # Description: Squid is a full-featured web proxy cache with support for \
  25. # many protocols, cache hierarchies, transparent proxy and \
  26. # many other features.
  27. #
  28. ### END INIT INFO
  29.  
  30. ulimit -n 8192
  31. PATH=/usr/bin:/sbin:/bin:/usr/sbin
  32. export PATH
  33.  
  34. # Source function library.
  35. . /etc/rc.d/init.d/functions
  36.  
  37. # Source networking configuration.
  38. . /etc/sysconfig/network
  39.  
  40. # Check that networking is up.
  41. [ ${NETWORKING} = "no" ] && exit 0
  42.  
  43. # check if the squid conf file is present
  44. [ -f /etc/squid/squid.conf ] || exit 0
  45.  
  46. if [ -f /etc/sysconfig/squid ]; then
  47. . /etc/sysconfig/squid
  48. fi
  49.  
  50. # don't raise an error if the config file is incomplete
  51. # set defaults instead:
  52. SQUID_OPTS=${SQUID_OPTS:-""}
  53. SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
  54. SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
  55.  
  56. # determine the name of the squid binary
  57. [ -f /usr/sbin/squid ] && SQUID=squid
  58. [ -z "$SQUID" ] && exit 0
  59.  
  60. prog="$SQUID"
  61.  
  62. # determine which one is the cache_swap directory
  63. CACHE_SWAP=`sed -e 's/#.*//g' /etc/squid/squid.conf | \
  64. grep cache_dir | awk '{ print $3 }'`
  65. [ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/spool/squid
  66.  
  67. RETVAL=0
  68.  
  69. start() {
  70. # taken from udev
  71. case "$(uname -r)" in
  72. 2.[012345].*)
  73. gprintf "squid requires a 2.6.x kernel (with epoll support). "
  74. failure; echo
  75. exit 1
  76. ;;
  77. esac
  78.  
  79. if [ ! -d $adir/00 ]; then
  80. gprintf "init_cache_dir %s... " "$adir"
  81. $SQUID -z -F >> /var/log/squid/squid.out 2>&1
  82. fi
  83.  
  84. gprintf "Starting %s: " "$prog"
  85. $SQUID $SQUID_OPTS >> /var/log/squid/squid.out 2>&1
  86. RETVAL=$?
  87. if [ $RETVAL -eq 0 ]; then
  88. timeout=0;
  89. while : ; do
  90. [ ! -f /var/run/squid.pid ] || break
  91. if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then
  92. RETVAL=1
  93. break
  94. fi
  95. sleep 1 && gprintf "."
  96. timeout=$((timeout+1))
  97. done
  98. fi
  99.  
  100. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID
  101. [ $RETVAL -eq 0 ] && success
  102. [ $RETVAL -ne 0 ] && failure
  103. echo
  104. return $RETVAL
  105. }
  106.  
  107. stop() {
  108. gprintf "Stopping %s: " "$prog"
  109. $SQUID -k check >> /var/log/squid/squid.out 2>&1
  110. RETVAL=$?
  111. if [ $RETVAL -eq 0 ] ; then
  112. $SQUID -k shutdown &
  113. rm -f /var/lock/subsys/$SQUID
  114. timeout=0
  115. while : ; do
  116. [ -f /var/run/squid.pid ] || break
  117. if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
  118. echo
  119. return 1
  120. fi
  121. sleep 2 && gprintf "."
  122. timeout=$((timeout+2))
  123. done
  124. success; echo
  125. else
  126. failure; echo
  127. fi
  128. return $RETVAL
  129. }
  130.  
  131. reload() {
  132. $SQUID $SQUID_OPTS -k reconfigure
  133. }
  134.  
  135. restart() {
  136. stop
  137. start
  138. }
  139.  
  140. condrestart() {
  141. [ -e /var/lock/subsys/squid ] && restart || :
  142. }
  143.  
  144. rhstatus() {
  145. status $SQUID
  146. $SQUID -k check
  147. }
  148.  
  149. probe() {
  150. return 0
  151. }
  152.  
  153. case "$1" in
  154. start)
  155. start
  156. ;;
  157.  
  158. stop)
  159. stop
  160. ;;
  161.  
  162. reload)
  163. reload
  164. ;;
  165.  
  166. restart)
  167. restart
  168. ;;
  169.  
  170. condrestart)
  171. condrestart
  172. ;;
  173.  
  174. status)
  175. rhstatus
  176. ;;
  177.  
  178. probe)
  179. exit 0
  180. ;;
  181.  
  182. *)
  183. gprintf "Usage: %s {start|stop|status|reload|restart|condrestart}\n" "$0"
  184. exit 1
  185. esac
  186.  
  187. exit $?
Advertisement
Add Comment
Please, Sign In to add comment