projects/aports·blob master · refs

120 lines · 3.3 KiB

1#!/sbin/openrc-run
2# Copyright 1999-2013 Gentoo Foundation
3# Distributed under the terms of the GNU General Public License v2
4# $Header: /var/cvsroot/gentoo-x86/net-proxy/squid/files/squid.initd-r3,v 1.1 2013/01/11 15:25:49 eras Exp $
5
6extra_started_commands="reload rotate"
7
8depend() {
9 use dns
10 need net
11 after firewall
12}
13
14checkconfig() {
15 if [ ! -f /etc/squid/${SVCNAME}.conf ]; then
16 eerror "You need to create /etc/squid/${SVCNAME}.conf first."
17 eerror "An example can be found in /etc/squid/squid.conf.default"
18 return 1
19 fi
20
21 local PIDFILE=$(awk '/^[ \t]*pid_filename[ \t]+/ { print $2 }' < /etc/squid/${SVCNAME}.conf)
22 [ -z ${PIDFILE} ] && PIDFILE=/var/run/squid.pid
23 if [ /var/run/${SVCNAME}.pid != ${PIDFILE} ]; then
24 eerror "/etc/squid/${SVCNAME}.conf must set pid_filename to"
25 eerror " /var/run/${SVCNAME}.pid"
26 eerror "CAUTION: http_port, cache_dir and *_log parameters must be different than"
27 eerror " in any other instance of squid."
28 return 1
29 fi
30
31 # Maximum file descriptors squid can open is determined by:
32 # a basic default of N=1024
33 # ... altered by ./configure --with-filedescriptors=N
34 # ... overridden on production by squid.conf max_filedescriptors (if,
35 # and only if, setrlimit() RLIMIT_NOFILE is able to be built+used).
36 # Since we do not configure hard coded # of filedescriptors anymore,
37 # there is no need for ulimit calls in the init script.
38 # Use max_filedescriptors in squid.conf instead.
39
40 local CACHE_SWAP=$(awk '/^[ \t]*cache_dir[ \t]+/ { if ($2 == "coss" ) printf "%s/stripe ", $3 ; else printf "%s/00 ", $3; }' < /etc/squid/${SVCNAME}.conf)
41 [ -z "$CACHE_SWAP" ] && CACHE_SWAP="/var/cache/squid/00"
42
43 local x
44 for x in $CACHE_SWAP ; do
45 if [ ! -e $x ] ; then
46 ebegin "Initializing cache directory ${x%/*}"
47 local ORIG_UMASK=$(umask)
48 umask 027
49
50 if ! (mkdir -p ${x%/*} && chown squid ${x%/*}) ; then
51 eend 1
52 return 1
53 fi
54
55 local INIT_CACHE_RESPONSE="$(/usr/sbin/squid -z -N -f /etc/squid/${SVCNAME}.conf 2>&1)"
56 if [ $? != 0 ] || echo "$INIT_CACHE_RESPONSE" | grep -q "erminated abnormally" ; then
57 umask $ORIG_UMASK
58 eend 1
59 echo "$INIT_CACHE_RESPONSE"
60 return 1
61 fi
62
63 umask $ORIG_UMASK
64 eend 0
65 break
66 fi
67 done
68
69 return 0
70}
71
72start() {
73 checkconfig || return 1
74 checkpath -d /var/run/squid -m 0755 -o squid:squid
75 checkpath -d /var/log/squid -m 0750 -o squid:squid
76 ebegin "Starting ${SVCNAME}"
77 KRB5_KTNAME="${SQUID_KEYTAB}" /usr/sbin/squid ${SQUID_OPTS} -f /etc/squid/${SVCNAME}.conf
78 eend $? && sleep 1
79}
80
81stop() {
82 ebegin "Stopping ${SVCNAME}"
83 if /usr/sbin/squid -k shutdown -f /etc/squid/${SVCNAME}.conf ; then
84 # Now we have to wait until squid has _really_ stopped.
85 sleep 1
86 if [ -f /var/run/${SVCNAME}.pid ] ; then
87 einfon "Waiting for squid to shutdown ."
88 cnt=0
89 while [ -f /var/run/${SVCNAME}.pid ] ; do
90 cnt=$(expr $cnt + 1)
91 if [ $cnt -gt 60 ] ; then
92 # Waited 120 seconds now. Fail.
93 echo
94 eend 1 "Failed."
95 break
96 fi
97 sleep 2
98 echo -n "."
99 done
100 echo
101 fi
102 else
103 eerror "Squid shutdown failed, probably service is already down."
104 fi
105 eend 0
106}
107
108reload() {
109 checkconfig || return 1
110 ebegin "Reloading ${SVCNAME}"
111 /usr/sbin/squid -k reconfigure -f /etc/squid/${SVCNAME}.conf
112 eend $?
113}
114
115rotate() {
116 service_started ${SVCNAME} || return 1
117 ebegin "Rotating ${SVCNAME} logs"
118 /usr/sbin/squid -k rotate -f /etc/squid/${SVCNAME}.conf
119 eend $?
120}