Trailing dots in old-school domain patterns mean "(\..*)?", not "\..*".
[privoxy.git] / privoxy.init
1 #!/bin/sh
2 #
3 # This is file /etc/rc.d/init.d/privoxy and was put here 
4 # by the privoxy rpm
5 #
6 # chkconfig: 2345 84 09
7 #
8 # description: Web proxy with advanced filtering capabilities \
9 #              such as filtering web page content, managing \
10 #              cookies and removing ads
11 #
12
13 #  ********************************************************************
14
15 #  File        :  $Source: /cvsroot/ijbswa/current/privoxy.init,v $
16
17 #  Purpose     :  This shell script takes care of starting and stopping
18 #                 privoxy.
19
20 #  Copyright   :  Written by and Copyright (C) 2001 the SourceForge
21 #                 Privoxy team. http://www.privoxy.org/
22
23 #                 Based on the Internet Junkbuster originally written
24 #                 by and Copyright (C) 1997 Anonymous Coders and
25 #                 Junkbusters Corporation.  http://www.junkbusters.com
26
27 #                 This program is free software; you can redistribute it
28 #                 and/or modify it under the terms of the GNU General
29 #                 Public License as published by the Free Software
30 #                 Foundation; either version 2 of the License, or (at
31 #                 your option) any later version.
32
33 #                 This program is distributed in the hope that it will
34 #                 be useful, but WITHOUT ANY WARRANTY; without even the
35 #                 implied warranty of MERCHANTABILITY or FITNESS FOR A
36 #                 PARTICULAR PURPOSE.  See the GNU General Public
37 #                 License for more details.
38
39 #                 The GNU General Public License should be included with
40 #                 this file.  If not, you can view it at
41 #                 http://www.gnu.org/copyleft/gpl.html
42 #                 or write to the Free Software Foundation, Inc., 59
43 #                 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
44
45 #  Revisions   :
46 #     $Log: privoxy.init,v $
47 #     Revision 1.8.2.3  2002/12/10 20:52:16  kick_
48 #     better service description. This text will be shown when the user configures the services
49 #
50 #     Revision 1.8.2.2  2002/08/05 08:42:13  kick_
51 #     same permissions, same runlevels as all the other initscripts
52 #
53 #     Revision 1.8.2.1  2002/07/12 09:14:26  kick_
54 #     don't use ghost files for rcX.d/*, chkconfig is available to do this job. Enable translation of error messge
55 #
56 #     Revision 1.8  2002/04/09 02:51:31  hal9
57 #     Changed $JB to $PRIVOXY.
58 #
59 #     Revision 1.7  2002/04/08 14:54:51  morcego
60 #     Moved the chkconfig comments to the begining of the file, couse Linuxconf
61 #     was getting confused with it where it was.
62 #
63 #     Revision 1.6  2002/03/26 22:29:55  swa
64 #     we have a new homepage!
65 #
66 #     Revision 1.5  2002/03/25 06:14:18  morcego
67 #     Removing the OPRG definition (no longer needed)
68 #
69 #     Revision 1.4  2002/03/25 04:16:48  hal9
70 #     Fix proper config file location.
71 #
72 #     Revision 1.3  2002/03/24 19:12:15  hal9
73 #     Fixed some naming conflicts.
74 #
75 #     Revision 1.2  2002/03/24 11:40:14  swa
76 #     name change
77 #
78 #     Revision 1.1  2002/03/24 11:23:44  swa
79 #     name change
80 #
81 #     Revision 1.1  2002/03/22 20:53:03  morcego
82 #     - Ongoing process to change name to JunkbusterNG
83 #     - configure/configure.in: no change needed
84 #     - GNUmakefile.in:
85 #             - TAR_ARCH = /tmp/JunkbusterNG-$(RPM_VERSION).tar.gz
86 #             - PROGRAM    = jbng@EXEEXT@
87 #             - rh-spec now references as junkbusterng-rh.spec
88 #             - redhat-upload: references changed to junkbusterng-* (package names)
89 #             - tarball-dist: references changed to JunkbusterNG-distribution-*
90 #             - tarball-src: now JunkbusterNG-*
91 #             - install: initscript now junkbusterng.init and junkbusterng (when
92 #                        installed)
93 #     - junkbuster-rh.spec: renamed to junkbusterng-rh.spec
94 #     - junkbusterng.spec:
95 #             - References to the expression ijb where changed where possible
96 #             - New package name: junkbusterng (all in lower case, acording to
97 #               the LSB recomendation)
98 #             - Version changed to: 2.9.13
99 #             - Release: 1
100 #             - Added: junkbuster to obsoletes and conflicts (Not sure this is
101 #               right. If it obsoletes, why conflict ? Have to check it later)
102 #             - Summary changed: Stefan, please check and aprove it
103 #             - Changes description to use the new name
104 #             - Sed string was NOT changed. Have to wait to the manpage to
105 #               change first
106 #             - Keeping the user junkbuster for now. It will require some aditional
107 #               changes on the script (scheduled for the next specfile release)
108 #             - Added post entry to move the old logfile to the new log directory
109 #             - Removing "chkconfig --add" entry (not good to have it automaticaly
110 #               added to the startup list).
111 #             - Added preun section to stop the service with the old name, as well
112 #               as remove it from the startup list
113 #             - Removed the chkconfig --del entry from the conditional block on
114 #               the preun scriptlet (now handled on the %files section)
115 #     - junkbuster.init: renamed to junkbusterng.init
116 #     - junkbusterng.init:
117 #             - Changed JB_BIN to jbng
118 #             - Created JB_OBIN with the old value of JB_BIN (junkbuster), to
119 #               be used where necessary (config dir)
120 #
121 #     Aditional notes:
122 #     - The config directory is /etc/junkbuster yet. Have to change it on the
123 #     specfile, after it is changes on the code
124 #     - The only files that got renamed on the cvs tree were the rh specfile and
125 #     the init file. Some file references got changes on the makefile and on the
126 #     rh-spec (as listed above)
127 #
128 #     Revision 1.15  2002/03/09 15:05:58  swa
129 #     wrong user.group
130 #
131 #     Revision 1.14  2002/03/06 06:13:40  hal9
132 #     Adapted for Andreas' changes for --user and --pidfile.
133 #
134 #     Revision 1.13  2002/03/05 05:10:10  oes
135 #     Changed pidfile path to conform with FHS
136 #
137 #     Revision 1.12  2002/03/04 20:44:36  oes
138 #     Changed to new cmdline syntax
139 #
140 #     Revision 1.11  2001/12/30 14:07:32  steudten
141 #     - Add signal handling (unix)
142 #     - Add SIGHUP handler (unix)
143 #     - Add creation of pidfile (unix)
144 #     - Add action 'top' in rc file (RH)
145 #     - Add entry 'SIGNALS' to manpage
146 #     - Add exit message to logfile (unix)
147 #
148 #     Revision 1.10  2001/11/05 21:30:23  steudten
149 #     Make JB startup without & due to be a 'real' daemon right now.
150 #     Make the script easy to change.
151 #
152 #     Revision 1.9  2001/09/15 01:53:12  steudten
153 #
154 #     Remove test for subsys flag in start. Some minor changes.
155 #
156 #     Revision 1.8  2001/06/28 13:50:36  sarantis
157 #     swap ?$ with $?; remove bogus ";;"
158 #
159 #     Revision 1.7  2001/06/28 13:40:26  sarantis
160 #     remove single quotes from $JB; it was not expanded.
161 #
162 #     Revision 1.6  2001/06/28 13:38:42  sarantis
163 #     formatting changes; individual return values are returned from the init script.
164 #
165 #     Revision 1.5  2001/06/11 11:37:40  sarantis
166 #     Minor editing changes.
167 #
168 #     Revision 1.4  2001/06/09 09:14:11  swa
169 #     shamelessly adapted RPM stuff from the newest rpm that
170 #     RedHat provided for the JB.
171 #
172 #     Revision 1.3  2001/05/25 10:12:44  oes
173 #     Fixed default case in switch statement (# -> *)
174 #
175 #     Revision 1.2  2001/05/24 07:52:24  swa
176 #     added header. removed ^M.
177 #
178
179 # ********************************************************************/
180
181
182 # Source function library.
183 . /etc/rc.d/init.d/functions
184
185 . /etc/sysconfig/network
186
187 #  Check that networking is up.
188 [ ${NETWORKING} = "no" ] && exit 0
189
190 PRIVOXY_PRG="privoxy"
191 PRIVOXY_BIN="/usr/sbin/$PRIVOXY_PRG"
192 PRIVOXY_CONF="/etc/$PRIVOXY_PRG/config"
193 PRIVOXY_USER="privoxy"
194 PRIVOXY_PID=/var/run/$PRIVOXY_PRG.pid
195 PRIVOXY_LOCK=/var/lock/subsys/$PRIVOXY_PRG
196 PRIVOXY="$PRIVOXY_BIN --user $PRIVOXY_USER.$PRIVOXY_USER --pidfile $PRIVOXY_PID $PRIVOXY_CONF"
197
198 # some checks for us
199 ! [ -x $PRIVOXY_BIN  ] && echo $"Can't find $PRIVOXY_BIN, exit." && exit 0
200 ! [ -f $PRIVOXY_CONF ] && echo $"Can't find $PRIVOXY_CONF, exit." && exit 0
201
202 # See how we were called.
203
204 start () {
205         # start daemon
206         echo -n $"Starting $PRIVOXY_PRG: "
207      if [ -f $PRIVOXY_PID ]; then 
208         killproc $PRIVOXY_PRG && rm -f $PRIVOXY_LOCK $PRIVOXY_PID
209         RETVAL=$?
210         [ $RETVAL != 0 ] && return $RETVAL
211      fi
212         daemon $PRIVOXY
213         RETVAL=$?
214         echo
215         [ $RETVAL = 0 ] && touch $PRIVOXY_LOCK
216         return $RETVAL
217 }
218
219 stop () {
220         # stop daemon
221         echo -n $"Stopping $PRIVOXY_PRG: "
222         killproc $PRIVOXY_PRG && rm -f $PRIVOXY_LOCK $PRIVOXY_PID
223         RETVAL=$?
224         echo
225         return $RETVAL
226 }
227
228 case "$1" in
229   start)
230         start   
231         ;;
232   stop)
233         stop
234         ;;
235   reload)
236         if [ -f $PRIVOXY_PID ] ; then
237         kill -HUP `cat $PRIVOXY_PID`
238         RETVAL=$?
239      fi
240         ;;
241   restart)
242         stop
243         start
244         RETVAL=$?
245         ;;
246   condrestart)
247         # restart only if already running
248         if [ -f $PRIVOXY_PID ] ; then
249         stop
250         start
251         RETVAL=$?
252         fi 
253         ;;
254   status)
255         status $PRIVOXY_PRG 
256         RETVAL=$?
257         ;;
258   top)
259      if [ -f $PRIVOXY_PID ]; then
260                 a=""
261                 for i in `pidof $PRIVOXY_PRG` ; do
262                         a="$a -p $i"
263                 done
264                 top $a
265      fi
266         ;;
267   *)
268         echo $"Usage: $PRIVOXY_PRG {start|stop|reload|restart|condrestart|status|top}"
269         exit 1
270 esac
271
272 exit $RETVAL