Advertisement
albspirit86

Startup script for the SQUID

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