Advertisement
teknisiazza

/etc/init.d/squid

Oct 9th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.06 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 miquels@cistron.nl
  6. #
  7. ### BEGIN INIT INFO
  8. # Provides: squid
  9. # Required-Start: $local_fs $network
  10. # Required-Stop: $local_fs $network
  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/run/squid.pid
  22. # export LD_PRELOAD=/usr/local/lib/libjemalloc.so # ini apabila anda menggunakan jemalloc
  23. SQUID_ARGS="-YC"
  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. grepconf () {
  34. w=" " # space tab
  35. sq=/etc/squid/squid.conf
  36. # sed is cool.
  37. res=`sed -ne '
  38. s/^'$1'['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
  39. t end;
  40. d;
  41. :end q' < $sq`
  42. [ -n "$res" ] || res=$2
  43. echo "$res"
  44. }
  45.  
  46. grepconf2 () {
  47. w=" " # space tab
  48. sq=/etc/squid/$NAME.conf
  49. # sed is cool.
  50. res=`sed -ne '
  51. s/^'$1'['"$w"']\+[^'"$w"']\+['"$w"']\+\([^'"$w"']\+\).*$/\1/p;
  52. t end;
  53. d;
  54. :end q' < $sq`
  55. [ -n "$res" ] || res=$2
  56. echo "$res"
  57. }
  58.  
  59. #
  60. # Try to increase the # of filedescriptors we can open.
  61. #
  62. maxfds () {
  63. [ -n "$SQUID_MAXFD" ] || return
  64. [ -f /proc/sys/fs/file-max ] || return 0
  65. global_file_max=`cat /proc/sys/fs/file-max`
  66. minimal_file_max=$(($SQUID_MAXFD + 4096))
  67. if [ "$global_file_max" -lt $minimal_file_max ]
  68. then
  69. echo $minimal_file_max > /proc/sys/fs/file-max
  70. fi
  71. ulimit -n $SQUID_MAXFD
  72. }
  73.  
  74. start () {
  75. cdr=`grepconf2 cache_dir /cache-{1,2}`
  76. ctp=`grepconf cache_dir ufs`
  77.  
  78. case "$cdr" in
  79. [0-9]*)
  80. log_failure_msg "squid: squid.conf contains 2.2.5 syntax - not starting!"
  81. log_end_msg 1
  82. exit 1
  83. ;;
  84. esac
  85.  
  86. #
  87. # Create spool dirs if they don't exist.
  88. #
  89. if [ -d "$cdr" -a ! -d "$cdr/00" ] || [ "$ctp" = "coss" -a ! -w "$cdr" ]
  90. then
  91. log_warning_msg "Creating squid cache structure"
  92. $DAEMON $SQUID_ARGS -z
  93. fi
  94.  
  95. if [ "$CHUID" = "" ]; then
  96. CHUID=root
  97. fi
  98.  
  99. maxfds
  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
Advertisement