0% found this document useful (0 votes)
84 views5 pages

Squid HTTP Proxy Startup Script

This document provides a startup script for the Squid HTTP proxy cache. The script defines functions for starting, stopping, reloading and getting the status of the Squid service. It checks configuration files, creates required directories, sets file permissions and more when starting and stopping Squid.

Uploaded by

lordmash
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views5 pages

Squid HTTP Proxy Startup Script

This document provides a startup script for the Squid HTTP proxy cache. The script defines functions for starting, stopping, reloading and getting the status of the Squid service. It checks configuration files, creates required directories, sets file permissions and more when starting and stopping Squid.

Uploaded by

lordmash
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

[Link]

view source
print?
001 #! /bin/sh
002 #
003 # squid

Startup script for the SQUID HTTP proxy-cache.

004 #
005 # Version:

@(#)[Link]

2.20

01-Oct-2001

miquels@[Link]

006 #
007 ### BEGIN INIT INFO
008 # Provides:

squid

009 # Required-Start:

$local_fs $network

010 # Required-Stop:

$local_fs $network

011 # Should-Start:

$named

012 # Should-Stop:

$named

013 # Default-Start:

2 3 4 5

014 # Default-Stop:

0 1 6

015 # Short-Description: Squid HTTP Proxy


016 ### END INIT INFO
017
018 NAME=squid
019 DAEMON=/usr/sbin/squid
020 LIB=/usr/lib/squid
021 PIDFILE=/var/run/$[Link]
022 SQUID_ARGS="-D -YC"
023
024 [ ! -f /etc/default/squid ] || . /etc/default/squid
025
026 . /lib/lsb/init-functions
027
028 PATH=/bin:/usr/bin:/sbin:/usr/sbin
029
030 [ -x $DAEMON ] || exit 0
031
032 grepconf () {

1 of 5

033

w="

034

sq=/etc/squid/[Link]

035

# sed is cool.

" # space tab

10/04/2011 02:38 PM

[Link]

036

res=`sed -ne '

037

s/^'$1'['"$w"']\+\([^'"$w"']\+\).*$/\1/p;

038

t end;

039

d;

040

:end q' < $sq`

041

[ -n "$res" ] || res=$2

042

echo "$res"

043 }
044
045 grepconf2 () {
046

w="

047

sq=/etc/squid/$[Link]

048

# sed is cool.

049

res=`sed -ne '

" # space tab

050

s/^'$1'['"$w"']\+[^'"$w"']\+['"$w"']\+\([^'"$w"']\+\).*$/\1/p;

051

t end;

052

d;

053

:end q' < $sq`

054

[ -n "$res" ] || res=$2

055

echo "$res"

056 }
057
058 #
059 #

Try to increase the # of filedescriptors we can open.

060 #
061 maxfds () {
062

[ -n "$SQUID_MAXFD" ] || return

063

[ -f /proc/sys/fs/file-max ] || return 0

064

global_file_max=`cat /proc/sys/fs/file-max`

065

minimal_file_max=$(($SQUID_MAXFD + 4096))

066

if [ "$global_file_max" -lt $minimal_file_max ]

067

then

068

echo $minimal_file_max > /proc/sys/fs/file-max

069

fi

070

ulimit -n $SQUID_MAXFD

071 }
072

2 of 5

10/04/2011 02:38 PM

[Link]

073 start () {
074

cdr=`grepconf2 cache_dir /var/spool/$NAME`

075

ctp=`grepconf cache_dir ufs`

076
077

case "$cdr" in

078

[0-9]*)

079

log_failure_msg "squid: [Link] contains 2.2.5 syntax

080 - not starting!"


081

log_end_msg 1

082

exit 1

083

;;

084

esac

085
086

087

# Create spool dirs if they don't exist.

088

089

if [ -d "$cdr" -a ! -d "$cdr/00" ] || [ "$ctp" = "coss" -a ! -f "$cdr" ]

090

then

091

log_warning_msg "Creating squid cache structure"

092

$DAEMON $SQUID_ARGS -z

093

fi

094
095

if [ "$CHUID" = "" ]; then

096

CHUID=root

097

fi

098
099

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

3 of 5

PID=`cat $PIDFILE 2>/dev/null`

10/04/2011 02:38 PM

[Link]

110

start-stop-daemon --stop --quiet --pidfile $PIDFILE --name squid

111

112

113

114

sleep 2

115

if test -n "$PID" && kill -0 $PID 2>/dev/null

116

then

Now we have to wait until squid has _really_ stopped.

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
134

return 0
fi

135 }
136
137 case "$1" in
138

start)

139

log_daemon_msg "Starting Squid HTTP proxy" "squid"

140

if start ; then

141
142

log_end_msg $?
else

143
144

fi

145

;;

146

4 of 5

log_end_msg $?

stop)

10/04/2011 02:38 PM

[Link]

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

;;

158

restart)

159

log_daemon_msg "Restarting Squid HTTP proxy" "squid"

160

stop

161

if start ; then

162

log_end_msg $?

163

else

164

log_end_msg $?

165

fi

166

;;

167

status)

168

status_of_proc -p "$PIDFILE" "$DAEMON" squid && exit 0 || exit $?

169
170

;;
*)

171

echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart|s

172 tatus}"
173

exit 3

174

;;

175 esac
176
177 exit 0

5 of 5

10/04/2011 02:38 PM

You might also like